Commit 8feb2731 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'feature/sidekiq-cron' into 'master'

Migrate from Sidetiq to Sidekiq-cron EE specific jobs

This is a followup from gitlab-org/gitlab-ce#2355 with specific EE jobs migrated to use Sidekiq-cron instead of Sidetiq

See merge request !69
parents 6b028ed8 0b29cb59
...@@ -125,8 +125,8 @@ gem 'acts-as-taggable-on', '~> 3.4' ...@@ -125,8 +125,8 @@ gem 'acts-as-taggable-on', '~> 3.4'
# Background jobs # Background jobs
gem 'sinatra', '~> 1.4.4', require: nil gem 'sinatra', '~> 1.4.4', require: nil
gem 'sidekiq', '3.3.0' gem 'sidekiq', '~> 3.5.0'
gem 'sidetiq', '~> 0.6.3' gem 'sidekiq-cron', '~> 0.3.0'
# HTTP requests # HTTP requests
gem "httparty", '~> 0.13.3' gem "httparty", '~> 0.13.3'
......
...@@ -116,8 +116,23 @@ GEM ...@@ -116,8 +116,23 @@ GEM
activemodel (>= 3.2.0) activemodel (>= 3.2.0)
activesupport (>= 3.2.0) activesupport (>= 3.2.0)
json (>= 1.7) json (>= 1.7)
celluloid (0.16.0) celluloid (0.17.2)
timers (~> 4.0.0) celluloid-essentials
celluloid-extras
celluloid-fsm
celluloid-pool
celluloid-supervision
timers (>= 4.1.1)
celluloid-essentials (0.20.5)
timers (>= 4.1.1)
celluloid-extras (0.20.5)
timers (>= 4.1.1)
celluloid-fsm (0.20.5)
timers (>= 4.1.1)
celluloid-pool (0.20.5)
timers (>= 4.1.1)
celluloid-supervision (0.20.5)
timers (>= 4.1.1)
charlock_holmes (0.7.3) charlock_holmes (0.7.3)
chunky_png (1.3.5) chunky_png (1.3.5)
cliver (0.3.2) cliver (0.3.2)
...@@ -374,7 +389,6 @@ GEM ...@@ -374,7 +389,6 @@ GEM
multi_xml (>= 0.5.2) multi_xml (>= 0.5.2)
httpclient (2.7.0.1) httpclient (2.7.0.1)
i18n (0.7.0) i18n (0.7.0)
ice_cube (0.11.1)
ice_nine (0.11.1) ice_nine (0.11.1)
inflecto (0.0.2) inflecto (0.0.2)
ipaddress (0.8.0) ipaddress (0.8.0)
...@@ -645,6 +659,7 @@ GEM ...@@ -645,6 +659,7 @@ GEM
sexp_processor (~> 4.1) sexp_processor (~> 4.1)
rubyntlm (0.5.2) rubyntlm (0.5.2)
rubypants (0.2.0) rubypants (0.2.0)
rufus-scheduler (3.1.10)
rugged (0.23.3) rugged (0.23.3)
safe_yaml (1.0.4) safe_yaml (1.0.4)
sanitize (2.1.0) sanitize (2.1.0)
...@@ -672,16 +687,15 @@ GEM ...@@ -672,16 +687,15 @@ GEM
rack rack
shoulda-matchers (2.8.0) shoulda-matchers (2.8.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
sidekiq (3.3.0) sidekiq (3.5.3)
celluloid (>= 0.16.0) celluloid (~> 0.17.2)
connection_pool (>= 2.0.0) connection_pool (~> 2.2, >= 2.2.0)
json json (~> 1.0)
redis (>= 3.0.6) redis (~> 3.2, >= 3.2.1)
redis-namespace (>= 1.3.1) redis-namespace (~> 1.5, >= 1.5.2)
sidetiq (0.6.3) sidekiq-cron (0.3.1)
celluloid (>= 0.14.1) rufus-scheduler (>= 2.0.24)
ice_cube (= 0.11.1) sidekiq (>= 2.17.3)
sidekiq (>= 3.0.0)
simple_oauth (0.1.9) simple_oauth (0.1.9)
simplecov (0.10.0) simplecov (0.10.0)
docile (~> 1.1.0) docile (~> 1.1.0)
...@@ -747,7 +761,7 @@ GEM ...@@ -747,7 +761,7 @@ GEM
thor (0.19.1) thor (0.19.1)
thread_safe (0.3.5) thread_safe (0.3.5)
tilt (1.4.1) tilt (1.4.1)
timers (4.0.4) timers (4.1.1)
hitimes hitimes
timfel-krb5-auth (0.8.3) timfel-krb5-auth (0.8.3)
tinder (1.10.1) tinder (1.10.1)
...@@ -945,8 +959,8 @@ DEPENDENCIES ...@@ -945,8 +959,8 @@ DEPENDENCIES
settingslogic (~> 2.0.9) settingslogic (~> 2.0.9)
sham_rack sham_rack
shoulda-matchers (~> 2.8.0) shoulda-matchers (~> 2.8.0)
sidekiq (= 3.3.0) sidekiq (~> 3.5.0)
sidetiq (~> 0.6.3) sidekiq-cron (~> 0.3.0)
simplecov (~> 0.10.0) simplecov (~> 0.10.0)
sinatra (~> 1.4.4) sinatra (~> 1.4.4)
six (~> 0.2.0) six (~> 0.2.0)
......
class HistoricalDataWorker class HistoricalDataWorker
include Sidekiq::Worker include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence { daily.hour_of_day(12) }
def perform def perform
HistoricalData.track! HistoricalData.track!
......
class LdapSyncWorker class LdapSyncWorker
include Sidekiq::Worker include Sidekiq::Worker
include Sidetiq::Schedulable
sidekiq_options retry: false sidekiq_options retry: false
if Gitlab.config.ldap.enabled
DAILY = Gitlab.config.ldap.schedule_sync_daily
HOUR = Gitlab.config.ldap.schedule_sync_hour
MINUTE = Gitlab.config.ldap.schedule_sync_minute
recurrence { daily(DAILY).hour_of_day(HOUR).minute_of_hour(MINUTE) }
end
def perform def perform
Rails.logger.info "Performing daily LDAP sync task." Rails.logger.info "Performing daily LDAP sync task."
User.ldap.find_each(batch_size: 100).each do |ldap_user| User.ldap.find_each(batch_size: 100).each do |ldap_user|
......
class StuckCiBuildsWorker class StuckCiBuildsWorker
include Sidekiq::Worker include Sidekiq::Worker
include Sidetiq::Schedulable
BUILD_STUCK_TIMEOUT = 1.day BUILD_STUCK_TIMEOUT = 1.day
recurrence { daily }
def perform def perform
Rails.logger.info 'Cleaning stuck builds' Rails.logger.info 'Cleaning stuck builds'
......
class UpdateAllMirrorsWorker class UpdateAllMirrorsWorker
include Sidekiq::Worker include Sidekiq::Worker
include Sidetiq::Schedulable
recurrence { hourly }
def perform def perform
Project.mirror.each(&:update_mirror) Project.mirror.each(&:update_mirror)
......
...@@ -170,13 +170,10 @@ production: &base ...@@ -170,13 +170,10 @@ production: &base
ldap: ldap:
enabled: false enabled: false
# GitLab EE only. #
# In addition to refreshing users when they log in, # Gitlab EE only:
# enabling this setting will refresh LDAP user membership once a day. # Since Gitlab 8.3, LDAP refresh job execution can be configured in schedule.yml
# Default time of the day when this will happen is at 1:30am server time. #
schedule_sync_daily: 1 # Run once every X days. Default: 1, meaning 'daily'
schedule_sync_hour: 1 # Hour of the day. Value from 0-23.
schedule_sync_minute: 30 # Minute of the hour. Value from 0-59.
servers: servers:
########################################################################## ##########################################################################
......
...@@ -17,6 +17,12 @@ Sidekiq.configure_server do |config| ...@@ -17,6 +17,12 @@ Sidekiq.configure_server do |config|
chain.add Gitlab::SidekiqMiddleware::ArgumentsLogger if ENV['SIDEKIQ_LOG_ARGUMENTS'] chain.add Gitlab::SidekiqMiddleware::ArgumentsLogger if ENV['SIDEKIQ_LOG_ARGUMENTS']
chain.add Gitlab::SidekiqMiddleware::MemoryKiller if ENV['SIDEKIQ_MEMORY_KILLER_MAX_RSS'] chain.add Gitlab::SidekiqMiddleware::MemoryKiller if ENV['SIDEKIQ_MEMORY_KILLER_MAX_RSS']
end end
# Sidekiq-cron: load recurring jobs from schedule.yml
schedule_file = 'config/schedule.yml'
if File.exists?(schedule_file)
Sidekiq::Cron::Job.load_from_hash YAML.load(ERB.new(File.read(schedule_file)).result)
end
end end
Sidekiq.configure_client do |config| Sidekiq.configure_client do |config|
......
require 'sidekiq/web' require 'sidekiq/web'
require 'sidekiq/cron/web'
require 'api/api' require 'api/api'
Rails.application.routes.draw do Rails.application.routes.draw do
......
# Here is a list of jobs that are scheduled to run periodically.
# We use a UNIX cron notation to specify execution schedule.
#
# Please read here for more information:
# https://github.com/ondrejbartas/sidekiq-cron#adding-cron-job
stuck_ci_builds_worker:
cron: "0 0 * * *"
class: "StuckCiBuildsWorker"
queue: "default"
#
# GitLab EE only jobs:
#
historical_data_worker:
cron: "0 12 * * *"
class: "HistoricalDataWorker"
queue: "default"
update_all_mirrors_worker:
cron: "0 * * * *"
class: "UpdateAllMirrorsWorker"
queue: "default"
<% if Gitlab.config.ldap.enabled %>
# In addition to refreshing users when they log in,
# enabling this setting will refresh LDAP user membership once a day.
# Default time of the day when this will happen is at 1:30am server time.
ldap_sync_worker:
cron: "30 1 * * *"
class: "LdapSyncWorker"
queue: "default"
<% end %>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment