1
This commit is contained in:
39
server/services/task_executor.js
Normal file
39
server/services/task_executor.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { crawl_run_record } from '../models/index.js';
|
||||
import { safe_json_stringify } from './json_utils.js';
|
||||
import { invoke_extension_action } from './puppeteer_runner.js';
|
||||
|
||||
export async function execute_action_and_record(params) {
|
||||
const {
|
||||
action_name,
|
||||
action_payload,
|
||||
source,
|
||||
schedule_task_id
|
||||
} = params;
|
||||
|
||||
const request_payload = safe_json_stringify(action_payload || {});
|
||||
|
||||
let ok = false;
|
||||
let result_payload = null;
|
||||
let error_message = null;
|
||||
|
||||
try {
|
||||
const result = await invoke_extension_action(action_name, action_payload || {});
|
||||
ok = true;
|
||||
result_payload = safe_json_stringify(result);
|
||||
return result;
|
||||
} catch (err) {
|
||||
ok = false;
|
||||
error_message = (err && err.message) || String(err);
|
||||
throw err;
|
||||
} finally {
|
||||
await crawl_run_record.create({
|
||||
action_name,
|
||||
request_payload,
|
||||
ok,
|
||||
result_payload,
|
||||
error_message,
|
||||
source,
|
||||
schedule_task_id: schedule_task_id || null
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user