Bull: Question: Running from cron

Created on 19 Mar 2019  路  2Comments  路  Source: OptimalBits/bull

Description

Hi, Thank you for sharing the code and creating this great library.

I would like to know how to run code in my function 'myCustomMethod' via the Queue/Bull . Is this the right way to do it?

./models/Sport.js

export async function myCustomMethod(type, req)
{
    console.log("This method should be executed via the Queue / Bull");
    let computationResult = true;
    return computationResult;
}

cronCustomFile.js

import { myCustomMethod } from './models/Sport.js';

cron.schedule('*/5 * * * * *', () =>
{
    var battleRoyaleQueue = new Queue('battle_royale_queue');
    console.log('Checking live events every 5 seconds');
    battleRoyaleQueue.process(function (job, done)
    {
        try
        {
            console.log('Processing via battle_royale_queue');
            myCustomMethod('live-events');
            done();
        }
        catch (err)
        {
            console.log(err.message);
        }
    });
    return true;
});

Bull version

"bull": "^3.6.0"

Additional information

It looks like jobs are not being added to the queue or processed.

Screen Shot 2019-03-18 at 9 23 27 PM

Console
Screen Shot 2019-03-18 at 9 31 08 PM

question

Most helpful comment

Apparently, you create the process (battleRoyaleQueue) but you never call it.

You can try a repeatable parameter:

import { myCustomMethod } from './models/Sport.js';

battleRoyaleQueue.process(function (job, done) {
  try{
    console.log('Processing via battle_royale_queue');
    myCustomMethod('live-events');
    done();
  } catch (err) {
    console.log(err.message);
  }
});

battleRoyaleQueue.add({
  repeat: {
    cron: '*/5 * * * * *'
  }
})

All 2 comments

Apparently, you create the process (battleRoyaleQueue) but you never call it.

You can try a repeatable parameter:

import { myCustomMethod } from './models/Sport.js';

battleRoyaleQueue.process(function (job, done) {
  try{
    console.log('Processing via battle_royale_queue');
    myCustomMethod('live-events');
    done();
  } catch (err) {
    console.log(err.message);
  }
});

battleRoyaleQueue.add({
  repeat: {
    cron: '*/5 * * * * *'
  }
})

Thank you! The issue has been solved

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rodrigoords picture rodrigoords  路  4Comments

sibelius picture sibelius  路  3Comments

chocof picture chocof  路  3Comments

tdzienniak picture tdzienniak  路  4Comments

PhillippOhlandt picture PhillippOhlandt  路  4Comments