diff --git a/src/server/entities/queue-run.ts b/src/server/entities/queue-run.ts index 2dcb9698..f4e237c0 100644 --- a/src/server/entities/queue-run.ts +++ b/src/server/entities/queue-run.ts @@ -1,5 +1,6 @@ import type { Queue } from './queue' import type { QueueRun as QueueRunBase } from './base' +import { createQueue } from './queue' export interface QueueRun extends Required { /** @@ -53,14 +54,14 @@ export interface QueueRun extends Required { options: Options /** - * The reason the queue run failed. + * The parent queue as Queue. */ - reason: string | null + queue: Queue /** - * The parent queue as Queue. + * The reason the queue run failed. */ - queue?: Queue + reason: string | null /** * The status. @@ -68,20 +69,21 @@ export interface QueueRun extends Required { status: 'err' | 'ok' | 'pending' } -export function createQueueRun (queue?: Queue): QueueRun { +export function createQueueRun> (queueRun?: Partial>): QueueRun { return { aggr_err: 0, aggr_ok: 0, aggr_total: 0, date_created: new Date(), date_updated: new Date(), - fkey_queue_id: queue?.id ?? 0, + fkey_queue_id: queueRun?.queue?.id ?? 0, fkey_task_run_id: null, id: 0, - name: queue?.name ?? 'name', - options: (queue?.options ?? {}) as Options, - queue, + name: queueRun?.queue?.name ?? 'name', + options: (queueRun?.queue?.options ?? {}) as Options, + queue: queueRun?.queue ?? createQueue(), reason: null, - status: 'pending' + status: 'pending', + ...queueRun } } diff --git a/src/server/entities/queue.ts b/src/server/entities/queue.ts index b88546bf..6d6f6243 100644 --- a/src/server/entities/queue.ts +++ b/src/server/entities/queue.ts @@ -66,7 +66,7 @@ export interface Queue extends Required { schedule_next: Date | null } -export function createQueue (options?: Options): Queue { +export function createQueue> (queue?: Partial>): Queue { return { database: 'database', date_created: new Date(), @@ -74,7 +74,7 @@ export function createQueue (options?: Options): Queue { fkey_queue_id: 0, id: 0, name: 'name', - options: (options ?? {}) as Options, + options: (queue?.options ?? {}) as Options, query: '', schedule: '', schedule_begin: null, diff --git a/src/server/entities/task-run.ts b/src/server/entities/task-run.ts index 5afcd67d..2e71cc01 100644 --- a/src/server/entities/task-run.ts +++ b/src/server/entities/task-run.ts @@ -64,7 +64,7 @@ export interface TaskRun status: 'err' | 'ok' | 'pending' } -export function createTaskRun (payload?: Payload): TaskRun { +export function createTaskRun, Options = Record, Result = Record> (taskRun?: Partial>): TaskRun { return { date_created: new Date(), date_queued: null, @@ -73,10 +73,11 @@ export function createTaskRun (payload?: Payload): Tas fkey_queue_run_id: 0, host: null, id: 0, - payload: (payload ?? {}) as Payload, - queueRun: createQueueRun(), + payload: Object.create(null) as Payload, + queueRun: taskRun?.queueRun ?? createQueueRun(), reason: null, result: Object.create(null) as Result, - status: 'pending' + status: 'pending', + ...taskRun } } diff --git a/src/server/helpers/queue/queue-runner.ts b/src/server/helpers/queue/queue-runner.ts index 08415ad0..48075c1d 100644 --- a/src/server/helpers/queue/queue-runner.ts +++ b/src/server/helpers/queue/queue-runner.ts @@ -114,7 +114,7 @@ export class QueueRunner { * @param parameters - The parameters for the generator query */ public async run (queue: Queue, parameters?: Record): Promise { - const queueRun: QueueRun = createQueueRun(queue) + const queueRun: QueueRun = createQueueRun({ queue }) const { id: queueRunId } = await this.insertQueueRun(queueRun) queueRun.id = queueRunId @@ -168,7 +168,7 @@ export class QueueRunner { $(options) ) `, { - fkey_queue_id: queueRun.queue?.id, + fkey_queue_id: queueRun.queue.id, name: queueRun.name, options: queueRun.options })