serverless / serverless-local-schedule

⚡️🗺️⏰ Schedule AWS CloudWatch Event based invocations in local time(with DST support!)
MIT License
72 stars 11 forks source link

Cannot Specify Day of the Week in Cron Expression #3

Open jfix opened 6 years ago

jfix commented 6 years ago

Hello, I've just installed your sls plugin, great find, thanks for the work! I have the following expression:

      - schedule:
          rate: cron(0 7 ? * MON-FRI *)
          timezone: Europe/Paris

When deploying from scratch via sls deploy I see the following lines, the first one being of your plugin:

$ sls deploy
Serverless: Converting local crontabs to UTC crontabs...
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Creating Stack...
Serverless: Checking Stack create progress...
.....
Serverless: Stack create finished...
Serverless: Uploading CloudFormation file to S3...
Serverless: Uploading artifacts...
Serverless: Uploading service .zip file to S3 (3 MB)...
Serverless: Validating template...
Serverless: Updating Stack...
Serverless: Checking Stack update progress...
.....................
Serverless: Operation failed!

  Serverless Error ---------------------------------------

  An error occurred: NudgerEventsRuleSchedule2 - send-export-feedback-nudge already exists in stack arn:aws:cloudformation:eu-central-1:[obfuscated]:stack/export-nudger-dev/[obfuscated].

Would you have an idea whether there is an attempt to create a schedule twice?

I had a look at the cloudformation-template-update-stack.json file in the unzipped deployment package and I cannot find anything problematic. I can provide this file if required for analysis.

jfix commented 6 years ago

I commented out the plugin and the corresponding timezone line in the serverless.yml file for the time being and deployment runs without fault ... mmh. ;-)

dschep commented 6 years ago

Hm.. not entirely sure about the specific error, but I have noticed that AWS is very picky about day-of-week & day-of-month. Namely, it seems one of them must be ?. However this conflicts with using this plugin & specifying day of week. This is because to support the split months (March & November in the US), the plugin has to specify a day of month (EG: November 1-3 this year), so you cannot specify a DOW other than ? unfortunately. I'm gonna leave this open since I need to document this limitation. For my own purposes, I accepted that It'll run every day (instead of weekdays, similar to your expression) and the code checks the DOW at start and exits if it is a weekend.

dschep commented 6 years ago

Idea from @dwolfand, make the plugin warn about this limitation in addition to documenting it in the readme.

jfix commented 6 years ago

OK, I understand the limitation (and yes, would be good to document and warn). I may move the check from the cron expression to my code too. Thanks for pointing that out.

XinfinityoO commented 6 years ago

i wish this issue could be fixed. also facing similar issue. cant get DST to work properly

dwolfand commented 6 years ago

I've updated the title of this issue and added a note about this to the readme as a first step. I am going to leave this open so we can eventually add a build-time error message when this happens.

simondutertre commented 5 years ago

Would love this to be fixed too.