Different Oban Periodic Jobs Per Each Deployment Environments

Hello community.

My understanding is that only way to setup a recurring periodic job with Oban Workers is to utilize the Oban.Plugins.Cron. Documentation seems to set the configuration on the config.exs. My question is if I use the same container image to deploy to multiple environment servers (test, sandbox, production, etc), won’t this run all the periodic jobs on each the servers?

This is not a desired action in my case because each job will have a notification email info within the args data and will send out the notification even for non-production environment runs. Each environments are deployed with the same container images so will have same configurations (email address).

So far options I have come up with:

  1. Update the config.exs after deployment to each servers. This is not ideal as each deployment will overwrite the environment specific config.exs.
  2. Implement a environment value check for all the Workers to only execute on specific envrionments. For example, only call perform function if env_variable is “prod”. I question if this is a good approach to manage all Worker executions this way.

Please let me know if I am missing something here of if you need any additional info. I am open to any suggestions as I am bit stuck at this point.

If you define the cron in each of your environment specific configuration files (config/prod.exs, config/test.exs, etc.) then they’d be isolated.

Thanks for the suggestion. I did consider this option, but aren’t the config/{environment}.exs files used for build envrionment configuration? For example, when runing a mix command default would be dev.exs, but if I run a mix test it would pull from test.exs. Also, if I set MIX_ENV=prod then it would pull from prod.exs. But this only applies during the build stage?

I am setting MIX_ENV=prod for building the container image which will be deployed to all envrionment servers (test, sandbox, prod, etc.). It seems if I wanted to use the {environment}.exs files then I need to create different container images for each release environments. I would like to find a way to use a single image for all the release, as it would prevent unnecessary issues managing multiple container images.

I have confirmed this with some testing, but maybe I am missing something in this approach?