mirror of
https://github.com/immich-app/immich
synced 2026-08-15 13:03:57 +00:00
feat: workflow logging (#29878)
* feat: workflow logging * chore: update sql and openapi patch * chore: include id in workflow log entries * chore(server): update sql and lint * chore(mobile): remove openapi files * chore(web): lint * chore: clean up workflow logging * chore(server): add runId to workflow logs * chore(server): store workflow results as enum
This commit is contained in:
parent
af33a78d18
commit
447cc40a50
20 changed files with 689 additions and 22 deletions
|
|
@ -1788,6 +1788,7 @@
|
|||
"restore_all": "Restore all",
|
||||
"restore_user": "Restore user",
|
||||
"restored_asset": "Restored asset",
|
||||
"result": "Result",
|
||||
"resume": "Resume",
|
||||
"resume_paused_jobs": "Resume {count, plural, one {# paused job} other {# paused jobs}}",
|
||||
"review_duplicates": "Review duplicates",
|
||||
|
|
@ -2278,6 +2279,13 @@
|
|||
"workflow_info": "Workflow info",
|
||||
"workflow_json": "Workflow JSON",
|
||||
"workflow_json_help": "Edit the workflow configuration in JSON format. Changes will sync to the visual builder.",
|
||||
"workflow_logging_completed": "Completed",
|
||||
"workflow_logging_disable": "Disable logging",
|
||||
"workflow_logging_disabled_description": "Logging is currently disabled for this workflow.",
|
||||
"workflow_logging_enable": "Enable logging",
|
||||
"workflow_logging_error_step": "Error on step #{step}",
|
||||
"workflow_logging_halted": "Halted",
|
||||
"workflow_logging_halted_step": "Halted on step #{step}",
|
||||
"workflow_name": "Workflow name",
|
||||
"workflow_navigation_prompt": "Are you sure you want to leave without saving your changes?",
|
||||
"workflow_summary": "Workflow summary",
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ final Map<String, Map<String, Object?>> openApiPatches = {
|
|||
'SyncAssetV1': {'isEdited': false},
|
||||
'ServerFeaturesDto': {'ocr': false, 'realtimeTranscoding': false},
|
||||
'MemoriesResponse': {'duration': 5},
|
||||
'WorkflowResponseDto': {'logging': false},
|
||||
};
|
||||
|
||||
void upgradeDto(dynamic value, String targetType) {
|
||||
|
|
|
|||
|
|
@ -15873,6 +15873,15 @@
|
|||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "logging",
|
||||
"required": false,
|
||||
"in": "query",
|
||||
"description": "Workflow logs run results",
|
||||
"schema": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "name",
|
||||
"required": false,
|
||||
|
|
@ -16186,6 +16195,95 @@
|
|||
"x-immich-state": "Deprecated"
|
||||
}
|
||||
},
|
||||
"/workflows/{id}/logs": {
|
||||
"get": {
|
||||
"description": "Retrieve logs of a workflows runs by ID",
|
||||
"operationId": "getWorkflowLogs",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "before",
|
||||
"required": false,
|
||||
"in": "query",
|
||||
"description": "Filter by runs before a date/time",
|
||||
"schema": {
|
||||
"format": "date-time",
|
||||
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
|
||||
"example": "2024-01-01T00:00:00.000Z",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "id",
|
||||
"required": true,
|
||||
"in": "path",
|
||||
"schema": {
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"in": "query",
|
||||
"description": "Maximum number of logs",
|
||||
"schema": {
|
||||
"maximum": 9007199254740991,
|
||||
"exclusiveMinimum": true,
|
||||
"default": 50,
|
||||
"type": "integer",
|
||||
"minimum": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "result",
|
||||
"required": false,
|
||||
"in": "query",
|
||||
"description": "Filter by run result",
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/WorkflowResult"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/WorkflowLogEntryDto"
|
||||
},
|
||||
"type": "array"
|
||||
}
|
||||
}
|
||||
},
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"bearer": []
|
||||
},
|
||||
{
|
||||
"cookie": []
|
||||
},
|
||||
{
|
||||
"api_key": []
|
||||
}
|
||||
],
|
||||
"summary": "Retrieve workflow logs",
|
||||
"tags": [
|
||||
"Workflows"
|
||||
],
|
||||
"x-immich-history": [
|
||||
{
|
||||
"version": "v3.0.0",
|
||||
"state": "Added"
|
||||
}
|
||||
],
|
||||
"x-immich-permission": "workflow.logs"
|
||||
}
|
||||
},
|
||||
"/workflows/{id}/share": {
|
||||
"get": {
|
||||
"description": "Retrieve a workflow details without ids, default values, etc.",
|
||||
|
|
@ -21057,6 +21155,7 @@
|
|||
"workflow.read",
|
||||
"workflow.update",
|
||||
"workflow.delete",
|
||||
"workflow.logs",
|
||||
"adminUser.create",
|
||||
"adminUser.read",
|
||||
"adminUser.update",
|
||||
|
|
@ -27909,6 +28008,10 @@
|
|||
"description": "Workflow enabled",
|
||||
"type": "boolean"
|
||||
},
|
||||
"logging": {
|
||||
"description": "Workflow logs run results",
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"description": "Workflow name",
|
||||
"nullable": true,
|
||||
|
|
@ -27930,6 +28033,59 @@
|
|||
],
|
||||
"type": "object"
|
||||
},
|
||||
"WorkflowLogEntryDto": {
|
||||
"properties": {
|
||||
"at": {
|
||||
"description": "Workflow run date/time",
|
||||
"example": "2024-01-01T00:00:00.000Z",
|
||||
"format": "date-time",
|
||||
"pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:\\.\\d+)?)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$",
|
||||
"type": "string"
|
||||
},
|
||||
"id": {
|
||||
"description": "Workflow log entry ID",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$",
|
||||
"type": "string"
|
||||
},
|
||||
"lastStep": {
|
||||
"description": "Last step ran, if the workflow ended early",
|
||||
"properties": {
|
||||
"index": {
|
||||
"description": "Index of the step in the workflow",
|
||||
"exclusiveMinimum": true,
|
||||
"maximum": 9007199254740991,
|
||||
"minimum": 0,
|
||||
"type": "integer"
|
||||
},
|
||||
"method": {
|
||||
"description": "Method of the step",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"method",
|
||||
"index"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"result": {
|
||||
"$ref": "#/components/schemas/WorkflowResult"
|
||||
},
|
||||
"triggerDataId": {
|
||||
"description": "Workflow trigger data ID",
|
||||
"format": "uuid",
|
||||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"at",
|
||||
"id",
|
||||
"result"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"WorkflowResponseDto": {
|
||||
"properties": {
|
||||
"createdAt": {
|
||||
|
|
@ -27951,6 +28107,10 @@
|
|||
"pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$",
|
||||
"type": "string"
|
||||
},
|
||||
"logging": {
|
||||
"description": "Workflow logs run results",
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"description": "Workflow name",
|
||||
"nullable": true,
|
||||
|
|
@ -27977,6 +28137,7 @@
|
|||
"description",
|
||||
"enabled",
|
||||
"id",
|
||||
"logging",
|
||||
"name",
|
||||
"steps",
|
||||
"trigger",
|
||||
|
|
@ -27984,6 +28145,15 @@
|
|||
],
|
||||
"type": "object"
|
||||
},
|
||||
"WorkflowResult": {
|
||||
"description": "Workflow run result",
|
||||
"enum": [
|
||||
"completed",
|
||||
"halted",
|
||||
"error"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"WorkflowShareResponseDto": {
|
||||
"properties": {
|
||||
"description": {
|
||||
|
|
@ -28109,6 +28279,10 @@
|
|||
"description": "Workflow enabled",
|
||||
"type": "boolean"
|
||||
},
|
||||
"logging": {
|
||||
"description": "Workflow logs run results",
|
||||
"type": "boolean"
|
||||
},
|
||||
"name": {
|
||||
"description": "Workflow name",
|
||||
"nullable": true,
|
||||
|
|
|
|||
|
|
@ -2791,6 +2791,8 @@ export type WorkflowResponseDto = {
|
|||
enabled: boolean;
|
||||
/** Workflow ID */
|
||||
id: string;
|
||||
/** Workflow logs run results */
|
||||
logging: boolean;
|
||||
/** Workflow name */
|
||||
name: string | null;
|
||||
/** Workflow steps */
|
||||
|
|
@ -2805,6 +2807,8 @@ export type WorkflowCreateDto = {
|
|||
description?: string | null;
|
||||
/** Workflow enabled */
|
||||
enabled?: boolean;
|
||||
/** Workflow logs run results */
|
||||
logging?: boolean;
|
||||
/** Workflow name */
|
||||
name?: string | null;
|
||||
steps?: WorkflowStepDto[];
|
||||
|
|
@ -2822,12 +2826,30 @@ export type WorkflowUpdateDto = {
|
|||
description?: string | null;
|
||||
/** Workflow enabled */
|
||||
enabled?: boolean;
|
||||
/** Workflow logs run results */
|
||||
logging?: boolean;
|
||||
/** Workflow name */
|
||||
name?: string | null;
|
||||
steps?: WorkflowStepDto[];
|
||||
/** Workflow trigger type */
|
||||
trigger?: WorkflowTrigger;
|
||||
};
|
||||
export type WorkflowLogEntryDto = {
|
||||
/** Workflow run date/time */
|
||||
at: string;
|
||||
/** Workflow log entry ID */
|
||||
id: string;
|
||||
/** Last step ran, if the workflow ended early */
|
||||
lastStep?: {
|
||||
/** Index of the step in the workflow */
|
||||
index: number;
|
||||
/** Method of the step */
|
||||
method: string;
|
||||
};
|
||||
result: WorkflowResult;
|
||||
/** Workflow trigger data ID */
|
||||
triggerDataId?: string;
|
||||
};
|
||||
export type WorkflowShareStepDto = {
|
||||
/** Step configuration */
|
||||
config: {
|
||||
|
|
@ -6977,10 +6999,11 @@ export function getUniqueOriginalPaths(opts?: Oazapfts.RequestOpts) {
|
|||
/**
|
||||
* List all workflows
|
||||
*/
|
||||
export function searchWorkflows({ description, enabled, id, name, trigger }: {
|
||||
export function searchWorkflows({ description, enabled, id, logging, name, trigger }: {
|
||||
description?: string;
|
||||
enabled?: boolean;
|
||||
id?: string;
|
||||
logging?: boolean;
|
||||
name?: string;
|
||||
trigger?: WorkflowTrigger;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
|
|
@ -6991,6 +7014,7 @@ export function searchWorkflows({ description, enabled, id, name, trigger }: {
|
|||
description,
|
||||
enabled,
|
||||
id,
|
||||
logging,
|
||||
name,
|
||||
trigger
|
||||
}))}`, {
|
||||
|
|
@ -7063,6 +7087,26 @@ export function updateWorkflow({ id, workflowUpdateDto }: {
|
|||
body: workflowUpdateDto
|
||||
})));
|
||||
}
|
||||
/**
|
||||
* Retrieve workflow logs
|
||||
*/
|
||||
export function getWorkflowLogs({ before, id, limit, result }: {
|
||||
before?: string;
|
||||
id: string;
|
||||
limit?: number;
|
||||
result?: WorkflowResult;
|
||||
}, opts?: Oazapfts.RequestOpts) {
|
||||
return oazapfts.ok(oazapfts.fetchJson<{
|
||||
status: 200;
|
||||
data: WorkflowLogEntryDto[];
|
||||
}>(`/workflows/${encodeURIComponent(id)}/logs${QS.query(QS.explode({
|
||||
before,
|
||||
limit,
|
||||
result
|
||||
}))}`, {
|
||||
...opts
|
||||
}));
|
||||
}
|
||||
/**
|
||||
* Retrieve a workflow
|
||||
*/
|
||||
|
|
@ -7310,6 +7354,7 @@ export enum Permission {
|
|||
WorkflowRead = "workflow.read",
|
||||
WorkflowUpdate = "workflow.update",
|
||||
WorkflowDelete = "workflow.delete",
|
||||
WorkflowLogs = "workflow.logs",
|
||||
AdminUserCreate = "adminUser.create",
|
||||
AdminUserRead = "adminUser.read",
|
||||
AdminUserUpdate = "adminUser.update",
|
||||
|
|
@ -7687,6 +7732,11 @@ export enum AssetOrderBy {
|
|||
TakenAt = "takenAt",
|
||||
CreatedAt = "createdAt"
|
||||
}
|
||||
export enum WorkflowResult {
|
||||
Completed = "completed",
|
||||
Halted = "halted",
|
||||
Error = "error"
|
||||
}
|
||||
export enum ReleaseType {
|
||||
Major = "major",
|
||||
Premajor = "premajor",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { Endpoint, HistoryBuilder } from 'src/decorators';
|
|||
import { AuthDto } from 'src/dtos/auth.dto';
|
||||
import {
|
||||
WorkflowCreateDto,
|
||||
WorkflowGetLogsDto,
|
||||
WorkflowLogEntryDto,
|
||||
WorkflowResponseDto,
|
||||
WorkflowSearchDto,
|
||||
WorkflowShareResponseDto,
|
||||
|
|
@ -113,4 +115,19 @@ export class WorkflowController {
|
|||
deleteWorkflow(@Auth() auth: AuthDto, @Param() { id }: UUIDParamDto): Promise<void> {
|
||||
return this.service.delete(auth, id);
|
||||
}
|
||||
|
||||
@Get(':id/logs')
|
||||
@Authenticated({ permission: Permission.WorkflowLogs })
|
||||
@Endpoint({
|
||||
summary: 'Retrieve workflow logs',
|
||||
description: 'Retrieve logs of a workflows runs by ID',
|
||||
history: HistoryBuilder.v3(),
|
||||
})
|
||||
getWorkflowLogs(
|
||||
@Auth() auth: AuthDto,
|
||||
@Param() { id }: UUIDParamDto,
|
||||
@Query() dto: WorkflowGetLogsDto,
|
||||
): Promise<WorkflowLogEntryDto[]> {
|
||||
return this.service.getLogs(auth, id, dto);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import type { WorkflowStepConfig, WorkflowTrigger } from '@immich/plugin-sdk';
|
||||
import { createZodDto } from 'nestjs-zod';
|
||||
import { WorkflowTriggerSchema, WorkflowTypeSchema } from 'src/enum';
|
||||
import { WorkflowResultSchema, WorkflowTriggerSchema, WorkflowTypeSchema } from 'src/enum';
|
||||
import { isoDatetimeToDate } from 'src/validation';
|
||||
import z from 'zod';
|
||||
|
||||
const WorkflowTriggerResponseSchema = z
|
||||
|
|
@ -17,6 +18,7 @@ const WorkflowSearchSchema = z
|
|||
name: z.string().optional().describe('Workflow name'),
|
||||
description: z.string().optional().describe('Workflow description'),
|
||||
enabled: z.boolean().optional().describe('Workflow enabled'),
|
||||
logging: z.boolean().optional().describe('Workflow logs run results'),
|
||||
})
|
||||
.meta({ id: 'WorkflowSearchDto' });
|
||||
|
||||
|
|
@ -42,6 +44,7 @@ const WorkflowCreateSchema = z
|
|||
name: z.string().nullable().optional().describe('Workflow name'),
|
||||
description: z.string().nullable().optional().describe('Workflow description'),
|
||||
enabled: z.boolean().optional().describe('Workflow enabled'),
|
||||
logging: z.boolean().optional().describe('Workflow logs run results'),
|
||||
steps: z.array(WorkflowStepSchema).optional(),
|
||||
})
|
||||
.meta({ id: 'WorkflowCreateDto' });
|
||||
|
|
@ -52,6 +55,7 @@ const WorkflowUpdateSchema = z
|
|||
name: z.string().nullable().optional().describe('Workflow name'),
|
||||
description: z.string().nullable().optional().describe('Workflow description'),
|
||||
enabled: z.boolean().optional().describe('Workflow enabled'),
|
||||
logging: z.boolean().optional().describe('Workflow logs run results'),
|
||||
steps: z.array(WorkflowStepSchema).optional(),
|
||||
})
|
||||
.meta({ id: 'WorkflowUpdateDto' });
|
||||
|
|
@ -65,6 +69,7 @@ const WorkflowResponseSchema = z
|
|||
createdAt: z.string().describe('Creation date'),
|
||||
updatedAt: z.string().describe('Update date'),
|
||||
enabled: z.boolean().describe('Workflow enabled'),
|
||||
logging: z.boolean().describe('Workflow logs run results'),
|
||||
steps: z.array(WorkflowStepSchema).describe('Workflow steps'),
|
||||
})
|
||||
.meta({ id: 'WorkflowResponseDto' });
|
||||
|
|
@ -78,12 +83,36 @@ const WorkflowShareResponseSchema = z
|
|||
})
|
||||
.meta({ id: 'WorkflowShareResponseDto' });
|
||||
|
||||
const WorkflowLogEntrySchema = z
|
||||
.object({
|
||||
id: z.uuidv4().describe('Workflow log entry ID'),
|
||||
at: isoDatetimeToDate.describe('Workflow run date/time'),
|
||||
result: WorkflowResultSchema.describe('Workflow run result'),
|
||||
triggerDataId: z.uuid().optional().describe('Workflow trigger data ID'),
|
||||
lastStep: z
|
||||
.object({
|
||||
method: z.string().describe('Method of the step'),
|
||||
index: z.int().positive().describe('Index of the step in the workflow'),
|
||||
})
|
||||
.optional()
|
||||
.describe('Last step ran, if the workflow ended early'),
|
||||
})
|
||||
.meta({ id: 'WorkflowLogEntryDto' });
|
||||
|
||||
const WorkflowGetLogsSchema = z.object({
|
||||
result: WorkflowResultSchema.optional().describe('Filter by run result'),
|
||||
before: isoDatetimeToDate.optional().describe('Filter by runs before a date/time'),
|
||||
limit: z.coerce.number().int().positive().default(50).describe('Maximum number of logs'),
|
||||
});
|
||||
|
||||
export class WorkflowTriggerResponseDto extends createZodDto(WorkflowTriggerResponseSchema) {}
|
||||
export class WorkflowSearchDto extends createZodDto(WorkflowSearchSchema) {}
|
||||
export class WorkflowCreateDto extends createZodDto(WorkflowCreateSchema) {}
|
||||
export class WorkflowUpdateDto extends createZodDto(WorkflowUpdateSchema) {}
|
||||
export class WorkflowResponseDto extends createZodDto(WorkflowResponseSchema) {}
|
||||
export class WorkflowShareResponseDto extends createZodDto(WorkflowShareResponseSchema) {}
|
||||
export class WorkflowLogEntryDto extends createZodDto(WorkflowLogEntrySchema) {}
|
||||
export class WorkflowGetLogsDto extends createZodDto(WorkflowGetLogsSchema) {}
|
||||
|
||||
type Workflow = {
|
||||
id: string;
|
||||
|
|
@ -93,6 +122,7 @@ type Workflow = {
|
|||
name: string | null;
|
||||
description: string | null;
|
||||
enabled: boolean;
|
||||
logging: boolean;
|
||||
};
|
||||
|
||||
type WorkflowStep = {
|
||||
|
|
@ -107,6 +137,7 @@ export const mapWorkflow = (workflow: Workflow & { steps: WorkflowStep[] }): Wor
|
|||
id: workflow.id,
|
||||
enabled: workflow.enabled,
|
||||
trigger: workflow.trigger,
|
||||
logging: workflow.logging,
|
||||
name: workflow.name,
|
||||
description: workflow.description,
|
||||
createdAt: workflow.createdAt.toISOString(),
|
||||
|
|
|
|||
|
|
@ -298,6 +298,7 @@ export enum Permission {
|
|||
WorkflowRead = 'workflow.read',
|
||||
WorkflowUpdate = 'workflow.update',
|
||||
WorkflowDelete = 'workflow.delete',
|
||||
WorkflowLogs = 'workflow.logs',
|
||||
|
||||
AdminUserCreate = 'adminUser.create',
|
||||
AdminUserRead = 'adminUser.read',
|
||||
|
|
@ -1235,6 +1236,17 @@ export enum CalendarHeatmapType {
|
|||
Taken = 'Taken',
|
||||
}
|
||||
|
||||
export enum WorkflowResult {
|
||||
Completed = 'completed',
|
||||
Halted = 'halted',
|
||||
Error = 'error',
|
||||
}
|
||||
|
||||
export const WorkflowResultSchema = z
|
||||
.enum(WorkflowResult)
|
||||
.describe('Workflow run result')
|
||||
.meta({ id: 'WorkflowResult' });
|
||||
|
||||
export enum SearchOrderField {
|
||||
FileCreatedAt = 'fileCreatedAt',
|
||||
LocalDateTime = 'localDateTime',
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ select
|
|||
"workflow"."enabled",
|
||||
"workflow"."createdAt",
|
||||
"workflow"."updatedAt",
|
||||
"workflow"."logging",
|
||||
(
|
||||
select
|
||||
coalesce(json_agg(agg), '[]')
|
||||
|
|
@ -43,6 +44,7 @@ select
|
|||
"workflow"."enabled",
|
||||
"workflow"."createdAt",
|
||||
"workflow"."updatedAt",
|
||||
"workflow"."logging",
|
||||
(
|
||||
select
|
||||
coalesce(json_agg(agg), '[]')
|
||||
|
|
@ -73,6 +75,7 @@ select
|
|||
"workflow"."id",
|
||||
"workflow"."name",
|
||||
"workflow"."trigger",
|
||||
"workflow"."logging",
|
||||
(
|
||||
select
|
||||
coalesce(json_agg(agg), '[]')
|
||||
|
|
@ -100,6 +103,39 @@ where
|
|||
"id" = $2
|
||||
and "enabled" = $3
|
||||
|
||||
-- WorkflowRepository.getLogs
|
||||
select
|
||||
"workflow_log"."id",
|
||||
"workflow_log"."createdAt",
|
||||
"workflow_log"."result",
|
||||
"workflow_log"."workflowId",
|
||||
"workflow_log"."workflowStepId",
|
||||
"workflow_log"."triggerDataId",
|
||||
(
|
||||
select
|
||||
to_json(obj)
|
||||
from
|
||||
(
|
||||
select
|
||||
"plugin_method"."pluginId",
|
||||
"plugin_method"."name" as "methodName",
|
||||
"workflow_step"."order"
|
||||
from
|
||||
"workflow_step"
|
||||
inner join "plugin_method" on "plugin_method"."id" = "workflow_step"."pluginMethodId"
|
||||
where
|
||||
"workflow_step"."id" = "workflow_log"."workflowStepId"
|
||||
) as obj
|
||||
) as "step"
|
||||
from
|
||||
"workflow_log"
|
||||
where
|
||||
"workflow_log"."workflowId" = $1
|
||||
order by
|
||||
"workflow_log"."createdAt" desc
|
||||
limit
|
||||
$2
|
||||
|
||||
-- WorkflowRepository.delete
|
||||
delete from "workflow"
|
||||
where
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres';
|
|||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import { columns } from 'src/database';
|
||||
import { DummyValue, GenerateSql } from 'src/decorators';
|
||||
import { WorkflowSearchDto } from 'src/dtos/workflow.dto';
|
||||
import { WorkflowGetLogsDto, WorkflowSearchDto } from 'src/dtos/workflow.dto';
|
||||
import { DB } from 'src/schema';
|
||||
import { WorkflowLogTable } from 'src/schema/tables/workflow-log.table';
|
||||
import { WorkflowStepTable } from 'src/schema/tables/workflow-step.table';
|
||||
import { WorkflowTable } from 'src/schema/tables/workflow.table';
|
||||
import { withTags } from 'src/utils/database';
|
||||
|
|
@ -27,6 +28,7 @@ export class WorkflowRepository {
|
|||
'workflow.enabled',
|
||||
'workflow.createdAt',
|
||||
'workflow.updatedAt',
|
||||
'workflow.logging',
|
||||
])
|
||||
.select((eb) => [
|
||||
jsonArrayFrom(
|
||||
|
|
@ -66,7 +68,7 @@ export class WorkflowRepository {
|
|||
getForWorkflowRun(id: string) {
|
||||
return this.db
|
||||
.selectFrom('workflow')
|
||||
.select(['workflow.id', 'workflow.name', 'workflow.trigger'])
|
||||
.select(['workflow.id', 'workflow.name', 'workflow.trigger', 'workflow.logging'])
|
||||
.select((eb) => [
|
||||
jsonArrayFrom(
|
||||
eb
|
||||
|
|
@ -99,6 +101,9 @@ export class WorkflowRepository {
|
|||
|
||||
update(id: string, dto: Updateable<WorkflowTable>, steps?: WorkflowStepUpsert[]) {
|
||||
return this.db.transaction().execute(async (tx) => {
|
||||
if (dto.logging === false) {
|
||||
await tx.deleteFrom('workflow_log').where('workflowId', '=', id).execute();
|
||||
}
|
||||
if (Object.values(dto).some((prop) => prop !== undefined)) {
|
||||
await tx.updateTable('workflow').set(dto).where('id', '=', id).executeTakeFirstOrThrow();
|
||||
}
|
||||
|
|
@ -106,6 +111,39 @@ export class WorkflowRepository {
|
|||
});
|
||||
}
|
||||
|
||||
@GenerateSql({ params: [DummyValue.UUID, { result: undefined }] })
|
||||
getLogs(id: string, dto: WorkflowGetLogsDto) {
|
||||
return this.db
|
||||
.selectFrom('workflow_log')
|
||||
.select([
|
||||
'workflow_log.id',
|
||||
'workflow_log.createdAt',
|
||||
'workflow_log.result',
|
||||
'workflow_log.workflowId',
|
||||
'workflow_log.workflowStepId',
|
||||
'workflow_log.triggerDataId',
|
||||
])
|
||||
.where('workflow_log.workflowId', '=', id)
|
||||
.select((eb) => [
|
||||
jsonObjectFrom(
|
||||
eb
|
||||
.selectFrom('workflow_step')
|
||||
.whereRef('workflow_step.id', '=', 'workflow_log.workflowStepId')
|
||||
.innerJoin('plugin_method', 'plugin_method.id', 'workflow_step.pluginMethodId')
|
||||
.select(['plugin_method.pluginId', 'plugin_method.name as methodName', 'workflow_step.order']),
|
||||
).as('step'),
|
||||
])
|
||||
.$if(dto.result !== undefined, (qb) => qb.where('workflow_log.result', '=', dto.result!))
|
||||
.$if(dto.before !== undefined, (qb) => qb.where('workflow_log.createdAt', '<', dto.before!))
|
||||
.orderBy('workflow_log.createdAt', 'desc')
|
||||
.limit(dto.limit)
|
||||
.execute();
|
||||
}
|
||||
|
||||
log(dto: Insertable<WorkflowLogTable>) {
|
||||
return this.db.insertInto('workflow_log').values(dto).execute();
|
||||
}
|
||||
|
||||
async updateStep(id: string, dto: Updateable<WorkflowStepTable>) {
|
||||
await this.db.updateTable('workflow_step').where('workflow_step.id', '=', id).set(dto).execute();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ import {
|
|||
VideoStreamSessionTable,
|
||||
VideoStreamVariantTable,
|
||||
} from 'src/schema/tables/video-stream.table';
|
||||
import { WorkflowLogTable } from 'src/schema/tables/workflow-log.table';
|
||||
import { WorkflowStepTable } from 'src/schema/tables/workflow-step.table';
|
||||
import { WorkflowTable } from 'src/schema/tables/workflow.table';
|
||||
|
||||
|
|
@ -279,4 +280,5 @@ export interface DB {
|
|||
|
||||
workflow: WorkflowTable;
|
||||
workflow_step: WorkflowStepTable;
|
||||
workflow_log: WorkflowLogTable;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
import { Kysely, sql } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await sql`ALTER TABLE "workflow" ADD "logging" boolean NOT NULL DEFAULT false;`.execute(db);
|
||||
await sql`CREATE TABLE "workflow_log" (
|
||||
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
|
||||
"createdAt" timestamp with time zone NOT NULL DEFAULT now(),
|
||||
"workflowId" uuid NOT NULL,
|
||||
"result" character varying NOT NULL,
|
||||
"workflowStepId" uuid,
|
||||
"triggerDataId" uuid,
|
||||
"runId" uuid NOT NULL,
|
||||
CONSTRAINT "workflow_log_workflowId_fkey" FOREIGN KEY ("workflowId") REFERENCES "workflow" ("id") ON UPDATE CASCADE ON DELETE CASCADE,
|
||||
CONSTRAINT "workflow_log_workflowStepId_fkey" FOREIGN KEY ("workflowStepId") REFERENCES "workflow_step" ("id") ON UPDATE CASCADE ON DELETE SET NULL,
|
||||
CONSTRAINT "workflow_log_pkey" PRIMARY KEY ("id")
|
||||
);`.execute(db);
|
||||
await sql`CREATE INDEX "workflow_log_workflowId_idx" ON "workflow_log" ("workflowId");`.execute(db);
|
||||
await sql`CREATE INDEX "workflow_log_workflowStepId_idx" ON "workflow_log" ("workflowStepId");`.execute(db);
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await sql`ALTER TABLE "workflow" DROP COLUMN "logging";`.execute(db);
|
||||
await sql`DROP TABLE "workflow_log";`.execute(db);
|
||||
}
|
||||
36
server/src/schema/tables/workflow-log.table.ts
Normal file
36
server/src/schema/tables/workflow-log.table.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
ForeignKeyColumn,
|
||||
Generated,
|
||||
PrimaryGeneratedColumn,
|
||||
Table,
|
||||
Timestamp,
|
||||
} from '@immich/sql-tools';
|
||||
import { WorkflowResult } from 'src/enum';
|
||||
import { WorkflowStepTable } from 'src/schema/tables/workflow-step.table';
|
||||
import { WorkflowTable } from 'src/schema/tables/workflow.table';
|
||||
|
||||
@Table('workflow_log')
|
||||
export class WorkflowLogTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Generated<Timestamp>;
|
||||
|
||||
@ForeignKeyColumn(() => WorkflowTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', index: true })
|
||||
workflowId!: string;
|
||||
|
||||
@Column()
|
||||
result!: WorkflowResult;
|
||||
|
||||
@ForeignKeyColumn(() => WorkflowStepTable, { onDelete: 'SET NULL', onUpdate: 'CASCADE', nullable: true })
|
||||
workflowStepId!: string | null;
|
||||
|
||||
@Column({ type: 'uuid', nullable: true })
|
||||
triggerDataId!: string | null;
|
||||
|
||||
@Column({ type: 'uuid' })
|
||||
runId!: string;
|
||||
}
|
||||
|
|
@ -41,4 +41,7 @@ export class WorkflowTable {
|
|||
|
||||
@Column({ type: 'boolean', default: true })
|
||||
enabled!: Generated<boolean>;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
logging!: Generated<boolean>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import {
|
|||
JobName,
|
||||
JobStatus,
|
||||
QueueName,
|
||||
WorkflowResult,
|
||||
WorkflowType,
|
||||
} from 'src/enum';
|
||||
import { ArgOf } from 'src/repositories/event.repository';
|
||||
|
|
@ -38,7 +39,7 @@ const dummy = () => {
|
|||
};
|
||||
|
||||
type ExecuteOptions<T extends WorkflowType> = {
|
||||
read: (type: T) => Promise<{ authUserId: string; data: WorkflowEventData<T> }>;
|
||||
read: (type: T) => Promise<{ authUserId: string; data: WorkflowEventData<T>; entityId?: string }>;
|
||||
write: (auth: AuthDto, changes: WorkflowChanges<T>) => Promise<void>;
|
||||
};
|
||||
|
||||
|
|
@ -345,6 +346,7 @@ export class WorkflowExecutionService extends BaseService {
|
|||
return {
|
||||
data: { asset } as any,
|
||||
authUserId: asset.ownerId,
|
||||
entityId: asset.id,
|
||||
};
|
||||
},
|
||||
write: async (auth, changes) => {
|
||||
|
|
@ -412,11 +414,13 @@ export class WorkflowExecutionService extends BaseService {
|
|||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { read, write } = handler;
|
||||
const readResult = await read(type);
|
||||
let data = readResult.data;
|
||||
for (const step of workflow.steps) {
|
||||
const { read, write } = handler;
|
||||
const readResult = await read(type);
|
||||
let data = readResult.data;
|
||||
const runId = crypto.randomUUID();
|
||||
|
||||
for (const step of workflow.steps) {
|
||||
try {
|
||||
const payload: WorkflowEventPayload<typeof type> = {
|
||||
trigger: workflow.trigger,
|
||||
type,
|
||||
|
|
@ -467,14 +471,45 @@ export class WorkflowExecutionService extends BaseService {
|
|||
|
||||
const shouldContinue = result?.workflow?.continue ?? true;
|
||||
if (!shouldContinue) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (workflow.logging) {
|
||||
await this.workflowRepository.log({
|
||||
workflowId,
|
||||
result: WorkflowResult.Halted,
|
||||
workflowStepId: step.id,
|
||||
triggerDataId: readResult.entityId,
|
||||
runId,
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.debug(`Workflow ${workflowId} executed successfully`);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error executing workflow ${workflowId}:`, error);
|
||||
return JobStatus.Failed;
|
||||
this.logger.debug(`Workflow ${workflowId} run ${runId} stopped on step ${step.id}`);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
this.logger.error(`Error executing workflow ${workflowId} run ${runId}:`, error);
|
||||
|
||||
if (workflow.logging) {
|
||||
await this.workflowRepository.log({
|
||||
workflowId,
|
||||
result: WorkflowResult.Error,
|
||||
workflowStepId: step.id,
|
||||
triggerDataId: readResult.entityId,
|
||||
runId,
|
||||
});
|
||||
}
|
||||
|
||||
return JobStatus.Failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (workflow.logging) {
|
||||
await this.workflowRepository.log({
|
||||
workflowId,
|
||||
result: WorkflowResult.Completed,
|
||||
triggerDataId: readResult.entityId,
|
||||
runId,
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.debug(`Workflow ${workflowId} run ${runId} executed successfully`);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import {
|
|||
mapWorkflow,
|
||||
mapWorkflowShare,
|
||||
WorkflowCreateDto,
|
||||
WorkflowGetLogsDto,
|
||||
WorkflowLogEntryDto,
|
||||
WorkflowResponseDto,
|
||||
WorkflowSearchDto,
|
||||
WorkflowShareResponseDto,
|
||||
|
|
@ -83,6 +85,23 @@ export class WorkflowService extends BaseService {
|
|||
await this.workflowRepository.delete(id);
|
||||
}
|
||||
|
||||
async getLogs(auth: AuthDto, id: string, dto: WorkflowGetLogsDto): Promise<WorkflowLogEntryDto[]> {
|
||||
await this.requireAccess({ auth, permission: Permission.WorkflowLogs, ids: [id] });
|
||||
const logs = await this.workflowRepository.getLogs(id, dto);
|
||||
return logs.map((entry) => ({
|
||||
id: entry.id,
|
||||
at: entry.createdAt,
|
||||
result: entry.result,
|
||||
triggerDataId: entry.triggerDataId ?? undefined,
|
||||
lastStep: entry.step
|
||||
? {
|
||||
index: entry.step.order,
|
||||
method: `${entry.step.pluginId}#${entry.step.methodName}`,
|
||||
}
|
||||
: undefined,
|
||||
}));
|
||||
}
|
||||
|
||||
private async resolveAndValidateSteps<T extends { method: string }>(steps: T[], trigger: WorkflowTrigger) {
|
||||
const methods = await this.pluginRepository.getForValidation();
|
||||
const results: Array<T & { pluginMethod: PluginMethodSearchResponse }> = [];
|
||||
|
|
|
|||
|
|
@ -324,7 +324,8 @@ const checkOtherAccess = async (access: AccessRepository, request: OtherAccessRe
|
|||
|
||||
case Permission.WorkflowRead:
|
||||
case Permission.WorkflowUpdate:
|
||||
case Permission.WorkflowDelete: {
|
||||
case Permission.WorkflowDelete:
|
||||
case Permission.WorkflowLogs: {
|
||||
return access.workflow.checkOwnerAccess(auth.user.id, ids);
|
||||
}
|
||||
|
||||
|
|
|
|||
171
web/src/lib/modals/WorkflowLogsModal.svelte
Normal file
171
web/src/lib/modals/WorkflowLogsModal.svelte
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<script lang="ts">
|
||||
import { type WorkflowLogEntryDto, type WorkflowResponseDto, WorkflowResult, getWorkflowLogs } from '@immich/sdk';
|
||||
import {
|
||||
Modal,
|
||||
ModalBody,
|
||||
Table,
|
||||
TableHeader,
|
||||
TableHeading,
|
||||
TableBody,
|
||||
TableRow,
|
||||
TableCell,
|
||||
HStack,
|
||||
Icon,
|
||||
VStack,
|
||||
Button,
|
||||
Select,
|
||||
type SelectOption,
|
||||
} from '@immich/ui';
|
||||
import { mdiHistory, mdiOpenInNew } from '@mdi/js';
|
||||
import { t } from 'svelte-i18n';
|
||||
import { locale } from '$lib/stores/preferences.store';
|
||||
import { DateTime } from 'luxon';
|
||||
import { Route } from '$lib/route';
|
||||
import { handleUpdateWorkflow } from '$lib/services/workflow.service';
|
||||
|
||||
type Props = {
|
||||
workflow: WorkflowResponseDto;
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
let { workflow, onClose }: Props = $props();
|
||||
|
||||
let entries: WorkflowLogEntryDto[] = $state([]);
|
||||
let placeholder = $state<HTMLElement>();
|
||||
let filter = $state<WorkflowResult>();
|
||||
let before = $state<string>();
|
||||
let hasNext = $state(true);
|
||||
let loading = $state(false);
|
||||
|
||||
const setLogging = async (logging: boolean) => {
|
||||
const success = await handleUpdateWorkflow(workflow.id, { logging });
|
||||
if (!success) {
|
||||
return;
|
||||
}
|
||||
workflow = { ...workflow, logging };
|
||||
reset();
|
||||
};
|
||||
|
||||
const reset = () => {
|
||||
entries = [];
|
||||
hasNext = true;
|
||||
before = undefined;
|
||||
};
|
||||
|
||||
const setFilter = (option: SelectOption<WorkflowResult>) => {
|
||||
reset();
|
||||
filter = option.value;
|
||||
void getLogs();
|
||||
};
|
||||
|
||||
const getLogs = async () => {
|
||||
if (!hasNext || loading) {
|
||||
return;
|
||||
}
|
||||
|
||||
loading = true;
|
||||
const limit = 50;
|
||||
const results = await getWorkflowLogs({ id: workflow.id, result: filter, before, limit });
|
||||
entries.push(...results);
|
||||
if (results.length < limit) {
|
||||
hasNext = false;
|
||||
} else {
|
||||
before = results.at(-1)?.at;
|
||||
}
|
||||
loading = false;
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
const entry = entries.find((entry) => entry.target === placeholder);
|
||||
if (entry?.isIntersecting) {
|
||||
void getLogs();
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!placeholder) {
|
||||
return;
|
||||
}
|
||||
observer.disconnect();
|
||||
observer.observe(placeholder);
|
||||
});
|
||||
</script>
|
||||
|
||||
<Modal title={$t('logs')} icon={mdiHistory} {onClose} size="medium">
|
||||
<ModalBody>
|
||||
{#if workflow.logging}
|
||||
<Table striped>
|
||||
<TableHeader>
|
||||
<TableHeading>{$t('date')}</TableHeading>
|
||||
<TableHeading>{$t('result')}</TableHeading>
|
||||
</TableHeader>
|
||||
<TableBody class="max-h-100">
|
||||
{#each entries as entry (entry.id)}
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<HStack class="justify-center">
|
||||
<p>
|
||||
{DateTime.fromISO(entry.at).toLocaleString(DateTime.DATETIME_MED, {
|
||||
locale: $locale,
|
||||
})}
|
||||
</p>
|
||||
{#if entry.triggerDataId}
|
||||
<a href={Route.viewAsset({ id: entry.triggerDataId })} target="_blank">
|
||||
<Icon icon={mdiOpenInNew} size="20" class="text-primary" />
|
||||
</a>
|
||||
{/if}
|
||||
</HStack>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<HStack class="justify-center">
|
||||
{#if entry.result === WorkflowResult.Completed}
|
||||
<p class="rounded-full bg-green-700 px-3 py-1 text-xs text-white">
|
||||
{$t('workflow_logging_completed')}
|
||||
</p>
|
||||
{:else if entry.result === WorkflowResult.Halted}
|
||||
<p class="rounded-full bg-gray-600 px-3 py-1 text-xs text-white">
|
||||
{#if entry.lastStep}
|
||||
{$t('workflow_logging_halted_step', { values: { step: entry.lastStep.index + 1 } })}
|
||||
{:else}
|
||||
{$t('workflow_logging_halted')}
|
||||
{/if}
|
||||
</p>
|
||||
{:else}
|
||||
<p class="rounded-full bg-red-500 px-3 py-1 text-xs text-white">
|
||||
{#if entry.lastStep}
|
||||
{$t('workflow_logging_error_step', { values: { step: entry.lastStep.index + 1 } })}
|
||||
{:else}
|
||||
{$t('error')}
|
||||
{/if}
|
||||
</p>
|
||||
{/if}
|
||||
</HStack>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
{#if hasNext}
|
||||
<TableRow><TableCell><div bind:this={placeholder}>...</div></TableCell></TableRow>
|
||||
{/if}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div class="mt-5 flex gap-5">
|
||||
<Select
|
||||
onSelect={setFilter}
|
||||
class="flex-1"
|
||||
placeholder={$t('filter')}
|
||||
options={[
|
||||
{ value: WorkflowResult.Completed, label: $t('workflow_logging_completed') },
|
||||
{ value: WorkflowResult.Halted, label: $t('workflow_logging_halted') },
|
||||
{ value: WorkflowResult.Error, label: $t('error') },
|
||||
]}
|
||||
/>
|
||||
<Button class="flex-1" onclick={() => setLogging(false)}>{$t('workflow_logging_disable')}</Button>
|
||||
</div>
|
||||
{:else}
|
||||
<VStack class="gap-5 py-5">
|
||||
<p class="text-md text-center">{$t('workflow_logging_disabled_description')}</p>
|
||||
<Button onclick={() => setLogging(true)}>{$t('workflow_logging_enable')}</Button>
|
||||
</VStack>
|
||||
{/if}
|
||||
</ModalBody>
|
||||
</Modal>
|
||||
|
|
@ -15,6 +15,7 @@ import {
|
|||
mdiDeleteOutline,
|
||||
mdiDownload,
|
||||
mdiFileDocumentMultipleOutline,
|
||||
mdiHistory,
|
||||
mdiPause,
|
||||
mdiPencil,
|
||||
mdiPlay,
|
||||
|
|
@ -24,6 +25,7 @@ import type { MessageFormatter } from 'svelte-i18n';
|
|||
import { goto } from '$app/navigation';
|
||||
import { eventManager } from '$lib/managers/event-manager.svelte';
|
||||
import WorkflowDuplicateModal from '$lib/modals/WorkflowDuplicateModal.svelte';
|
||||
import WorkflowLogsModal from '$lib/modals/WorkflowLogsModal.svelte';
|
||||
import WorkflowTemplatePickerModal from '$lib/modals/WorkflowTemplatePickerModal.svelte';
|
||||
import { Route } from '$lib/route';
|
||||
import { copyToClipboard, downloadJson } from '$lib/utils';
|
||||
|
|
@ -112,7 +114,13 @@ export const getWorkflowActions = ($t: MessageFormatter, workflow: WorkflowRespo
|
|||
onAction: () => handleDeleteWorkflow(workflow),
|
||||
};
|
||||
|
||||
return { CopyJson, Download, Duplicate, ToggleEnabled, Edit, Delete };
|
||||
const Logs: ActionItem = {
|
||||
title: $t('check_logs'),
|
||||
icon: mdiHistory,
|
||||
onAction: () => modalManager.show(WorkflowLogsModal, { workflow }),
|
||||
};
|
||||
|
||||
return { CopyJson, Download, Duplicate, ToggleEnabled, Edit, Delete, Logs };
|
||||
};
|
||||
|
||||
export const getWorkflowShowSchemaAction = (
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@
|
|||
{:else}
|
||||
<div class="my-6 flex flex-col gap-3">
|
||||
{#each workflows as workflow (workflow.id)}
|
||||
{@const { ToggleEnabled, Duplicate, Edit, Delete } = getWorkflowActions($t, workflow)}
|
||||
{@const { ToggleEnabled, Duplicate, Logs, Edit, Delete } = getWorkflowActions($t, workflow)}
|
||||
|
||||
<Card class="group shadow-none transition-colors hover:border-primary">
|
||||
<CardHeader>
|
||||
|
|
@ -120,6 +120,7 @@
|
|||
ToggleEnabled,
|
||||
Edit,
|
||||
Duplicate,
|
||||
Logs,
|
||||
getWorkflowShowSchemaAction($t, expandedIds.has(workflow.id), () => onToggleExpand(workflow.id)),
|
||||
MenuItemType.Divider,
|
||||
Delete,
|
||||
|
|
|
|||
|
|
@ -265,7 +265,7 @@
|
|||
|
||||
$effect(() => console.log(steps));
|
||||
|
||||
const { Download, Duplicate, CopyJson, Delete } = $derived(
|
||||
const { Download, Duplicate, CopyJson, Delete, Logs } = $derived(
|
||||
getWorkflowActions($t, { ...savedWorkflow, name, description, enabled, trigger, steps }),
|
||||
);
|
||||
</script>
|
||||
|
|
@ -280,7 +280,7 @@
|
|||
{onClose}
|
||||
translations={{ close: $t('back') }}
|
||||
closeIcon={mdiArrowLeft}
|
||||
actions={[Duplicate, CopyJson, Download, Delete].map((item) => ({ ...item, color: undefined }))}
|
||||
actions={[Logs, Duplicate, CopyJson, Download, Delete].map((item) => ({ ...item, color: undefined }))}
|
||||
>
|
||||
<ControlBarHeader>
|
||||
<ControlBarTitle>{data.workflow.name}</ControlBarTitle>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue