ajmath / serverless-offline-scheduler

MIT License
96 stars 40 forks source link

TypeError: scheduleEvent.replace is not a function #78

Open BhuvaneshwaranR opened 2 years ago

BhuvaneshwaranR commented 2 years ago
config.yml

cron:
  handler:  cron
  events:
    - schedule:
        name: schedule-cron
        description: "Trigger the every Monday at 08:00 UTC"
        rate: cron(0 8 ? * MON *)

Throws an error

Type Error ----------------------------------------------

TypeError: scheduleEvent.replace is not a function at Scheduler._convertExpressionToCron (J:\project\node_modules\serverless-offline-scheduler\lib\scheduler.js:177:8)

_convertExpressionToCron(scheduleEvent) {
    const params = scheduleEvent
      .replace("rate(", "")
      .replace("cron(", "")
      .replace(")", "");

    if (scheduleEvent.startsWith("cron(")) {
      return this._convertCronSyntax(params);
    }
    if (scheduleEvent.startsWith("rate(")) {
      return this._convertRateToCron(params);
    }

    this.serverless.cli.log("scheduler: invalid, schedule syntax");
    return null;
  }

_convertExpressionToCron function received scheduleEvent parameter as an array. [ 'cron(0 8 ? * MON *)' ]

So replace function doesn't work on the array value. This has to be type-checked, iterated, and replace login should be applied.

focus1691 commented 2 years ago

I guess you fixed it but didn't publish the new changes on npm?

Ikrama312 commented 2 years ago

I'm facing the same issue.

danilaplee commented 2 years ago

why is this not merged? @ajmath