Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer sidekiq-cron over the whenever gem #1893

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ FROM ruby:2.4
# Cleanup expired Let's Encrypt CA (Sept 30, 2021)
RUN sed -i '/^mozilla\/DST_Root_CA_X3/s/^/!/' /etc/ca-certificates.conf && update-ca-certificates -f

RUN apt-get update && \
apt-get install -y cron && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Create a user for the web app.
RUN addgroup --gid 9999 app && \
adduser --uid 9999 --gid 9999 --disabled-password --gecos "Application" app && \
Expand All @@ -19,9 +15,11 @@ WORKDIR /app
# Configuration
ARG gemfile=Gemfile
ENV BUNDLE_GEMFILE=${gemfile}
ENV PUMA_OPTIONS "--preload -w 4 -p 3000"
ENV NNDD_VERSION "cdx-0.11-pre7"
ENV PUMA_OPTIONS="--preload -w 4 -p 3000"
ENV NNDD_VERSION="cdx-0.11-pre7"
ENV RAILS_ENV=production
ENV RAILS_LOG_TO_STDOUT=true
ENV RAILS_SERVE_STATIC_FILES=true

# Install gem bundle
COPY Gemfile* cdx.gemspec cdx-api-elasticsearch.gemspec /app/
Expand All @@ -45,4 +43,4 @@ RUN /app/docker/config-nndd
RUN mkdir -p /app/tmp /app/log && chown -R app:app /app/tmp /app/log

EXPOSE 3000
CMD ["/app/docker/web-run"]
CMD bundle exec puma $PUMA_OPTIONS -e $RAILS_ENV
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ gem 'geojson_import', git: 'https://github.com/instedd/geojson_import', branch:
# Services
gem 'puma', '~> 3.0'
gem 'sidekiq', '~> 4.2'
gem 'sidekiq-cron', '~> 0.3' # TODO: not maintained, consider sidekiq-scheduler instead
gem 'whenever', '~> 1.0' # TODO: replace with a sidekiq-cron job
gem 'sidekiq-cron'

# External services
gem 'location_service', git: 'https://github.com/instedd/ruby-location_service.git', branch: 'master'
Expand Down
18 changes: 6 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ GEM
capybara (>= 1.0, < 4)
launchy
childprocess (3.0.0)
chronic (0.10.2)
chunky_png (1.4.0)
climate_control (0.2.0)
cocaine (0.5.8)
Expand All @@ -137,7 +136,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.0)
config (1.7.2)
activesupport (>= 3.0)
deep_merge (~> 1.2, >= 1.2.1)
Expand Down Expand Up @@ -250,7 +249,7 @@ GEM
ffi (1.15.5)
filewatcher (0.3.6)
trollop (~> 2.0)
fugit (1.8.0)
fugit (1.8.1)
et-orbi (~> 1, >= 1.2.7)
raabro (~> 1.4)
gherkin (5.1.0)
Expand Down Expand Up @@ -482,8 +481,6 @@ GEM
ruby_parser (3.19.2)
sexp_processor (~> 4.16)
rubyzip (2.3.2)
rufus-scheduler (3.8.2)
fugit (~> 1.1, >= 1.1.6)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
Expand All @@ -506,8 +503,8 @@ GEM
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (~> 3.2, >= 3.2.1)
sidekiq-cron (0.6.3)
rufus-scheduler (>= 3.3.0)
sidekiq-cron (1.2.0)
fugit (~> 1.1)
sidekiq (>= 4.2.1)
simplecov (0.18.5)
docile (~> 1.1)
Expand Down Expand Up @@ -541,7 +538,7 @@ GEM
ttfunk (1.6.2.1)
turbolinks (2.5.4)
coffee-rails
tzinfo (1.2.10)
tzinfo (1.2.11)
thread_safe (~> 0.1)
uglifier (2.7.2)
execjs (>= 0.3.0)
Expand All @@ -563,8 +560,6 @@ GEM
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
whenever (1.0.0)
chronic (>= 0.6.3)
xpath (3.2.0)
nokogiri (~> 1.8)

