msavin / SteveJobs

A simple jobs queue that just works (for Meteor.js)
Other
207 stars 35 forks source link

async / await Failure #94

Closed 67726e closed 2 years ago

67726e commented 3 years ago

Currently running into issues with the async / await support around job failures.

Environment:

Meteor 2.0
msavin:sjobs@4.0.0

Example:

// ./jobs/index.js
import { transitionState } from './state/';

Jobs.register({
  transitionState,
});

// ./jobs/state/index.js
export const transitionState = async function(request) {
  return await new StateTransitionJob(request).run();
};

// ./jobs/state/StateTransitionJob.js
export default class StateTransitionJob {
  async run() {
    throw Meteor.Error('...', '...');
  }
}

The expected result would be a job in the failure state, however it appears in the success state.

{
        "_id" : "5x8C75cwDKiXHpK8T",
        "name" : "transitionState",
        "created" : ISODate("2021-03-26T02:07:55.978Z"),
        "serverId" : "9jBr88nptszzRTHPE",
        "state" : "success",
        "due" : ISODate("2021-03-26T02:07:55.978Z"),
        "priority" : 0,
        "arguments" : [],
        "history" : [
                {
                        "date" : ISODate("2021-03-26T02:07:56.671Z"),
                        "state" : "success",
                        "serverId" : "9jBr88nptszzRTHPE",
                        "result" : {

                        }
                }
        ]
}

The results I see in the CLI:

W20210325-22:07:56.675(-4)? (STDERR) (node:9571) UnhandledPromiseRejectionWarning: undefined
W20210325-22:07:56.676(-4)? (STDERR) (node:9571) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
67726e commented 3 years ago

One can manually add the then and catch to manually update the job status, however support for these functions is a state feature of the 4.0 release so I'm not sure if I'm just not doing something right here?

// ./jobs/state/index.js
export const transitionState = async function(request) {
  return await new StateTransitionJob(request).run()
    .then(() => this.success())
    .catch(() => this.failure());
};
20210325-22:16:42.035(-4)? ****
I20210325-22:16:42.035(-4)? Jobs: Job has failed: transitionState, ftajf4yFrtHZ3iwQh
I20210325-22:16:42.035(-4)? Jobs: Queue was stopped; please correct your job function and restart the server
I20210325-22:16:42.036(-4)? ****
67726e commented 3 years ago

Looking at your most recent commit, there appears to be a mismatch between expectations of the function's name vs. practice:

console.log('Name:', transitionState.constructor.name);
Name: Function

https://github.com/msavin/SteveJobs/commit/3db5623895b61bba50b0dcb0fc16adc5223f1aea#diff-501cf71c87bf08799812e67f523688ad62a947e90288368f53dffc1952b37e8b

weilitao commented 3 years ago

same error here. It looks 3.1.1 do not have this bug.

weilitao commented 3 years ago

Looking at your most recent commit, there appears to be a mismatch between expectations of the function's name vs. practice:

console.log('Name:', transitionState.constructor.name);
Name: Function

3db5623#diff-501cf71c87bf08799812e67f523688ad62a947e90288368f53dffc1952b37e8b

So how to fix that?

67726e commented 3 years ago

@weilitao Personally, I haven't bothered using this library. I found, https://github.com/wildhart/meteor.jobs, a much more thought-out library with a responsive, helpful, and friendly author.

weilitao commented 3 years ago

@weilitao Personally, I haven't bothered using this library. I found, https://github.com/wildhart/meteor.jobs, a much more thought-out library with a responsive, helpful, and friendly author.

Thanks. I'll check that library.

msavin commented 2 years ago

Hey folks - this has been fixed in the new version