Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Redis counters exposed on index view.

  • Loading branch information...
commit 82b1c7dad4c4ffe20a07a160e6e9690bd879ac1f 1 parent b7748b0
@wasabhi wasabhi authored
View
1  Gemfile
@@ -6,6 +6,7 @@ gem 'resque'
gem 'fog'
gem 'mini_magick'
gem 'thin'
+gem 'sinatra-redis'
group :development, :test do
gem 'pry'
View
4 Gemfile.lock
@@ -58,6 +58,9 @@ GEM
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
+ sinatra-redis (0.3.0)
+ redis
+ sinatra (>= 0.9.4)
slop (3.3.2)
subexec (0.2.2)
thin (1.4.1)
@@ -80,4 +83,5 @@ DEPENDENCIES
resque
rspec
sinatra
+ sinatra-redis
thin
View
15 lib/redis_keys.rb
@@ -0,0 +1,15 @@
+def s3_originals_key
+ "s3_originals"
+end
+
+def local_uploads_key
+ "local_uploads"
+end
+
+def s3_watermarked_key
+ "s3_watermarked"
+end
+
+def watermarked_url_list
+ "watermarked_urls"
+end
View
3  lib/watermark.rb
@@ -1,3 +1,5 @@
+require File.expand_path('../redis_keys', __FILE__)
+
class Watermark
attr_reader :originals_directory, :watermarked_directory, :connection, :original_file
@queue = :watermark
@@ -41,6 +43,7 @@ def apply_watermark
$stdout.flush
save_watermarked_file(watermarked_local_file)
+ redis.incr s3_watermarked_key
end
end
View
16 resque-example-app.rb
@@ -1,16 +1,30 @@
require 'bundler/setup'
Bundler.require(:default)
require File.expand_path('../lib/watermark', __FILE__)
+require File.expand_path('../lib/redis_keys', __FILE__)
+require 'sinatra/redis'
configure do
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
+ Resque.redis.namespace = "resque:example"
+ set :redis, ENV["REDISTOGO_URL"]
+end
+
+get "/" do
+ @local_uploads = redis.get local_uploads_key
+ @s3_originals = redis.get s3_originals_key
+ @s3_watermarked = redis.get s3_watermarked_key
+ @watermarked_urls = redis.lrange(watermarked_url_list, 0, 4)
+ @working = Resque.working
+ erb :index
end
post '/upload' do
unless params['file'][:tempfile].nil?
tmpfile = params['file'][:tempfile]
name = params['file'][:filename]
+ redis.incr local_uploads_key
file_token = send_to_s3(tmpfile, name)
Resque.enqueue(Watermark, file_token.key)
end
@@ -29,4 +43,6 @@ def send_to_s3(tmpfile, name)
:body => File.open(tmpfile),
:public => true
)
+ redis.incr s3_originals_key
+ file_token
end
View
14 views/index.erb
@@ -0,0 +1,14 @@
+<meta http-equiv="Refresh" content="3">
+<h1><a href="/resque">Resque Dashboard</a></h1>
+<h1><%= @local_uploads %> local uploads, <%= @s3_originals %> S3 originals, <%= @s3_watermarked %> watermarked.</h1>
+
+<% unless @working.length == 0 %>
+ <h2>Watermarking in progress...</h2>
+<% end %>
+
+<h2>Recently watermarked images</h2>
+<ul>
+ <% @watermarked_urls.each do |url| %>
+ <li><a href="<%= url %>"><%= url %></a></li>
+ <% end %>
+</ul>
Please sign in to comment.
Something went wrong with that request. Please try again.