Skip to content

Commit eb8e1d0

Browse files
committed
added throttle by defer
1 parent 79458c6 commit eb8e1d0

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/workflows/WorkflowContext.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,19 @@ export default class WorkflowContext {
227227
let throttleGroup = null;
228228

229229
if (throttle) {
230-
const { deferSeconds } = throttle;
230+
const { deferSeconds, group } = throttle;
231231
if (deferSeconds) {
232232
const lw = await this.storage.getLastEta(throttle);
233233
if (lw) {
234234
return lw.id;
235235
}
236+
eta = DateTime.now.addSeconds(deferSeconds);
237+
queued = eta;
238+
throttleGroup = group;
236239
} else {
237240
eta = await this.storage.getNextEta(throttle);
238241
queued = eta;
239-
throttleGroup = throttle.group;
242+
throttleGroup = group;
240243
}
241244
}
242245

src/workflows/WorkflowStorage.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,18 @@ import Sql from "../sql/Sql.js";
1212

1313
export type IWorkflowThrottleGroup = {
1414
group: string;
15+
/**
16+
* Throttling based on defer, the workflow will be scheduled in future
17+
* only if current workflow in same throttle group is queued or running.
18+
*/
1519
deferSeconds?: number;
1620
maxPerSecond?: never;
1721
} | {
1822
group: string;
1923
deferSeconds?: never;
24+
/**
25+
* Throttled on based on maximum iterations per second.
26+
*/
2027
maxPerSecond?: number;
2128
};
2229

0 commit comments

Comments
 (0)