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.01k stars 78 forks source link

[bug] Can't Set L in Cron. had an invalid cron pattern: Element 'L of daysOfMonth field is invalid. (Input cron: '30 18 L * *') #135

Closed DynamiteC closed 2 years ago

DynamiteC commented 2 years ago

Getting Above Error While Setting up Cron Job for Last Day of month at 6:30pm time. As per the guidelines the cron is supported.

    // runs `./jobs/worker-11.js` at midnight on the last day of month
    {
      name: 'worker-11',
      cron: '0 0 L * *'
    },

I got referenced from above, how to resolve this.

This is my code.

const bree = new Bree({
  logger,
  jobs: [{
    name: 'testJob',
    cron: '30 18 L * *'
  }]
});

This is the full error.

Error: Job #1 named "testJob" had an invalid cron pattern: Element 'L of daysOfMonth field is invalid. (Input cron: '30 18 L * *')
    at validateCron (/home/user/project/node_modules/bree/lib/job-validator.js:175:23)
    at validate (/home/user/project/node_modules/bree/lib/job-validator.js:265:64)
    at Bree.init (/home/user/project/node_modules/bree/lib/index.js:261:11)
    at new Bree (/home/user/project/node_modules/bree/lib/index.js:193:11)
    at Object.<anonymous> (/home/user/project/crons/test-job.js:5:14)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
shadowgate15 commented 2 years ago

add

      cronValidate: {
        override: {
          useLastDayOfWeek: true
        }
      }

to your job configuration. Will be adding this to the docs thanks for catching it.

DynamiteC commented 2 years ago

@shadowgate15 @niftylettuce Hi, This still didnt workout.

I tried both ways

    cron: '30 18 L * *',
    cronValidate: {
      useLastDayOfMonth: true
    }

as well as

    cron: '30 18 L * *',
    cronValidate: {
      override: {
        useLastDayOfMonth: true
      }
    }

It shows same error.

Error: Job #1 named "testJob" had an invalid cron pattern: Element 'L of daysOfMonth field is invalid. (Input cron: '30 18 L * *')
shadowgate15 commented 2 years ago

Just to confirm, which version of Bree are you using?

DynamiteC commented 2 years ago

I have found a workaround this.

hasSeconds: true,
cronValidate: {
   override: {
        useLastDayOfMonth: true
      }
    }