Skip to content

Commit 5a90831

Browse files
committed
Fix force step timeout
1 parent 251563b commit 5a90831

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

packages/workflows-shared/src/context.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ const defaultConfig: Required<WorkflowStepConfig> = {
2929
retries: {
3030
limit: 5,
3131
delay: 1000,
32-
backoff: "constant",
32+
backoff: "exponential",
3333
},
34-
timeout: "15 minutes",
34+
timeout: "10 minutes",
3535
};
3636

3737
export interface UserErrorField {
@@ -240,20 +240,12 @@ export class Context extends RpcTarget {
240240
const { accountId, instance } = instanceMetadata;
241241

242242
try {
243-
const forceStepTimeoutKey = `force-step-timeout-${valueKey}`;
244-
const forceStepTimeout =
245-
(await this.#state.storage.get(forceStepTimeoutKey)) ||
246-
(await this.#state.storage.get(
247-
`${forceStepTimeoutKey}-${stepState.attemptedCount}`
248-
));
249-
250243
const timeoutPromise = async () => {
251244
const priorityQueueHash = `${cacheKey}-${stepState.attemptedCount}`;
252245
// inserir aqui
253246
let timeout = ms(config.timeout);
254247
if (forceStepTimeout) {
255248
timeout = 0;
256-
console.log("[Context] I will timeout");
257249
}
258250
// @ts-expect-error priorityQueue is initiated in init
259251
await this.#engine.priorityQueue.add({
@@ -286,7 +278,7 @@ export class Context extends RpcTarget {
286278
await this.#state.storage.put(stepStateKey, stepState);
287279
const priorityQueueHash = `${cacheKey}-${stepState.attemptedCount}`;
288280

289-
const mockErrorKey = `mock-error-${valueKey}`;
281+
const mockErrorKey = `mock-step-error-${valueKey}`;
290282
const mockedErrorPayload =
291283
(await this.#state.storage.get<{
292284
name: string;
@@ -301,24 +293,25 @@ export class Context extends RpcTarget {
301293
if (mockedErrorPayload) {
302294
const errorToThrow = new Error(mockedErrorPayload.message);
303295
errorToThrow.name = mockedErrorPayload.name;
304-
console.log("[Context.do()] Will throw an error for step:", name);
305296
throw errorToThrow;
306297
}
307298

308299
const replaceResult = await this.#state.storage.get(
309300
`replace-result-${valueKey}`
310301
);
311-
if (replaceResult) {
312-
console.log(
313-
"[Context.do()] Will replace the result of step:",
314-
name,
315-
"with:",
316-
replaceResult
317-
);
302+
const forceStepTimeoutKey = `force-step-timeout-${valueKey}`;
303+
const forceStepTimeout =
304+
(await this.#state.storage.get(forceStepTimeoutKey)) ||
305+
(await this.#state.storage.get(
306+
`${forceStepTimeoutKey}-${stepState.attemptedCount}`
307+
));
308+
309+
if (forceStepTimeout) {
310+
result = await timeoutPromise();
311+
} else if (replaceResult) {
318312
result = replaceResult;
313+
await this.#state.storage.delete(`replace-result-${valueKey}`);
319314
// if there is a timeout to be forced we dont want to race with closure
320-
} else if (forceStepTimeout) {
321-
result = await timeoutPromise();
322315
} else {
323316
result = await Promise.race([doWrapperClosure(), timeoutPromise()]);
324317
}
@@ -441,8 +434,6 @@ export class Context extends RpcTarget {
441434
// TODO (WOR-71): Think through if every Error should transition
442435
const durationMs = calcRetryDuration(config, stepState);
443436

444-
console.log("Vou esperar", durationMs);
445-
446437
const priorityQueueHash = `${cacheKey}-${stepState.attemptedCount}`;
447438
// @ts-expect-error priorityQueue is initiated in init
448439
await this.#engine.priorityQueue.add({
@@ -674,7 +665,7 @@ export class Context extends RpcTarget {
674665
})) ||
675666
(timeoutEntryPQ !== undefined &&
676667
timeoutEntryPQ.targetTimestamp < Date.now()) ||
677-
(await this.#state.storage.get(`forceEventTimeout-${waitForEventKey}`))
668+
(await this.#state.storage.get(`force-event-timeout-${waitForEventKey}`))
678669
) {
679670
this.#engine.writeLog(
680671
InstanceEvent.WAIT_TIMED_OUT,
@@ -741,7 +732,6 @@ export class Context extends RpcTarget {
741732
: timeoutPromise(ms(options.timeout), true),
742733
])
743734
.then(async (event) => {
744-
console.log(event);
745735
this.#engine.writeLog(
746736
InstanceEvent.WAIT_COMPLETE,
747737
cacheKey,

0 commit comments

Comments
 (0)