Skip to content

Commit

Permalink
🧹 add dynamic toggling for job scheduling using environment variables
Browse files Browse the repository at this point in the history
- Updated `find_or_schedule_jobs` to dynamically include jobs based on environment variables.
- Introduced the following environment flags to control job scheduling:
  - `ENABLE_BATCH_EMAIL` for `BatchEmailNotificationJob`
  - `ENABLE_DEPOSITOR_EMAIL` for `DepositorEmailNotificationJob`
  - `ENABLE_USER_STAT` for `UserStatCollectionJob`
- This allows buggy jobs to be disabled temporarily without modifying the codebase.
- Default behavior ensures only non-buggy jobs are scheduled when flags are not set.
  • Loading branch information
Shana Moore committed Jan 24, 2025
1 parent c90b207 commit 6ee3c42
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions app/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,21 @@ def find_job(klass)
def find_or_schedule_jobs
account = Site.account
AccountElevator.switch!(self)
[

jobs_to_schedule = [
EmbargoAutoExpiryJob,
LeaseAutoExpiryJob,
BatchEmailNotificationJob,
DepositorEmailNotificationJob,
UserStatCollectionJob
].each do |klass|
LeaseAutoExpiryJob
]

# Add conditional checks based on a config or environment variable
jobs_to_schedule << BatchEmailNotificationJob if ENV['ENABLE_BATCH_EMAIL'] == 'true'
jobs_to_schedule << DepositorEmailNotificationJob if ENV['ENABLE_DEPOSITOR_EMAIL'] == 'true'
jobs_to_schedule << UserStatCollectionJob if ENV['ENABLE_USER_STAT'] == 'true'

jobs_to_schedule.each do |klass|
klass.perform_later unless find_job(klass)
end

account ? AccountElevator.switch!(account) : reset!
end
end
Expand Down

0 comments on commit 6ee3c42

Please sign in to comment.