tweaking things a bit to add a basic batch worker using sidekiq

master
Thomas Riboulet 6 years ago
parent 7d49e80dba
commit c716d7cf27

@ -9,4 +9,4 @@ ADD . /var/app
RUN cd /var/app; bundle install
CMD ["/usr/local/bin/foreman","run", "web","-d","/var/app"]
CMD ["./var/app/bin/http"]

@ -2,3 +2,4 @@ source 'https://rubygems.org'
gem 'sinatra'
gem 'haml'
gem 'puma'
gem 'sidekiq'

@ -1,34 +1,26 @@
GEM
remote: https://rubygems.org/
specs:
celluloid (0.16.0)
timers (~> 4.0.0)
connection_pool (2.1.2)
concurrent-ruby (1.0.5)
connection_pool (2.2.1)
haml (4.0.5)
tilt
hitimes (1.2.2)
json (1.8.2)
puma (2.11.1)
rack (>= 1.1, < 2.0)
rack (1.5.2)
rack-protection (1.5.2)
rack
redis (3.2.1)
redis-namespace (1.5.1)
redis (~> 3.0, >= 3.0.4)
sidekiq (3.3.2)
celluloid (>= 0.16.0)
connection_pool (>= 2.1.1)
json
redis (>= 3.0.6)
redis-namespace (>= 1.3.1)
redis (4.0.1)
sidekiq (5.0.5)
concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0)
rack-protection (>= 1.5.0)
redis (>= 3.3.4, < 5)
sinatra (1.4.4)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
tilt (1.4.1)
timers (4.0.1)
hitimes
PLATFORMS
ruby
@ -36,6 +28,8 @@ PLATFORMS
DEPENDENCIES
haml
puma
redis
sidekiq
sinatra
BUNDLED WITH
1.16.0

@ -0,0 +1,6 @@
#!/bin/sh
CONCURRENCY_LEVEL=${CONCURRENCY:-1}
echo "Concurrency set to : ${CONCURRENCY_LEVEL}"
echo ""
bundle exec sidekiq -r ./worker.rb -c $CONCURRENCY_LEVEL

@ -0,0 +1,3 @@
#!/bin/sh
echo "the port is : ${PORT}"
bundle exec puma -t 5:5 -p ${PORT:-8080} -e ${RACK_ENV:-development}

@ -1,12 +1,26 @@
require 'sinatra'
require 'sidekiq'
require 'redis'
require 'sidekiq/api'
require 'haml'
$redis = Redis.new
class SimpleApp < Sinatra::Base
get '/' do
SinatraWorker.perform_async(msg="beanstalk was pulled")
haml "%h3 Hello THE BEANSTALK AWESOME World!"
end
get '/stats' do
stats = Sidekiq::Stats.new
@failed = stats.failed
@processed = stats.processed
@messages = $redis.lrange('sinkiq-example-messages', 0, -1)
erb :index
end
get '/mu-c9478619-b3ea1fef-e218a7ee-09081759' do
'42'
end

@ -0,0 +1,15 @@
<h1>Sinatra + Sidekiq Example</h1>
<h2>Failed: <%= @failed %></h2>
<h2>Processed: <%= @processed %></h2>
<form method="post" action="/msg">
<input type="text" name="msg">
<input type="submit" value="Add Message">
</form>
<a href="/">Refresh page</a>
<h3>Messages</h3>
<% @messages.each do |msg| %>
<p><%= msg %></p>
<% end %>

@ -0,0 +1,15 @@
require 'sinatra'
require 'sidekiq'
require 'redis'
require 'sidekiq/api'
$redis = Redis.new
class SinatraWorker
include Sidekiq::Worker
def perform(msg="lulz you forgot a msg!")
sleep 2 + rand(10)
$redis.lpush("sinkiq-example-messages", msg)
end
end
Loading…
Cancel
Save