Skip to content

Commit

Permalink
Merge pull request #1054 from Accenture/bugfix/1048-rate-limit-automa…
Browse files Browse the repository at this point in the history
…tion-retrieval

Bugfix/1048 rate limit automation retrieval & improve automation schedule documentation
  • Loading branch information
JoernBerkefeld authored Jul 25, 2023
2 parents fed0939 + b0e799d commit 6ff3836
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
62 changes: 39 additions & 23 deletions lib/metadataTypes/Automation.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,36 @@ class Automation extends MetadataType {
)
);
}
// the API seems to handle 100 concurrent requests nicely
const rateLimit = pLimit(100);

const details = results.Results
? await Promise.all(
results.Results.map(async (a) => {
try {
return await this.client.rest.get(
'/automation/v1/automations/' + a.ObjectID
);
} catch (ex) {
results.Results.map(async (item) =>
rateLimit(async () => {
try {
if (ex.message == 'socket hang up') {
// one more retry; it's a rare case but retrying again should solve the issue gracefully
return await this.client.rest.get(
'/automation/v1/automations/' + a.ObjectID
);
return await this.client.rest.get(
'/automation/v1/automations/' + item.ObjectID
);
} catch (ex) {
try {
if (ex.message == 'socket hang up') {
// one more retry; it's a rare case but retrying again should solve the issue gracefully
return await this.client.rest.get(
'/automation/v1/automations/' + item.ObjectID
);
}
} catch {
// no extra action needed, handled below
}
} catch {
// no extra action needed, handled below
// if we do get here, we should log the error and continue instead of failing to download all automations
Util.logger.error(
` ☇ skipping Automation ${item.ObjectID}: ${ex.message} ${ex.code}`
);
return null;
}
// if we do get here, we should log the error and continue instead of failing to download all automations
Util.logger.error(
` ☇ skipping Automation ${a.ObjectID}: ${ex.message} ${ex.code}`
);
return null;
}
})
})
)
)
: [];

Expand Down Expand Up @@ -1323,9 +1328,20 @@ class Automation extends MetadataType {
}
const frequency = ical.FREQ.slice(0, -2).toLowerCase();

output += `* Recurrance: every ${ical.INTERVAL > 1 ? ical.INTERVAL : ''} ${
frequency === 'dai' ? 'day' : frequency
}${ical.INTERVAL > 1 ? 's' : ''}${ical.COUNT ? ` for ${ical.COUNT} times` : ''}\n`;
output += `* Recurrance: `;
output +=
ical.COUNT == 1
? 'run only once'
: `every${ical.INTERVAL > 1 ? ' ' + ical.INTERVAL : ''} ${
frequency === 'dai' ? 'day' : frequency
}${ical.INTERVAL > 1 ? 's' : ''}${
ical.COUNT
? ` for ${ical.COUNT} times`
: ical.UNTIL
? ' until end date'
: ''
}`;
output += '\n';
} else if (json.schedule) {
output += `**Schedule:** Not defined\n`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Start: 2020-05-13 18:30:32.11-06:00 +01:00
* End: 2079-06-06 21:00:00-06:00 +01:00
* Timezone: W. Europe Standard Time
* Recurrance: every 5 minutes
* Recurrance: every 5 minutes until end date

**Notifications:** _none_

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Start: 2022-07-30 00:00:00 +01:00
* End: 2022-07-30 00:00:00 +01:00
* Timezone: W. Europe Standard Time
* Recurrance: every day for 1 times
* Recurrance: run only once

**Notifications:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Start: 2022-07-30 00:00:00 +01:00
* End: 2022-07-30 00:00:00 +01:00
* Timezone: W. Europe Standard Time
* Recurrance: every day for 1 times
* Recurrance: run only once

**Notifications:** _none_

Expand Down

0 comments on commit 6ff3836

Please sign in to comment.