Skip to content
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

Using cron #32

Closed
pinguxx opened this issue Aug 27, 2020 · 5 comments
Closed

Using cron #32

pinguxx opened this issue Aug 27, 2020 · 5 comments

Comments

@pinguxx
Copy link

pinguxx commented Aug 27, 2020

Can somebody give me a simple example, im trying to use bree with a cron, but it just exit and nothing happens

const Bree = require('bree');

const bree = new Bree({
    jobs: [{
        name: 'test1',
        cron : '* * * * *'
    }]

});

bree.start();

job/test1

const { parentPort } = require("worker_threads");

console.log("working")
if (parentPort) parentPort.postMessage("done");
else process.exit(0);
@pinguxx
Copy link
Author

pinguxx commented Aug 27, 2020

After looking at the code i found that this works

const Bree = require('bree');
const later = require('@breejs/later');
var s = later.parse.cron('* * * * *');

const bree = new Bree({
    cronValidate: {},
    jobs: [{
        name: 'test1',
        cron : s
    }]

});

bree.start();

Two problems

  1. Looks like on parsing the cron is generating some functions that cant be send to the worker but it never generates a correct scheduel
  2. on start it never checks cron options since is assuming it will have an interval or similar

I assume that changing this piece of code may fix the problem

if (result.isValid()) {
          const schedule = later.schedule(
            later.parse.cron(
              job.cron,
              boolean(
                typeof job.hasSeconds === 'undefined'
                  ? this.config.hasSeconds
                  : job.hasSeconds
              )
            )
          );

So the schedule is correct and not functions, but i dont know later so not sure change it to what :P

@niftylettuce
Copy link
Contributor

Taking a look, sec

@niftylettuce
Copy link
Contributor

Ok, release inbound, one moment.

@niftylettuce
Copy link
Contributor

@pinguxx
Copy link
Author

pinguxx commented Aug 28, 2020

seems to be working now :D
Thanks for the quick fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants