Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @openfn/cli

## 1.39.4

### Patch Changes

- Updated dependencies [e3ddfef]
- @openfn/lexicon@2.4.1

## 1.39.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/cli",
"version": "1.39.3",
"version": "1.39.4",
"description": "CLI devtools for the OpenFn toolchain",
"engines": {
"node": ">=18",
Expand Down
6 changes: 6 additions & 0 deletions packages/lexicon/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# lexicon

## 2.4.1

### Patch Changes

- e3ddfef: Support metadata on the run object

## 2.4.0

### Minor Changes
Expand Down
8 changes: 8 additions & 0 deletions packages/lexicon/lightning.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ export type LightningPlan = {
options?: LightningPlanOptions;

globals?: string;

meta?: LightningPlanMeta;
};

export type LightningPlanMeta = {
work_order_id?: string;
workflow_id?: string;
project_id?: string;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/lexicon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/lexicon",
"version": "2.4.0",
"version": "2.4.1",
"description": "Central repo of names and type definitions",
"author": "Open Function Group <admin@openfn.org>",
"license": "ISC",
Expand Down
8 changes: 8 additions & 0 deletions packages/ws-worker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# ws-worker

## 1.29.1

### Patch Changes

- e3ddfef: Support metadata on the run object
- Updated dependencies [e3ddfef]
- @openfn/lexicon@2.4.1

## 1.29.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-worker/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openfn/ws-worker",
"version": "1.29.0",
"version": "1.29.1",
"description": "A Websocket Worker to connect Lightning to a Runtime Engine",
"main": "dist/index.js",
"type": "module",
Expand Down
12 changes: 12 additions & 0 deletions packages/ws-worker/src/util/convert-lightning-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,22 @@ export default (
// But some need to get passed down into the engine's options
const engineOpts: WorkerRunOptions = {};

// Lightning only sends run.meta from 2.18.0. Older versions get a meta global
// with just the run id, rather than a set of undefined keys. project_id is on
// the plan itself, so it's available whatever version we're talking to.
const ids = {
workOrderId: run.meta?.work_order_id,
workflowId: run.meta?.workflow_id,
projectId: run.meta?.project_id ?? run.project_id,
};

engineOpts.globals = {
meta: {
runId: run.id,
startTime: Date.now(),
...Object.fromEntries(
Object.entries(ids).filter(([_key, value]) => value !== undefined)
),
},
};

Expand Down
50 changes: 50 additions & 0 deletions packages/ws-worker/test/util/convert-lightning-plan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,53 @@ test('sets runId and startTime on the engine options globals meta', (t) => {
t.true(options.globals!.meta.startTime >= before);
t.true(options.globals!.meta.startTime <= after);
});

test('maps run.meta work order/workflow/project ids onto globals meta', (t) => {
const run: Partial<LightningPlan> = {
id: 'some-run-id',
jobs: [createNode()],
triggers: [],
edges: [],
meta: {
work_order_id: 'some-work-order-id',
workflow_id: 'some-workflow-id',
project_id: 'some-project-id',
},
};

const { options } = convertPlan(run as LightningPlan);

t.is(options.globals!.meta.workOrderId, 'some-work-order-id');
t.is(options.globals!.meta.workflowId, 'some-workflow-id');
t.is(options.globals!.meta.projectId, 'some-project-id');
});

test('takes projectId from the plan when run.meta is missing', (t) => {
const run: Partial<LightningPlan> = {
id: 'some-run-id',
project_id: 'some-project-id',
jobs: [createNode()],
triggers: [],
edges: [],
};

const { options } = convertPlan(run as LightningPlan);

t.is(options.globals!.meta.projectId, 'some-project-id');
});

test('omits globals meta ids when run.meta is missing', (t) => {
const run: Partial<LightningPlan> = {
id: 'some-run-id',
jobs: [createNode()],
triggers: [],
edges: [],
};

const { options } = convertPlan(run as LightningPlan);

t.deepEqual(Object.keys(options.globals!.meta).sort(), [
'runId',
'startTime',
]);
});