Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit a4736c0

Browse files
Merge pull request #427 from BRIMIL01/add_sidekiq_cron
Added sidekiq cron to allow for the scheduling of jobs
2 parents 46c4c90 + e94bb18 commit a4736c0

File tree

9 files changed

+59
-19
lines changed

9 files changed

+59
-19
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,6 @@ Style/RescueStandardError:
678678
- 'app/lib/json_web_token.rb'
679679
- 'app/lib/send_grid_client.rb'
680680
- 'config/initializers/core_extensions/devise/strategies/json_web_token.rb'
681-
- 'lib/tasks/git_hub.rake'
682681
- 'lib/tasks/meetup.rake'
683682
- 'lib/tasks/resource.rake'
684683
- 'lib/tasks/users.rake'

.ruby-gemset

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
operationcode_backend
1+
-global

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ gem 'rubocop', '~> 0.55.0', require: false
2929
gem 'sendgrid-ruby'
3030
gem 'sentry-raven'
3131
gem 'sidekiq'
32+
gem 'sidekiq-cron'
3233
gem 'skylight'
3334
gem 'pry-rails'
3435

Gemfile.lock

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ GEM
9090
responders
9191
warden (~> 1.2.3)
9292
erubis (2.7.0)
93+
et-orbi (1.1.6)
94+
tzinfo
9395
execjs (2.7.0)
9496
factory_girl (4.8.0)
9597
activesupport (>= 3.0.0)
@@ -104,6 +106,9 @@ GEM
104106
formtastic (3.1.5)
105107
actionpack (>= 3.2.13)
106108
formtastic_i18n (0.6.0)
109+
fugit (1.1.6)
110+
et-orbi (~> 1.1, >= 1.1.6)
111+
raabro (~> 1.1)
107112
geocoder (1.4.3)
108113
gibbon (3.0.1)
109114
faraday (>= 0.9.1)
@@ -185,6 +190,7 @@ GEM
185190
pry (>= 0.10.4)
186191
public_suffix (3.0.0)
187192
puma (3.8.2)
193+
raabro (1.1.6)
188194
rack (2.0.5)
189195
rack-cors (0.4.1)
190196
rack-protection (2.0.3)
@@ -251,6 +257,9 @@ GEM
251257
connection_pool (~> 2.2, >= 2.2.2)
252258
rack-protection (>= 1.5.0)
253259
redis (>= 3.3.5, < 5)
260+
sidekiq-cron (1.0.4)
261+
fugit (~> 1.1)
262+
sidekiq (>= 4.2.1)
254263
skylight (1.5.0)
255264
activesupport (>= 3.0.0)
256265
spring (2.0.1)
@@ -313,11 +322,12 @@ DEPENDENCIES
313322
sendgrid-ruby
314323
sentry-raven
315324
sidekiq
325+
sidekiq-cron
316326
skylight
317327
spring
318328
spring-watcher-listen (~> 2.0.0)
319329
vcr (~> 3.0, >= 3.0.3)
320330
webmock (~> 3.0, >= 3.0.1)
321331

322332
BUNDLED WITH
323-
1.16.4
333+
1.16.5
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class GithubCollectStatisticsJob
2+
include Sidekiq::Worker
3+
4+
def perform
5+
limit = GitHub::Client.new.rate_limit
6+
logger.info("Github Ratelimit: #{limit}")
7+
8+
GitHub::PullRequests.new.fetch_and_save!
9+
GitHub::Issues.new.fetch_and_save!
10+
end
11+
end

config/initializers/sidekiq.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
require 'sidekiq'
2+
require 'sidekiq-cron'
3+
4+
schedule_file = 'config/job_schedule.yml'
25

36
Sidekiq.configure_server do |config|
47
# https://stackoverflow.com/questions/28412913/disable-automatic-retry-with-activejob-used-with-sidekiq
@@ -10,4 +13,6 @@
1013
}
1114
Rails.logger = Sidekiq::Logging.logger
1215
ActiveRecord::Base.logger = Sidekiq::Logging.logger
16+
17+
Sidekiq::Cron::Job.load_from_hash YAML.load_file(schedule_file) if File.exist?(schedule_file)
1318
end

config/job_schedule.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Examples of job configurations
2+
3+
#my_first_job:
4+
# cron: "*/5 * * * *"
5+
# class: "HardWorker"
6+
# queue: hard_worker
7+
#
8+
#second_job:
9+
# cron: "*/30 * * * *" # execute at every 30 minutes
10+
# class: "HardWorker"
11+
# queue: hard_worker_long
12+
# args:
13+
# hard: "stuff"
14+
15+
16+
# At 04:00 every day run the meetup member sync job
17+
meetup_member_sync_job:
18+
#cron: "0 4 * * *"
19+
cron: "0 0 5 31 2 ?" # only run Feb 31
20+
class: "MeetupMemberSyncJob"
21+
queue: "default"
22+
23+
# At 03:00 every day run the github collect statistics job
24+
github_collect_statistics_job:
25+
#cron: "0 3 * * *"
26+
cron: "0 0 5 31 2 ?" # only run Feb 31
27+
class: "GithubCollectStatisticsJob"
28+
queue: "default"

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
ActiveAdmin.routes(self)
55

66
require 'sidekiq/web'
7-
authenticate :admin_user, ->(u) { u.role.super_admin? } do
7+
require 'sidekiq/cron/web'
8+
authenticate :admin_user, ->(u) { u.role.admin_accessible? } do
89
mount Sidekiq::Web => '/admin/sidekiq'
910
end
1011

lib/tasks/git_hub.rake

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)