UNPKG

actionhero

Version:

actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks

36 lines (35 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaskEnqueue = void 0; const index_1 = require("./../../../index"); class TaskEnqueue extends index_1.CLI { constructor() { super(); this.name = "task enqueue"; this.description = "enqueue a defined task into your actionhero cluster"; this.example = "actionhero task enqueue --name=[taskName] --args=[JSON-formatted args]"; this.inputs = { name: { required: true }, args: { required: false }, params: { required: false }, }; } async run({ params }) { if (!index_1.api.tasks.tasks[params.name]) { throw new Error('Task "' + params.name + '" not found'); } let args = {}; if (params.args) { args = JSON.parse(params.args); } if (params.params) { args = JSON.parse(params.params); } await index_1.api.resque.startQueue(); const toRun = await index_1.task.enqueue(params.name, args); index_1.log("response", "info", toRun); return true; } } exports.TaskEnqueue = TaskEnqueue;