Expand Down Expand Up @@ -645,7 +640,7 @@ DEPENDENCIES
selenium-webdriver (< 4.0)
sentry-raven (~> 2.13)
sidekiq (~> 4.2)
sidekiq-cron (~> 0.3)
sidekiq-cron
simplecov
site_prism (~> 3.0)
spring
Expand All @@ -659,7 +654,6 @@ DEPENDENCIES
view_components!
web-console (< 4.0)
webmock (~> 2.3.1)
whenever (~> 1.0)

BUNDLED WITH
1.17.3
10 changes: 10 additions & 0 deletions app/jobs/cleanup_assay_files_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CleanupAssayFilesJob
include Sidekiq::Worker

# Delete AssayFile that don't have any AssayAttachment (parent model) associated.
def perform
AssayFile
.where("created_at > ? AND assay_attachment_id IS NULL", 7.days.ago)
.find_each(&:destroy)
end
end
5 changes: 0 additions & 5 deletions app/jobs/daily_alert_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ def perform
alert_history_check(1.day, Alert.aggregation_frequencies["day"])
end
end

# note: an alternative gem for scheduling cron jobs could be: http://github.com/javan/whenever but
# the advantage of gem "sidekiq-cron" is that it appears in the sidekiq web url , http://localhost:3000/sidekiq/cron

Sidekiq::Cron::Job.create(name: 'Alert Daily - daily 12:15am', cron: '15 0 * * *', klass: 'DailyAlertJob') #run daily at 15 after midnight
15 changes: 7 additions & 8 deletions app/jobs/daily_demo_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
class DailyDemoData
include Sidekiq::Worker

#just paste here, we can move this value into an env setting once we start to use this tool
#just paste here, we can move this value into an env setting once we start to use this tool
def get_repeat_demo_per_device
1000
end

##
# Note: it is assumed that rake db:ssed has been called to load the seeds data generated.
#
# if say 1000 daily testresults are needed per device, then loop over the device templates (only two templates at the moment)
def perform
insert_demo_data(get_repeat_demo_per_device)
def perform
insert_demo_data(get_repeat_demo_per_device)
end

end

# note: an alternative gem for scheduling cron jobs could be: http://github.com/javan/whenever but
# the advantage of gem "sidekiq-cron" is that it appears in the sidekiq web url , http://localhost:3000/sidekiq/cron
if use_demo_data?
Sidekiq::Cron::Job.create(name: 'Demo Data - daily 12:15am', cron: '15 0 * * *', klass: 'DailyDemoData') #run daily at 15 after midnight
# run daily at 15 after midnight
Sidekiq::Cron::Job.create(name: 'Demo Data - daily 12:15am', cron: '15 0 * * *', klass: 'DailyDemoData')
end
8 changes: 0 additions & 8 deletions app/jobs/hourly_alert_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,3 @@ def perform
alert_history_check(1.hour, Alert.aggregation_frequencies["hour"])
end
end

# note: an alternative gem for scheduling cron jobs could be: http://github.com/javan/whenever but
# the advantage of gem "sidekiq-cron" is that it appears in the sidekiq web url , http://localhost:3000/sidekiq/cron

Sidekiq::Cron::Job.create(name: 'Alert Hourly - hourly', cron: '0 * * * *', klass: 'HourlyAlertJob') #run each hour

#for test run every 5 mins:
#Sidekiq::Cron::Job.create(name: 'Alert Hourly - 10mins 12:15am', cron: '*/10 * * * *', klass: 'HourlyAlertJob') #run daily at 15 after midnight
13 changes: 3 additions & 10 deletions app/jobs/hourly_utilization_efficiency_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def perform
#convert the aggregation [days or hours] into hours for calculations
hours_per_day = 24
if alert.aggregation_frequency == "month"
utilization_efficiency_hours = amount * hours_per_day * 30
utilization_efficiency_hours = amount * hours_per_day * 30
elsif alert.aggregation_frequency == "week"
utilization_efficiency_hours = amount * hours_per_day * 7
utilization_efficiency_hours = amount * hours_per_day * 7
elsif alert.aggregation_frequency == "day"
utilization_efficiency_hours = amount * hours_per_day
utilization_efficiency_hours = amount * hours_per_day
else
utilization_efficiency_hours = amount
end
Expand All @@ -51,10 +51,3 @@ def perform
end
end
end

#run every 30 mins to give more accuracy, +/- 30 mins
Sidekiq::Cron::Job.create(name: 'Alert Utilization Efficiency - hourly', cron: '*/30 * * * *', klass: 'HourlyUtilizationEfficiencyJob')


#every 2 minsutes for testing
#Sidekiq::Cron::Job.create(name: 'Alert Utilization Efficiency - hourly', cron: '*/2 * * * *', klass: 'HourlyUtilizationEfficiencyJob')
4 changes: 0 additions & 4 deletions app/jobs/monthly_alert_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ def perform
alert_history_check(1.month, Alert.aggregation_frequencies["month"])
end
end

Sidekiq::Cron::Job.create(name: 'Alert Monthly - daily 12:15am', cron: '35 0 * * *', klass: 'MonthlyAlertJob') #run daily at 35 after midnight

#Sidekiq::Cron::Job.create(name: 'Alert Monthly - 10mins 12:15am', cron: '*/5 * * * *', klass: 'MonthlyAlertJob')
3 changes: 0 additions & 3 deletions app/jobs/weekly_alert_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ def perform
alert_history_check(1.week, Alert.aggregation_frequencies["week"])
end
end

Sidekiq::Cron::Job.create(name: 'Alert Weekly - daily 12:15am', cron: '25 0 * * *', klass: 'WeekyAlertJob') #run daily at 25 after midnight

26 changes: 26 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Sidekiq.configure_server do |config|
config.on(:startup) do
# run daily at 15 after midnight
Sidekiq::Cron::Job.create(name: 'Alert Daily - daily 12:15am', cron: '15 0 * * *', klass: 'DailyAlertJob')

# run daily at 25 after midnight
Sidekiq::Cron::Job.create(name: 'Alert Weekly - daily 12:15am', cron: '25 0 * * *', klass: 'WeekyAlertJob')

# run daily at 35 after midnight
Sidekiq::Cron::Job.create(name: 'Alert Monthly - daily 12:15am', cron: '35 0 * * *', klass: 'MonthlyAlertJob')

# run hourly
Sidekiq::Cron::Job.create(name: 'Alert Hourly - hourly', cron: '0 * * * *', klass: 'HourlyAlertJob')

# run every 30 mins to give more accuracy, +/- 30 mins
Sidekiq::Cron::Job.create(name: 'Alert Utilization Efficiency - hourly', cron: '*/30 * * * *', klass: 'HourlyUtilizationEfficiencyJob')

# for manual tests (run every some 2, 5 or 10 mins):
# Sidekiq::Cron::Job.create(name: 'Alert Utilization Efficiency - hourly', cron: '*/2 * * * *', klass: 'HourlyUtilizationEfficiencyJob')
# Sidekiq::Cron::Job.create(name: 'Alert Monthly - 10mins 12:15am', cron: '*/5 * * * *', klass: 'MonthlyAlertJob')
# Sidekiq::Cron::Job.create(name: 'Alert Hourly - 10mins 12:15am', cron: '*/10 * * * *', klass: 'HourlyAlertJob')

# run daily at 02:00am
Sidekiq::Cron::Job.create(name: 'Cleanup unused AssayFile', cron: '0 2 * * *', klass: 'CleanupAssayFilesJob')
end
end
16 changes: 0 additions & 16 deletions config/schedule.rb

This file was deleted.

4 changes: 0 additions & 4 deletions docker/web-run

This file was deleted.

7 changes: 0 additions & 7 deletions lib/tasks/assay_files.rake

This file was deleted.