New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I cannot queue Task #1908
Comments
Can you share any errors you may be seeing? |
No error appears when we use Any idea where the error may be? Below you can see our config for
|
Your config looks fine (other than some extra stuff that I'll bet is for your application ( Can you share a way to reproduce the problem where enqueuing a task directly doesn't work? Here are some debugging ideas:
|
Thank you very much for your support and prompt response. We have finally found the cause of the error. It is when we try to add the middleware to the tasks through an initializer.
import _ = require("lodash");
import { log, Initializer, task, api } from "actionhero";
export class taskMiddleware extends Initializer {
constructor() {
super();
this.name = "customMiddleware";
}
async initialize() {
const middlewareTask = {
name: 'duration',
global: true,
priority: 90,
preProcessor: async function () {
const worker = this.worker
worker.startTime = process.hrtime()
},
postProcessor: async function () {
const worker = this.worker
const elapsed = process.hrtime(worker.startTime)
const seconds = elapsed[0]
const millis = elapsed[1] / 1000000
log(worker.job.class + ' done in ' + seconds + ' s and ' + millis + ' ms.', 'info')
},
preEnqueue: async function () {
const arg = this.args[0]
return (arg === 'ok') // returning `false` will prevent the task from enqueueing
},
postEnqueue: async function () {
log("Task successfully enqueued!")
}
}
task.addMiddleware(middlewareTask);
log("I initialized", "debug", this.name);
}
} We have removed the initialization and everything works correctly. Although, I do not understand what we are doing wrong when adding the middleware since the example is the same as the official model https://github.com/actionhero/actionhero/blob/main/src/modules/task.ts |
Thank you for this detail! The example was confusing, and is fixed in #1921 - the arguments were the inputs to the task... it's clearer now just to return More interesting, is the difference in behavior you were seeing with |
I can not enqued the tasks if we use:
If I use
enqueueIN
orenqueueAT
work correctly:26.1.1
14.16.0
(OSX)
Please I need your help. Thanks
The text was updated successfully, but these errors were encountered: