Skip to content

Commit

Permalink
support job log level in lightning plan
Browse files Browse the repository at this point in the history
  • Loading branch information
midigofrank committed Feb 11, 2025
1 parent 9202fb2 commit 097d58e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/engine-multi/src/worker/thread/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import process from 'node:process';
import stringify from 'fast-safe-stringify';
import createLogger, { SanitizePolicies } from '@openfn/logger';
import type { JSONLog } from '@openfn/logger';
import type { JSONLog, LogLevel } from '@openfn/logger';

import * as workerEvents from '../events';
import { HANDLED_EXIT_CODE } from '../../events';
Expand All @@ -14,7 +14,8 @@ import serializeError from '../../util/serialize-error';
export const createLoggers = (
workflowId: string,
sanitize: SanitizePolicies = 'none',
publish?: any
publish?: any,
jobLogLevel: LogLevel = 'debug'
) => {
const log = (message: JSONLog) => {
publish(workerEvents.LOG, {
Expand Down Expand Up @@ -47,7 +48,7 @@ export const createLoggers = (

const jobLogger = createLogger('JOB', {
logger: emitter,
level: 'debug',
level: jobLogLevel,
json: true,
sanitize,
});
Expand Down
9 changes: 6 additions & 3 deletions packages/engine-multi/src/worker/thread/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import run from '@openfn/runtime';
import type { NotifyEvents } from '@openfn/runtime';
import type { ExecutionPlan, State } from '@openfn/lexicon';
import type { SanitizePolicies } from '@openfn/logger';
import type { LogLevel, SanitizePolicies } from '@openfn/logger';

import { register, publish } from './runtime';
import { execute, createLoggers } from './helpers';
Expand All @@ -15,6 +15,7 @@ export type RunOptions = {
whitelist?: RegExp[];
sanitize: SanitizePolicies;
statePropsToRemove?: string[];
jobLogLevel?: LogLevel;
};

const eventMap = {
Expand All @@ -26,11 +27,13 @@ const eventMap = {

register({
run: (plan: ExecutionPlan, input: State, runOptions: RunOptions) => {
const { repoDir, whitelist, sanitize, statePropsToRemove } = runOptions;
const { repoDir, whitelist, sanitize, statePropsToRemove, jobLogLevel } =
runOptions;
const { logger, jobLogger, adaptorLogger } = createLoggers(
plan.id!,
sanitize,
publish
publish,
jobLogLevel
);

// Save the debug function so that we can use it
Expand Down
3 changes: 2 additions & 1 deletion packages/lexicon/lightning.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SanitizePolicies } from '@openfn/logger';
import type { LogLevel, SanitizePolicies } from '@openfn/logger';
import { LegacyJob, State } from './core';

export const API_VERSION: number;
Expand Down Expand Up @@ -50,6 +50,7 @@ export type LightningPlanOptions = {

run_memory_limit_mb?: number;
payload_limit_mb?: number;
job_log_level?: LogLevel;
};

/**
Expand Down
5 changes: 5 additions & 0 deletions packages/ws-worker/src/util/convert-lightning-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
WorkflowOptions,
Lazy,
} from '@openfn/lexicon';
import type { LogLevel } from '@openfn/logger';
import { LightningPlan, LightningEdge } from '@openfn/lexicon/lightning';
import { ExecuteOptions } from '@openfn/engine-multi';
import { getNameAndVersion } from '@openfn/runtime';
Expand Down Expand Up @@ -46,6 +47,7 @@ export type WorkerRunOptions = ExecuteOptions & {
// Defaults to true - must be explicity false to stop dataclips being sent
outputDataclips?: boolean;
payloadLimitMb?: number;
jobLogLevel?: LogLevel;
};

type ConversionOptions = {
Expand Down Expand Up @@ -124,6 +126,9 @@ export default (
if ('output_dataclips' in run.options) {
engineOpts.outputDataclips = run.options.output_dataclips;
}
if ('job_log_level' in run.options) {
engineOpts.jobLogLevel = run.options.job_log_level;
}
}

const plan: Partial<ExecutionPlan> = {
Expand Down

0 comments on commit 097d58e

Please sign in to comment.