Skip to content

Commit

Permalink
Revert "Revert "Reinstall Sidekiq""
Browse files Browse the repository at this point in the history
  • Loading branch information
hebron-george authored Sep 2, 2024
1 parent f857f68 commit a811bbf
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ ENTRYPOINT ["/rails/bin/docker-entrypoint"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000

# Default command for web server, can be overridden by docker-compose
CMD ["./bin/rails", "server"]

# Uncomment the following line if you want to run Sidekiq by default
CMD ["bundle", "exec", "sidekiq", "-C", "config/sidekiq.yml"]
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ gem "slim-rails", "~> 3.6"

# Error tracking
gem "honeybadger", "~> 5.15"

# Background jobs
gem 'sidekiq'
gem 'sidekiq-cron'
gem "redis", "~> 5.2"
25 changes: 25 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ GEM
execjs
coffee-script-source (1.12.2)
concurrent-ruby (1.3.1)
connection_pool (2.4.1)
crass (1.0.6)
date (3.3.4)
diff-lcs (1.5.0)
Expand All @@ -85,6 +86,8 @@ GEM
dotenv (= 2.8.1)
railties (>= 3.2)
erubi (1.12.0)
et-orbi (1.2.11)
tzinfo
execjs (2.8.1)
faraday (2.7.4)
faraday-net_http (>= 2.0, < 3.1)
Expand All @@ -96,6 +99,9 @@ GEM
multipart-post (~> 2)
faraday-net_http (3.0.2)
ffi (1.15.5)
fugit (1.11.1)
et-orbi (~> 1, >= 1.2.11)
raabro (~> 1.4)
gli (2.21.0)
globalid (1.2.1)
activesupport (>= 6.1)
Expand All @@ -111,6 +117,7 @@ GEM
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
logger (1.6.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand Down Expand Up @@ -149,6 +156,7 @@ GEM
pry (>= 0.10.4)
puma (5.6.8)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.8.0)
rack (2.2.9)
rack-cors (2.0.0)
Expand Down Expand Up @@ -187,6 +195,10 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.2)
connection_pool
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
Expand Down Expand Up @@ -219,6 +231,16 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
sidekiq (7.3.1)
concurrent-ruby (< 2)
connection_pool (>= 2.3.0)
logger
rack (>= 2.2.4)
redis-client (>= 0.22.2)
sidekiq-cron (1.12.0)
fugit (~> 1.8)
globalid (>= 1.0.1)
sidekiq (>= 6)
slack-ruby-client (2.0.0)
faraday (>= 2.0)
faraday-mashify
Expand Down Expand Up @@ -290,9 +312,12 @@ DEPENDENCIES
puma (~> 5.6.8)
rack-cors
rails (~> 6.1)
redis (~> 5.2)
rspec
rspec-rails (~> 4.0.0)
sass-rails (~> 6.0.0)
sidekiq
sidekiq-cron
slack-ruby-client
slim-rails (~> 3.6)
spring
Expand Down
7 changes: 7 additions & 0 deletions app/workers/daily_snapshot_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class DailySnapshotWorker
include Sidekiq::Worker

def perform
PlaylistSnapshot.capture_all_tracked_playlists!
end
end
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Application < Rails::Application
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.

config.time_zone = "Eastern Time (US & Canada)"

# Don't generate system test files.
config.generators.system_tests = nil

Expand Down
10 changes: 10 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require 'sidekiq-cron'

schedule_file = "config/schedule.yml"

if File.exist?(schedule_file) && Sidekiq.server?
schedule = YAML.load_file(schedule_file)
Sidekiq::Cron::Job.load_from_hash(schedule)
end
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require 'sidekiq/web'
require 'sidekiq/cron/web'

Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
mount Sidekiq::Web => '/sidekiq'

post '/shuffle', to: 'playlists#shuffle'
get '/tracked-playlists', to: 'tracked_playlists#index'
Expand Down
3 changes: 3 additions & 0 deletions config/schedule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
daily_snapshots:
cron: "0 10 * * *" # Runs at 10am daily
class: "DailySnapshotWorker"
3 changes: 3 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:concurrency: 5
:queues:
- default

0 comments on commit a811bbf

Please sign in to comment.