diff --git a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/Plugin.ts b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/Plugin.ts index 900b1d188..96bf044b8 100644 --- a/packages/plugins/@nocobase/plugin-workflow-manual/src/server/Plugin.ts +++ b/packages/plugins/@nocobase/plugin-workflow-manual/src/server/Plugin.ts @@ -37,7 +37,7 @@ export default class extends Plugin { this.app.acl.allow('users_jobs', ['list', 'get', 'submit'], 'loggedIn'); - const workflowPlugin = this.app.getPlugin(WorkflowPlugin); + const workflowPlugin = this.app.pm.get(WorkflowPlugin) as WorkflowPlugin; workflowPlugin.registerInstruction('manual', ManualInstruction); } } diff --git a/packages/plugins/@nocobase/plugin-workflow-sql/src/client/SQLInstruction.tsx b/packages/plugins/@nocobase/plugin-workflow-sql/src/client/SQLInstruction.tsx index f6af07682..ab3288794 100644 --- a/packages/plugins/@nocobase/plugin-workflow-sql/src/client/SQLInstruction.tsx +++ b/packages/plugins/@nocobase/plugin-workflow-sql/src/client/SQLInstruction.tsx @@ -3,6 +3,8 @@ import { css } from '@nocobase/client'; import { Instruction, WorkflowVariableRawTextArea, defaultFieldNames } from '@nocobase/plugin-workflow/client'; import { NAMESPACE } from '../locale'; +import { Trans } from 'react-i18next'; +import React from 'react'; export default class extends Instruction { title = `{{t("SQL action", { ns: "${NAMESPACE}" })}}`; @@ -14,7 +16,7 @@ export default class extends Instruction { type: 'string', required: true, title: 'SQL', - description: `{{t("Usage of SQL query result is not supported yet.", { ns: "${NAMESPACE}" })}}`, + description: '{{sqlDescription()}}', 'x-decorator': 'FormItem', 'x-component': 'WorkflowVariableRawTextArea', 'x-component-props': { @@ -26,6 +28,19 @@ export default class extends Instruction { }, }, }; + scope = { + sqlDescription() { + return ( + + {'SQL query result could be used through '} + + {'JSON query node'} + + {' (Commercial plugin).'} + + ); + }, + }; components = { WorkflowVariableRawTextArea, }; diff --git a/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/index.ts b/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/index.ts index f85747f64..5cbbb5bab 100644 --- a/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/index.ts +++ b/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/index.ts @@ -1,6 +1,6 @@ import { useTranslation } from 'react-i18next'; -export const NAMESPACE = 'workflow-sql'; +export const NAMESPACE = '@nocobase/plugin-workflow-sql'; export function useLang(key: string, options = {}) { const { t } = usePluginTranslation(options); diff --git a/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/zh-CN.json index 603d19d84..4d841b8e4 100644 --- a/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-workflow-sql/src/locale/zh-CN.json @@ -1,5 +1,5 @@ { "SQL action": "SQL 操作", - "Execute a SQL statement in database": "在数据库中执行一个 SQL 语句", - "Usage of SQL query result is not supported yet.": "SQL 执行的结果暂不支持使用。" + "Execute a SQL statement in database.": "在数据库中执行一个 SQL 语句", + "SQL query result could be used through <1>JSON query node (Commercial plugin).": "SQL 执行的结果可在 <1>JSON 解析节点 中使用(商业插件)。" } diff --git a/packages/plugins/@nocobase/plugin-workflow-sql/src/server/SQLInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-sql/src/server/SQLInstruction.ts index 8d7b08554..f75a1beaa 100644 --- a/packages/plugins/@nocobase/plugin-workflow-sql/src/server/SQLInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-sql/src/server/SQLInstruction.ts @@ -11,7 +11,7 @@ export default class extends Instruction { } const result = await sequelize.query(sql, { - // transaction: processor.transaction, + transaction: processor.transaction, // plain: true, // model: db.getCollection(node.config.collection).model }); diff --git a/packages/plugins/@nocobase/plugin-workflow-sql/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-sql/src/server/__tests__/instruction.test.ts index 448158a1a..4c626a66a 100644 --- a/packages/plugins/@nocobase/plugin-workflow-sql/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-sql/src/server/__tests__/instruction.test.ts @@ -1,4 +1,4 @@ -import Database from '@nocobase/database'; +import Database, { fn } from '@nocobase/database'; import { Application } from '@nocobase/server'; import { EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow'; import { getApp, sleep } from '@nocobase/plugin-workflow-test'; @@ -166,4 +166,33 @@ describe('workflow > instructions > sql', () => { expect(queryJob.result).toBeNull(); }); }); + + describe('run in sync mode', () => { + it('sync workflow', async () => { + const w2 = await WorkflowModel.create({ + enabled: true, + sync: true, + type: 'collection', + config: { + mode: 1, + collection: 'categories', + }, + }); + + const n1 = await w2.createNode({ + type: 'sql', + config: { + sql: `select count(id) from ${PostCollection.quotedTableName()}`, + }, + }); + + const CategoryRepo = db.getCollection('categories').repository; + const category = await CategoryRepo.create({ values: { title: 't1' } }); + + const [execution] = await w2.getExecutions(); + expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED); + const [job] = await execution.getJobs(); + expect(job.status).toBe(JOB_STATUS.RESOLVED); + }); + }); }); diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/end.tsx b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/end.tsx index e5f5e2340..160fcaeeb 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/end.tsx +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/nodes/end.tsx @@ -3,7 +3,7 @@ import { NAMESPACE } from '../locale'; import { JOB_STATUS } from '../constants'; export default class extends Instruction { - title = '{{t("End process")}}'; + title = `{{t("End process", { ns: "${NAMESPACE}" })}}`; type = 'end'; group = 'control'; description = `{{t("End the process immediately, with set status.", { ns: "${NAMESPACE}" })}}`; diff --git a/packages/plugins/@nocobase/plugin-workflow/src/client/schemas/workflows.ts b/packages/plugins/@nocobase/plugin-workflow/src/client/schemas/workflows.ts index b577b9b3b..896d14462 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/client/schemas/workflows.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/client/schemas/workflows.ts @@ -92,7 +92,7 @@ const workflowFieldset = { sync: { type: 'boolean', title: `{{ t("Execute mode", { ns: "${NAMESPACE}" }) }}`, - description: `{{ t("Could not be changed after created.", { ns: "${NAMESPACE}" }) }}`, + description: `{{ t("Execute workflow asynchronously or synchronously based on trigger type, and could not be changed after created.", { ns: "${NAMESPACE}" }) }}`, 'x-decorator': 'FormItem', 'x-component': 'SyncOptionSelect', 'x-component-props': { @@ -105,7 +105,7 @@ const workflowFieldset = { { label: `{{ t("Synchronously", { ns: "${NAMESPACE}" }) }}`, value: true, - tooltip: `{{ t("For user actions that require immediate feedback. Can not use asynchronous nodes in such mode.", { ns: "${NAMESPACE}" }) }}`, + tooltip: `{{ t("For user actions that require immediate feedback. Can not use asynchronous nodes in such mode, and it is not recommended to perform time-consuming operations under synchronous mode.", { ns: "${NAMESPACE}" }) }}`, }, ], }, diff --git a/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json b/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json index 9ca2f7b48..8cf75823f 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json +++ b/packages/plugins/@nocobase/plugin-workflow/src/locale/zh-CN.json @@ -27,6 +27,14 @@ "Trigger time": "触发时间", "Triggered at": "触发时间", + "Execute mode": "执行模式", + "Execute workflow asynchronously or synchronously based on trigger type, and could not be changed after created.": "基于触发类型异步或同步执行工作流,创建后不可更改。", + "Asynchronously": "异步", + "Synchronously": "同步", + "Will be executed in the background as a queued task.": "将作为队列任务在后台执行。", + "For user actions that require immediate feedback. Can not use asynchronous nodes in such mode, and it is not recommended to perform time-consuming operations under synchronous mode.": + "适用于需要即时反馈的用户操作。不能在此模式下使用异步节点,并且不建议在同步模式下执行耗时的操作。", + "Bind workflows": "绑定工作流", "Workflow will be triggered after submitting succeeded.": "提交成功后触发工作流。", "Workflow will be triggered after saving succeeded.": "保存成功后触发工作流。", diff --git a/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts b/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts index b24a2f6d0..2287eb21d 100644 --- a/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts +++ b/packages/plugins/@nocobase/plugin-workflow/src/server/migrations/20240115220721-add-node-key-to-job.ts @@ -6,7 +6,6 @@ export default class extends Migration { async up() { const { db } = this.context; - const PluginModel = db.getModel('applicationPlugins'); const JobRepo = db.getRepository('jobs'); await db.sequelize.transaction(async (transaction) => { const jobs = await JobRepo.find({