breejs / bree

Bree is a Node.js and JavaScript job task scheduler with worker threads, cron, Date, and human syntax. Built for @ladjs, @forwardemail, @spamscanner, @cabinjs.
https://jobscheduler.net
MIT License
3.06k stars 79 forks source link

Ran into an issue with a recurring instance of later.js #85

Closed ivorpad closed 3 years ago

ivorpad commented 3 years ago

This doesn't work as expected or am I doing something wrong?:

interval: later.parse.recur().on("12:10").time(),

Got this error:

internal/worker.js:210
    this[kPort].postMessage({
                ^

DOMException [DataCloneError]: function on() {
      values = Array.isArray(arguments[0]) ? arguments[0] : arguments;
      return this;
    } could not be cloned.
    at new Worker (internal/worker.js:210:17)
    at Bree.run (/Users/ivor/Developer/projects/order-tracking-app/ezot-jobs-server/node_modules/bree/lib/index.js:275:30)
    at /Users/ivor/Developer/projects/order-tracking-app/ezot-jobs-server/node_modules/bree/lib/index.js:460:27
    at Timeout.scheduleTimeout [as _onTimeout] (/Users/ivor/Developer/projects/order-tracking-app/ezot-jobs-server/node_modules/@breejs/later/lib/index.js:1013:7)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)
npm ERR! code ELIFECYCLE
npm ERR! errno 1

It works perfectly with later.parse.text but I need the job to ocurr at a certain date after the created_at field in the database. Basically:

const date = new Date(job.created_at);
const hour = date.getUTCHours();
const minute = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
later.parse.recur().on(`${hour}:${minute}:${seconds}`).time().on(getDay(date)).dayOfMonth();
ivorpad commented 3 years ago

Alright, so it seems you need to pass an object to interval:

 const everyThirtyDays = later.parse.recur().every(20).second();
 interval: { schedules: everyTwentySeconds.schedules }
shadowgate15 commented 3 years ago

Looks like you solved it yourself, @ivorpad. Let us know if you need anymore help with this but will close it for now.