What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Hey! Does anybody know, how to define if a cronjob should run on a certain environment? I see there

UPPB2H525
UPPB2H525 Posts: 51 🧑🏻‍🚀 - Cadet
edited February 2021 in Help

Hey! Does anybody know, how to define if a cronjob should run on a certain environment? I see there was a possibility to set run_on_non_production in cronjob definitions. But this does not work anymore with scheduler module shipped by spryker. vendor/spryker/setup/src/Spryker/Zed/Setup/Business/Model/Cronjobs.php is marked to be deprecated meanwhile and is still not used anymore.
Of course, i could check APPLICATION_ENV in config/Zed/cronjobs/jenkins.php and set enable accordingly. Should this be the "right" way?

Comments

  • Valerii Trots
    Valerii Trots SRE @ Spryker Sprykee Posts: 1,654 ✨ - Novice

    I believe you need to switch\migrate to spryker/scheduler-jenkins where the issue with run_on_non_production=>false has been fixed - https://api.release.spryker.com/release-group/2637.

  • UPPB2H525
    UPPB2H525 Posts: 51 🧑🏻‍🚀 - Cadet

    I am already using spryker/scheduler-jenkins in version 1.2.1. There is nothing like 'run_on_non_production' or similar in the code

  • Alberto Reyer
    Alberto Reyer Lead Spryker Solution Architect / Technical Director Posts: 690 🪐 - Explorer

    We have the following in jobs.php:

    if (Environment::isProduction() === false) {
    //non production job definition
    }
    
  • UPPB2H525
    UPPB2H525 Posts: 51 🧑🏻‍🚀 - Cadet

    Ya, this seems to be the only possibility. Thanks Alberto!

  • UPPB2H525
    UPPB2H525 Posts: 51 🧑🏻‍🚀 - Cadet

    Although...Envíronment is also marked to be deprecated and will be removed without replacement.

  • Andriy Netseplyayev
    Andriy Netseplyayev Domain Lead Solution Architecture Sprykee Posts: 519 🧑🏻‍🚀 - Cadet
    edited February 2021

    Hey @UPPB2H525 👋
    I think there is one more option, I didn’t not tried that myself, but looking from code should be possible:
    1. You can introduce a new array property in jobs.php where you could specify an environment (or array of envs);
    2. Extend the command “scheduler:setup” and introduce environment as a parameter (-e=your_env);
    3. Introduce a new ChainableJobsFilterInterface that would filter out jobs based on environment parameter vs. environment in jobs.php array (\Spryker\Zed\Scheduler\Business\SchedulerBusinessFactory::createJobsFilter())
    4. In respective config/install/your-environment.yml pipeline, you can call the command with the new parameter “vendor/bin/console scheduler:setup -e=your_env”

  • Andriy Netseplyayev
    Andriy Netseplyayev Domain Lead Solution Architecture Sprykee Posts: 519 🧑🏻‍🚀 - Cadet

    it sounds like more todo comparing to @UL6DGRULR solution, but could be also a bit cleaner and more flexible. But if Alberto’s solution fully covers your needs - I would go with it

  • UPPB2H525
    UPPB2H525 Posts: 51 🧑🏻‍🚀 - Cadet

    Thank you @UKJSE6T47