Add Sidekiq Cron timezone override configuration
What does this MR do and why?
Allows setting up a timezone override to sidekiq-cron, so each job scheduled for 3 AM runs in the correct timezone (which may be different then the one set for the rails application in environments like GitLab Dedicated).
This includes:
- Migration
- Models
- API
This does not include Admin UI frontend changes
References
Part of #582262
How to set up and validate locally
-
Export an administrator personal access token (adjust the host if needed):
export GITLAB_TOKEN=<admin_token> export GITLAB_URL=http://localhost:3000 -
Read the current settings and confirm the new attribute defaults to
null:curl -Ss --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ --url "$GITLAB_URL/api/v4/application/settings" | jq '.sidekiq_timezone_override' # => null -
Confirm an invalid IANA identifier is rejected with
400 Bad Request:curl -Ss --request PUT --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ --url "$GITLAB_URL/api/v4/application/settings?sidekiq_timezone_override=Not/AZone" # => {"message":{"sidekiq_timezone_override":["must be a valid IANA timezone identifier"]}} -
Set a valid timezone and confirm it is returned:
curl -Ss --request PUT --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ --url "$GITLAB_URL/api/v4/application/settings?sidekiq_timezone_override=America/Chicago" \ | jq '.sidekiq_timezone_override' # => "America/Chicago" -
In a terminal, confirm the cron jobs pick up the override (timezone appended to each cron string):
gdk restart rails-background-jobs gdk tail rails-background-jobs # wait until it is fully boot up, then control C to exit bundle exec rails runner 'puts Gitlab::SidekiqConfig::CronJobs.config.jobs.values.first["cron"]' # => 3-59/10 * * * * America/Chicago -
Clear the override by sending a blank value through the API and confirm it resets to ``:
curl -Ss --request PUT --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \ --url "$GITLAB_URL/api/v4/application/settings?sidekiq_timezone_override=" \ | jq '.sidekiq_timezone_override' # => '' -
In a terminal, confirm no timezone token is appended once the override is blank:
gdk restart rails-background-jobs gdk tail rails-background-jobs # wait until it is fully boot up, then control C to exit bundle exec rails runner 'puts Gitlab::SidekiqConfig::CronJobs.config.jobs.values.first["cron"]' # => 3-59/10 * * * * America/Chicago
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.