Skip to content

Commit

Permalink
fix(dobj): support updatedAt as Date or iso String
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Jun 7, 2024
1 parent 727c07d commit 1bd381d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/domain/objects/AsyncTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ export enum AsyncTaskStatus {
*/
export interface AsyncTask {
uuid?: string;
updatedAt?: string;
updatedAt?: string | Date;
status: AsyncTaskStatus;
}
11 changes: 10 additions & 1 deletion src/logic/withAsyncTaskExecutionLifecycleExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ export const withAsyncTaskExecutionLifecycleExecute = <
// if the task was updated less than 15 minutes ago, then it may still be being attempted, so throw an error so this message will get retried eventually
const attemptTimeoutSeconds =
options?.attempt?.timeout.seconds ?? 15 * 60;
const updatedAtLast =
typeof foundTask.updatedAt === 'string'
? parseISO(foundTask.updatedAt)
: foundTask.updatedAt;
if (!updatedAtLast)
throw new UnexpectedCodePathError(
'task did not have an .updatedAt attribute. this is required for reliable async-tasks',
{ foundTask },
);
const attemptTimeoutAt = addSeconds(
parseISO(foundTask.updatedAt!),
updatedAtLast,
attemptTimeoutSeconds, // default to 15 min
);
const now = new Date();
Expand Down

0 comments on commit 1bd381d

Please sign in to comment.