msavin / SteveJobs

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

RangeError: Maximum call stack size exceeded #81

Closed LucianoVandi closed 5 years ago

LucianoVandi commented 5 years ago

Hi there and thanks for the great work you did with the package. I'm trying to replace vsivsi:job-collection in a Meteor project but when I run jobs I get the following error:

RangeError: Maximum call stack size exceeded
at packages/mongo/mongo_driver.js:117:
...

This happens even if the job complete it's work. I'm using Meteor 1.8.1

This is the job code:

import { Jobs } from 'meteor/msavin:sjobs';
import { Sales } from '../../lib/sales';
import * as winston from "winston"
import { Promise as MeteorPromise } from 'meteor/promise';

const registerJob = function({ name, run }) {
    Jobs.register({
      [name](...parameters) {
         MeteorPromise.await(run.apply(this, parameters));
      },
    });
}

registerJob({
    name: 'writeToSQL',
    async run(data) {
        const sales = new Sales();
        const job = this;
        try {
            const result = await sales.insertSQL(data);
            if(result){
              job.success(result);
              return;
            }else{
                winston.error('Job Failed', {
                  id: job.document._id,
                  data: result,
                });
                job.failure(result);
                return;
            }
        } catch (error) {
            winston.error('Job Failed', {
              id: job.document._id,
              error: error,
            });
            job.failure(error);
        }
    },
});

The try block is executed without errors and the code reach the job.success(result) part, but then it catch the error shown above making the job fail.

I call Jobs.run("writeToSQL") inside a Meteor Method. I think I'm doing something wrong but can't get what... -_-

msavin commented 5 years ago

Can you check if the job is failing?

I suspect passing in error param from the catch statement is what's messing it up. Maybe you need to pass error.stack

        job.failure(error.stack);
LucianoVandi commented 5 years ago

@msavin Yes is failing. I've update the job.failure with error.stack but the issue remain. I don't understand how it's reaching the catch block if everything seems work in the try block. I'm already calling job.success(result) if I got a result from sales.insertSQL(data) and doing console.log of the result confirm that. It looks weird...

LucianoVandi commented 5 years ago

@msavin Think i've found it. The error is thrown from job.success(result), where result is the set by await sale.insertSQL(). This method simply wrap Sequelize static create() that should return an object. This is an example of result:

OrderDetail {
  dataValues:
   { ... },
  _previousDataValues:
   { ... },
  _changed:
   { ... },
  _modelOptions:
   { ...
     sequelize:
      Sequelize { ... },
     hooks: {} },
  _options:
   { ... },
  isNewRecord: false,
  null: null 
}
LucianoVandi commented 5 years ago

@msavin maybe this issue should be closed. In fact the data I'm trying to pass to job.success() is not an object but an instance of OrderDetail model. Thanks for support and for the awesome work!