moved examples and added an example of sinatra running sidekiq to view the paste jobs easier in a web ui without needing all of rails

This commit is contained in:
booboy 2019-02-06 00:21:56 -06:00
parent c80bd01875
commit 9b0e11bcd9
7 changed files with 64 additions and 2 deletions

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
require '../pastebinner'
require '../lib/pastebinner'
######################## TESTING ####################################################
#####################################################################################

61
examples/sinkiq.rb Normal file
View file

@ -0,0 +1,61 @@
# 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'
require 'redis'
require 'sidekiq/api'
$redis = Redis.new
class SinatraWorker
include Sidekiq::Worker
def perform(msg="lulz you forgot a msg!")
$redis.lpush("sinkiq-example-messages", msg)
end
end
get '/' do
stats = Sidekiq::Stats.new
@failed = stats.failed
@processed = stats.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>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 %>

View file

@ -37,5 +37,6 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'pry', '~> 0.11'
spec.add_runtime_dependency 'rest-client', '~> 2.0'
spec.add_runtime_dependency 'sidekiq', '~> 5.2.5'
spec_add_runtime_dependency 'redis', '~> 4.1.0'
spec.add_runtime_dependency 'redis', '~> 4.1.0'
spec.add_runtime_dependency 'sinatra', '~> 2.0.5'
end