mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
Merge branch 'master' of github.com:mperham/sidekiq
This commit is contained in:
commit
4c7ae756c8
3 changed files with 75 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ tags
|
|||
Gemfile.lock
|
||||
*.swp
|
||||
dump.rdb
|
||||
.rbx
|
||||
|
|
17
examples/por.rb
Normal file
17
examples/por.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require 'sidekiq'
|
||||
|
||||
# Start up sidekiq via
|
||||
# ./bin/sidekiq -r ./examples/por.rb
|
||||
# and then you can open up an IRB session like so:
|
||||
# irb -r ./examples/por.rb
|
||||
# where you can then say
|
||||
# PlainOldRuby.perform_async "like a dog", 3
|
||||
#
|
||||
class PlainOldRuby
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(how_hard="super hard", how_long=1)
|
||||
sleep how_long
|
||||
puts "Workin' #{how_hard}"
|
||||
end
|
||||
end
|
57
examples/sinkiq.rb
Normal file
57
examples/sinkiq.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
# Make sure you have Sinatra installed, then start sidekiq with
|
||||
# ./bin/sidekiq -r ./examples/sinkiq.rb
|
||||
# Simply run Sinatra with
|
||||
# ruby examples/sinkiq.rb
|
||||
# and then browse to http://localhost:4567
|
||||
#
|
||||
require 'sinatra'
|
||||
require 'sidekiq/worker'
|
||||
$redis = Sidekiq::RedisConnection.create
|
||||
|
||||
class SinatraWorker
|
||||
include Sidekiq::Worker
|
||||
|
||||
def perform(msg="lulz you forgot a msg!")
|
||||
$redis.lpush("sinkiq-example-messages", msg)
|
||||
end
|
||||
end
|
||||
|
||||
get '/' do
|
||||
@failed = $redis.get('stat:failed')
|
||||
@processed = $redis.get('stat:processed')
|
||||
@messages = $redis.lrange('sinkiq-example-messages', 0, -1)
|
||||
erb :index
|
||||
end
|
||||
|
||||
post '/msg' do
|
||||
SinatraWorker.perform_async params[:msg]
|
||||
redirect to('/')
|
||||
end
|
||||
|
||||
__END__
|
||||
|
||||
@@ layout
|
||||
<html>
|
||||
<head>
|
||||
<title>Sinatra + Sidekiq</title>
|
||||
<body>
|
||||
<%= yield %>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ index
|
||||
<h1>Sinata + 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 %>
|
Loading…
Add table
Add a link
Reference in a new issue