Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/1048 rate limit automation retrieval & improve automation schedule documentation #1054

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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