mirror of
https://github.com/nocobase/nocobase.git
synced 2026-08-29 02:03:53 +08:00
Merge branch 'next' into develop
This commit is contained in:
+6
@@ -29,6 +29,12 @@ export default class extends Instruction {
|
||||
type: 'void',
|
||||
'x-component': 'LocalProvider',
|
||||
},
|
||||
ignoreFail: {
|
||||
type: 'boolean',
|
||||
'x-content': `{{t("Ignore failure and continue workflow", { ns: "${NAMESPACE}" })}}`,
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Checkbox',
|
||||
},
|
||||
};
|
||||
components = {
|
||||
LocalProvider,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"Notification": "通知",
|
||||
"Send notification. You can use the variables in the upstream nodes as content and ohter config.": "发送通知。您可以使用上游节点中的变量作为通知的内容和其他配置。"
|
||||
"Send notification. You can use the variables in the upstream nodes as content and ohter config.": "发送通知。您可以使用上游节点中的变量作为通知的内容和其他配置。",
|
||||
"Ignore failure and continue workflow": "忽略失败并继续工作流"
|
||||
}
|
||||
|
||||
+36
-39
@@ -9,15 +9,16 @@
|
||||
|
||||
import NotificationsServerPlugin from '@nocobase/plugin-notification-manager';
|
||||
|
||||
import { Processor, Instruction, JOB_STATUS, FlowNodeModel } from '@nocobase/plugin-workflow';
|
||||
import { Processor, Instruction, JOB_STATUS, FlowNodeModel, IJob } from '@nocobase/plugin-workflow';
|
||||
|
||||
export default class extends Instruction {
|
||||
async run(node: FlowNodeModel, prevJob, processor: Processor) {
|
||||
const options = processor.getParsedValue(node.config, node.id);
|
||||
const { ignoreFail, ...config } = node.config;
|
||||
const options = processor.getParsedValue(config, node.id);
|
||||
const scope = processor.getScope(node.id);
|
||||
const sendParams = {
|
||||
channelName: options.channelName,
|
||||
message: { ...options, content: node.config.content },
|
||||
message: { ...options, content: config.content },
|
||||
triggerFrom: 'workflow',
|
||||
data: scope,
|
||||
};
|
||||
@@ -35,60 +36,56 @@ export default class extends Instruction {
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: JOB_STATUS.FAILED,
|
||||
status: ignoreFail ? JOB_STATUS.RESOLVED : JOB_STATUS.FAILED,
|
||||
result,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
status: JOB_STATUS.FAILED,
|
||||
status: ignoreFail ? JOB_STATUS.RESOLVED : JOB_STATUS.ERROR,
|
||||
result: error,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const job = processor.saveJob({
|
||||
const { id } = processor.saveJob({
|
||||
status: JOB_STATUS.PENDING,
|
||||
nodeId: node.id,
|
||||
nodeKey: node.key,
|
||||
upstreamId: prevJob?.id ?? null,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line promise/catch-or-return
|
||||
notificationServer
|
||||
.send(sendParams)
|
||||
.then((result) => {
|
||||
if (result.status === 'success') {
|
||||
processor.logger.info(`notification (#${node.id}) sent successfully.`);
|
||||
job.set({
|
||||
status: JOB_STATUS.RESOLVED,
|
||||
result,
|
||||
});
|
||||
} else {
|
||||
processor.logger.info(`notification (#${node.id}) sent failed.`);
|
||||
job.set({
|
||||
status: JOB_STATUS.FAILED,
|
||||
result: result,
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
processor.logger.warn(`notification (#${node.id}) sent failed: ${error.message}`);
|
||||
await processor.exit();
|
||||
|
||||
job.set({
|
||||
status: JOB_STATUS.FAILED,
|
||||
result: error,
|
||||
});
|
||||
})
|
||||
.finally(() => {
|
||||
processor.logger.debug(`notification (#${node.id}) sending ended, resume workflow...`);
|
||||
setImmediate(() => {
|
||||
this.workflow.resume(job);
|
||||
});
|
||||
const jobDone: IJob = { status: JOB_STATUS.PENDING };
|
||||
|
||||
try {
|
||||
processor.logger.info(`notification (#${node.id}) sent, waiting for response...`);
|
||||
const result = await notificationServer.send(sendParams);
|
||||
if (result.status === 'success') {
|
||||
processor.logger.info(`notification (#${node.id}) sent successfully.`);
|
||||
jobDone.status = JOB_STATUS.RESOLVED;
|
||||
jobDone.result = result;
|
||||
} else {
|
||||
processor.logger.info(`notification (#${node.id}) sent failed.`);
|
||||
jobDone.status = ignoreFail ? JOB_STATUS.RESOLVED : JOB_STATUS.FAILED;
|
||||
jobDone.result = result;
|
||||
}
|
||||
} catch (error) {
|
||||
processor.logger.warn(`notification (#${node.id}) sent failed: ${error.message}`);
|
||||
|
||||
jobDone.status = ignoreFail ? JOB_STATUS.RESOLVED : JOB_STATUS.FAILED;
|
||||
jobDone.result = error;
|
||||
} finally {
|
||||
const job = await this.workflow.app.db.getRepository('jobs').findOne({
|
||||
filterByTk: id,
|
||||
});
|
||||
processor.logger.info(`notification (#${node.id}) sent, waiting for response...`);
|
||||
|
||||
return processor.exit();
|
||||
job.set(jobDone);
|
||||
processor.logger.debug(`notification (#${node.id}) sending ended, resume workflow...`);
|
||||
setImmediate(() => {
|
||||
this.workflow.resume(job);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async resume(node: FlowNodeModel, job, processor: Processor) {
|
||||
|
||||
Reference in New Issue
Block a user