-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Worker: Update version listings (#611)
* engine: publish versions with workflow-start and support multiple adaptors * worker: update version handling We only include versions on workflow start and allow multiple adaptor versions to be printed
- Loading branch information
1 parent
4f5f1dd
commit 58e0d11
Showing
21 changed files
with
254 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@openfn/engine-multi': patch | ||
--- | ||
|
||
Record adaptor versions as an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@openfn/ws-worker': patch | ||
--- | ||
|
||
Move version log to workflow start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { RunStartPayload } from '@openfn/lexicon/lightning'; | ||
import { timestamp } from '@openfn/logger'; | ||
import type { WorkflowStartPayload } from '@openfn/engine-multi'; | ||
|
||
import { RUN_START } from '../events'; | ||
import { sendEvent, Context, onJobLog } from '../api/execute'; | ||
import calculateVersionString from '../util/versions'; | ||
|
||
import pkg from '../../package.json' assert { type: 'json' }; | ||
|
||
export default async function onRunStart( | ||
context: Context, | ||
event: WorkflowStartPayload | ||
) { | ||
const { channel, state } = context; | ||
// Cheat on the timestamp time to make sure this is the first thing in the log | ||
const time = (timestamp() - BigInt(10e6)).toString(); | ||
|
||
// Send the log with its own little state object | ||
// to preserve the run id | ||
// Otherwise, by the time the log sends, | ||
// the active step could have changed | ||
// TODO if I fix ordering I think I can kill this | ||
const versionLogContext = { | ||
...context, | ||
state: { | ||
...state, | ||
activeStep: state.activeStep, | ||
}, | ||
}; | ||
|
||
const versions = { | ||
worker: pkg.version, | ||
...event.versions, | ||
}; | ||
|
||
await sendEvent<RunStartPayload>(channel, RUN_START, { versions }); | ||
|
||
const versionMessage = calculateVersionString(versions); | ||
|
||
await onJobLog(versionLogContext, { | ||
time, | ||
message: [versionMessage], | ||
level: 'info', | ||
name: 'VER', | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,25 @@ | ||
import crypto from 'node:crypto'; | ||
import { timestamp } from '@openfn/logger'; | ||
import { JobStartPayload } from '@openfn/engine-multi'; | ||
import type { Job } from '@openfn/lexicon'; | ||
import type { StepStartPayload } from '@openfn/lexicon/lightning'; | ||
|
||
import pkg from '../../package.json' assert { type: 'json' }; | ||
import { STEP_START } from '../events'; | ||
import { sendEvent, Context, onJobLog } from '../api/execute'; | ||
import calculateVersionString from '../util/versions'; | ||
import { sendEvent, Context } from '../api/execute'; | ||
|
||
export default async function onStepStart( | ||
context: Context, | ||
event: JobStartPayload | ||
) { | ||
// Cheat on the timestamp time to make sure this is the first thing in the log | ||
const time = (timestamp() - BigInt(10e6)).toString(); | ||
|
||
const { channel, state } = context; | ||
|
||
// generate a run id and write it to state | ||
state.activeStep = crypto.randomUUID(); | ||
state.activeJob = event.jobId; | ||
|
||
const job = state.plan.workflow.steps.find( | ||
({ id }) => id === event.jobId | ||
) as Job; | ||
|
||
const input_dataclip_id = state.inputDataclips[event.jobId]; | ||
|
||
const versions = { | ||
worker: pkg.version, | ||
...event.versions, | ||
}; | ||
|
||
// Send the log with its own little state object | ||
// to preserve the run id | ||
// Otherwise, by the time the log sends, | ||
// the active step could have changed | ||
// TODO if I fix ordering I think I can kill this | ||
const versionLogContext = { | ||
...context, | ||
state: { | ||
...state, | ||
activeStep: state.activeStep, | ||
}, | ||
}; | ||
|
||
await sendEvent<StepStartPayload>(channel, STEP_START, { | ||
step_id: state.activeStep!, | ||
job_id: state.activeJob!, | ||
input_dataclip_id, | ||
|
||
versions, | ||
}); | ||
|
||
const versionMessage = calculateVersionString( | ||
versionLogContext.state.activeStep, | ||
versions, | ||
job?.adaptor | ||
); | ||
|
||
await onJobLog(versionLogContext, { | ||
time, | ||
message: [versionMessage], | ||
level: 'info', | ||
name: 'VER', | ||
}); | ||
return; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.