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

engine: Include timestamp on JOB_ERROR #793

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/healthy-kangaroos-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/engine-multi': minor
---

Include timestamp on JOB_ERROR payload
1 change: 1 addition & 0 deletions packages/engine-multi/src/api/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export const jobError = (
duration,
jobId,
next,
time: timestamp(),
});
};

Expand Down
1 change: 1 addition & 0 deletions packages/engine-multi/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface JobCompletePayload extends ExternalEvent {
export interface JobErrorPayload extends ExternalEvent {
jobId: string;
duration: number;
time: bigint;
state: any; // the result state
error: any;
next: string[]; // downstream jobs
Expand Down
44 changes: 44 additions & 0 deletions packages/engine-multi/test/api/lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
jobStart,
jobComplete,
error,
jobError,
} from '../../src/api/lifecycle';
import { WorkflowState } from '../../src/types';
import ExecutionContext from '../../src/classes/ExecutionContext';
Expand Down Expand Up @@ -194,6 +195,49 @@ test(`job-complete: emits ${e.JOB_COMPLETE} with key fields`, (t) => {
});
});

test(`job-error: emits ${e.JOB_ERROR} with key fields`, (t) => {
return new Promise((done) => {
const workflowId = 'a';

const state = {
id: workflowId,
startTime: Date.now() - 1000,
} as WorkflowState;

const context = createContext(workflowId, state);

const event: w.JobErrorEvent = {
type: w.JOB_ERROR,
error: {
message: 'Unexpected content returned',
name: 'JobError',
severity: 'fail',
},
workflowId,
threadId: '1',
jobId: 'j',
duration: 2,
state: 22,
next: [],
};

context.on(e.JOB_ERROR, (evt) => {
t.is(evt.workflowId, workflowId);
t.is(evt.threadId, '1');
t.is(evt.jobId, 'j');
t.is(evt.state, 22);
t.is(evt.duration, 2);
t.deepEqual(evt.next, []);
t.deepEqual(evt.error, event.error);
t.assert(evt.time > 0);
t.assert(typeof evt.time === 'bigint');
done();
});

jobError(context, event);
});
});

test(`log: emits ${e.WORKFLOW_LOG}`, (t) => {
return new Promise((done) => {
const workflowId = 'a';
Expand Down
Loading