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

fix!: remove disableScheduledEvents option #1582

Merged
merged 1 commit into from
Sep 29, 2022

Conversation

dnalborczyk
Copy link
Collaborator

@dnalborczyk dnalborczyk commented Sep 26, 2022

Description

BREAKING, next major release, v11

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

@dnalborczyk dnalborczyk marked this pull request as ready for review September 26, 2022 02:04
@dnalborczyk dnalborczyk merged commit a640c37 into master Sep 29, 2022
@dnalborczyk dnalborczyk deleted the remove-disableScheduledEvents branch September 29, 2022 01:04
@tobeno
Copy link

tobeno commented Oct 11, 2022

Hi @dnalborczyk ! I just stumbled upon this and was wondering about the context of this. Was this removed because there is a better solution? If yes, can you share it maybe?

We used this feature to disable cronjobs locally as they are hard to predict there and it is usually better to just invoke the cron handler directly instead of waiting for the cron trigger for development.

I could not find any mention on the reasoning behind this and also all mentions in the README.md seem to be gone without replacement. So wanted to ask quickly. Is there a better way to solve our use case?

Many thanks!

@dnalborczyk
Copy link
Collaborator Author

Was this removed because there is a better solution? If yes, can you share it maybe?

@tobeno not necessarily better, but a built-in solution does exist. I mentioned this in the v11.0.0 release overview: https://github.com/dherault/serverless-offline/releases/tag/v11.0.0 -> events.schedule.enabled

in order to flip back and forth between development (turned off) and deployment (turned on) you could use serverless variables/conditions/fallbacks etc.

I wanted to create an overview for past and future migration paths, and tips & tricks kind of thing. still on the toto list. let me know if you run into any issues with that approach.

@tobeno
Copy link

tobeno commented Oct 11, 2022

@dnalborczyk Ah, missed that as I only checked the CHANGELOG.md (which also renovate bot forwarded in the update PR). Thanks for the pointer! 👍

Will add this behaviour then to an inline plugin (using plugins.localPath in Serverless config) we are using to mutate the Serverless config dynamically for remote stages. Something like "if offline / stage is local, remove all functions that have a schedule event defined" should work. Will fulfil the same task, just was curious if it is possible without extra code.
(reason for the plugin approach being that we really want to avoid execution of automated logic locally and the "enabled" definition is something that you can forget)

But see your point of this not necessarily being a feature that the offline runtime needs to provide as there are many ways to solve it using the config or plugins. Thanks for the clarification!

@andidev
Copy link
Contributor

andidev commented Aug 30, 2023

we are having issues upgrading to latest offline verison to support latest python runtime because of this.
I am surprised no one has complained and asked.
Its pretty easy to solve but not super clear.

this is how we solved it in case someone needs it. we modified our start scripts with a param cronEnabled set to false

  "scripts": {
    "start:localhost":"npx serverless offline --stage localhost --param='cronEnabled=false"
    "start:dev":"npx serverless offline --stage dev --param='cronEnabled=false'"
    "start:test":"npx serverless offline --stage test --param='cronEnabled=false"
    "start:prod":"npx serverless offline --stage prod --param='cronEnabled=false"
  }

then as mentioned in our cron config we do this and fallback to the env variable that enables or disables it per environment:

  cron:
    handler: src/cron._run
    timeout: 900
    events:
      - schedule:
          rate: cron(*/1 * * * ? *)
          enabled: ${param:cronEnabled, strToBool(${env:CRON_ENABLED})}
          input:
            task: aCronTask

this change could have been a bit more clear on how to solve this issue.

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

Successfully merging this pull request may close these issues.

3 participants