diff --git a/lib/metadataTypes/Automation.js b/lib/metadataTypes/Automation.js index 119681b0f..ec2bcc3e7 100644 --- a/lib/metadataTypes/Automation.js +++ b/lib/metadataTypes/Automation.js @@ -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; - } - }) + }) + ) ) : []; @@ -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`; } diff --git a/test/resources/9999999/automation/create-testNew_automation-expected.md b/test/resources/9999999/automation/create-testNew_automation-expected.md index c607175cc..ce52ff454 100644 --- a/test/resources/9999999/automation/create-testNew_automation-expected.md +++ b/test/resources/9999999/automation/create-testNew_automation-expected.md @@ -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_ diff --git a/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md b/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md index ae8f4c10a..6c22b1c53 100644 --- a/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md +++ b/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md @@ -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:** diff --git a/test/resources/9999999/automation/update-testExisting_automation-expected.md b/test/resources/9999999/automation/update-testExisting_automation-expected.md index fbee3558c..fb007b2df 100644 --- a/test/resources/9999999/automation/update-testExisting_automation-expected.md +++ b/test/resources/9999999/automation/update-testExisting_automation-expected.md @@ -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_