pulsecron / pulse

The modern MongoDB-powered job scheduler library for Node.js
https://pulsecron.com
MIT License
90 stars 4 forks source link

`Processor` type does not allowing creation of async processors #14

Closed kostysh closed 3 months ago

kostysh commented 3 months ago

Here is the actual type:

export type Processor<T extends JobAttributes> = (job: Job<T>, done?: () => void) => void;

So, you cannot define async processors like mentioned in the example:

pulse.define(
  'doJob',
  async (job, done) => { // <-- defining `async` leads to a typescript compiler error: "Promise returned in function argument where a void return was expected."
    try {
      // processor logic
      done(); // <-- also leads to the error "Cannot invoke an object which is possibly 'undefined'"
    } catch (error) {
      console.error('Failed:', error);
    }
  }, {
    concurrency: 5,
    // etc...
});

Also, question: Why the done argument is optional? Where are conditions when done may be defined or not?

code-xhyun commented 3 months ago

Thank you for the issue! I will solve these and give you an answer as soon as possible.

code-xhyun commented 3 months ago

@kostysh

This was fixed in v1.1.9 🚀

export type Processor<T extends JobAttributesData> = (job: Job<T>, done: () => void) => void | Promise<void>;
cheeselemon commented 3 months ago

Awesome!

kostysh commented 3 months ago

Thank you, very quick )