Spaces:
Running
Running
File size: 1,124 Bytes
b39afbe |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
/**
* Copyright (c) 2023 MERCENARIES.AI PTE. LTD.
* All rights reserved.
*/
const script = {
name: 'runBlock',
exec: async function (ctx, payload) {
const blockManager = ctx.app.blocks
const block = payload.block
const args = payload.args
const opts = {}
if (payload.cache) {
opts.cacheType = payload.cache
}
if (payload.bustCache) {
opts.bustCache = payload.bustCache
}
if (payload.timeout) {
opts.timeout = payload.timeout
}
// TypeScript can't check types in plain JavaScript
// runScript gives a `ctx` of type IRunScriptContext
// runBlock takes a `ctx` of type WorkerContext
const workerContext = { ...ctx } // Shallow copy
const jobData = {
session: null, // ctx.session,
sessionId: ctx.sessionId,
user: null, // ctx.user,
userId: ctx.userId,
jobId: ctx.jobId,
workflowId: ctx.workflowId,
args
}
workerContext.getData = () => { return jobData }
const result = await blockManager.runBlock(workerContext, block, args, {}, opts)
return result
}
}
export default script
|