Skip to content

Commit

Permalink
Switched to resque because of process-based (not thread-based) parall…
Browse files Browse the repository at this point in the history
…el processing better fits OWL.
  • Loading branch information
Paweł Paprota committed Sep 30, 2013
1 parent 85198f8 commit 2733387
Show file tree
Hide file tree
Showing 22 changed files with 242 additions and 502 deletions.
10 changes: 7 additions & 3 deletions Gemfile
Expand Up @@ -36,9 +36,13 @@ gem 'pg'
gem 'ffi-geos'

gem 'sinatra', '>= 1.3.0', :require => nil
gem 'sidekiq'
gem 'sidekiq_status'
gem 'sidekiq_monitor'
#gem 'sidekiq'
#gem 'sidekiq_status'
#gem 'sidekiq_monitor'

gem 'resque'

gem 'twitter-bootstrap-rails'

# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
Expand Down
43 changes: 16 additions & 27 deletions Gemfile.lock
Expand Up @@ -25,20 +25,16 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
ajax-datatables-rails (0.0.1)
arel (4.0.0)
atomic (1.1.14)
builder (3.1.4)
celluloid (0.15.1)
timers (~> 1.1.0)
coffee-rails (4.0.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0.beta, < 5.0)
coffee-script (2.2.0)
coffee-script-source
execjs
coffee-script-source (1.6.3)
connection_pool (1.1.0)
erubis (2.7.0)
execjs (2.0.2)
ffi (1.9.0)
Expand All @@ -49,8 +45,6 @@ GEM
jbuilder (1.5.1)
activesupport (>= 3.0.0)
multi_json (>= 1.2.0)
jquery-datatables-rails (1.11.2)
jquery-rails
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
Expand All @@ -60,6 +54,7 @@ GEM
treetop (~> 1.4.8)
mime-types (1.25)
minitest (4.7.5)
mono_logger (1.1.0)
multi_json (1.8.0)
pg (0.17.0)
polyglot (0.3.3)
Expand Down Expand Up @@ -87,6 +82,12 @@ GEM
redis (3.0.4)
redis-namespace (1.3.1)
redis (~> 3.0.0)
resque (1.25.1)
mono_logger (~> 1.0)
multi_json (~> 1.0)
redis-namespace (~> 1.2)
sinatra (>= 0.9.2)
vegas (~> 0.1.2)
sass (3.2.11)
sass-rails (4.0.0)
railties (>= 4.0.0.beta, < 5.0)
Expand All @@ -95,26 +96,10 @@ GEM
sdoc (0.3.20)
json (>= 1.1.3)
rdoc (~> 3.10)
sidekiq (2.14.1)
celluloid (>= 0.14.1)
connection_pool (>= 1.0.0)
json
redis (>= 3.0.4)
redis-namespace (>= 1.3.1)
sidekiq_monitor (0.0.9)
ajax-datatables-rails
jquery-datatables-rails
sidekiq (>= 2.2.1)
slim
sidekiq_status (1.0.5)
sidekiq (>= 2.4, < 2.15)
sinatra (1.4.3)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slim (2.0.1)
temple (~> 0.6.6)
tilt (>= 1.3.3, < 2.1)
sprockets (2.10.0)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -125,21 +110,26 @@ GEM
activesupport (>= 3.0)
sprockets (~> 2.8)
sqlite3 (1.3.8)
temple (0.6.6)
thor (0.18.1)
thread_safe (0.1.3)
atomic
tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
turbolinks (1.3.0)
coffee-rails
twitter-bootstrap-rails (2.2.8)
actionpack (>= 3.1)
execjs
rails (>= 3.1)
railties (>= 3.1)
tzinfo (0.3.37)
uglifier (2.2.1)
execjs (>= 0.3.0)
multi_json (~> 1.0, >= 1.0.2)
vegas (0.1.11)
rack (>= 1.0.0)

PLATFORMS
ruby
Expand All @@ -151,12 +141,11 @@ DEPENDENCIES
jquery-rails
pg
rails (= 4.0.0)
resque
sass-rails (~> 4.0.0)
sdoc
sidekiq
sidekiq_monitor
sidekiq_status
sinatra (>= 1.3.0)
sqlite3
turbolinks
twitter-bootstrap-rails
uglifier (>= 1.3.0)
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -10,4 +10,6 @@
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require_tree .
3 changes: 3 additions & 0 deletions app/assets/javascripts/bootstrap.js.coffee
@@ -0,0 +1,3 @@
jQuery ->
$("a[rel~=popover], .has-popover").popover()
$("a[rel~=tooltip], .has-tooltip").tooltip()
1 change: 0 additions & 1 deletion app/assets/stylesheets/application.css
Expand Up @@ -8,7 +8,6 @@
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require leaflet
*= require_self
*= require_tree .
*/
Expand Down
7 changes: 7 additions & 0 deletions app/assets/stylesheets/bootstrap_and_overrides.css
@@ -0,0 +1,7 @@
/*
=require twitter-bootstrap-static/bootstrap
Use Font Awesome icons (default)
To use Glyphicons sprites instead of Font Awesome, replace with "require twitter-bootstrap-static/sprites"
=require twitter-bootstrap-static/fontawesome
*/
29 changes: 22 additions & 7 deletions app/controllers/admin_controller.rb
@@ -1,15 +1,30 @@
class AdminController < ActionController::Base
protect_from_forgery

def spawn_workers
#post_params[]
#TilerWorker.perform_async(params[:changeset_id])
sql = 'SELECT DISTINCT changeset_id AS id FROM nodes LIMIT 100'
def index
@person = {}
end

for row in ActiveRecord::Base.connection.execute(sql) do
TilerWorker.perform_async(row['id'].to_i)
def go
params[:ids].each_line do |line|
TilerWorker.perform_async(line.to_i)
end
render nothing: true
end

redirect_to '/admin'
def go_latest
sql = "SELECT DISTINCT changeset_id FROM ways w WHERE NOT EXISTS
(SELECT 1 FROM changeset_tiles WHERE changeset_id = w.changeset_id)
ORDER BY changeset_id DESC
LIMIT #{params[:limit]}"
go_from_sql(sql)
render nothing: true
end

def go_from_sql(sql)
for row in ActiveRecord::Base.connection.execute(sql) do
#TilerWorker.perform_async(row['changeset_id'].to_i)
Resque.enqueue(TilerWorker, row['changeset_id'].to_i)
end
end
end
24 changes: 24 additions & 0 deletions app/views/admin/index.html.erb
@@ -0,0 +1,24 @@
<div class="page-header"><h1>OWL</h1></div>
<%= form_tag("/admin/go", method: "post", :remote => true, :class => 'form-horizontal') do %>
<div class="control-group">
<%= label_tag(:ids, "changeset ids", :class => 'control-label') %>
<div class="controls">
<%= text_area_tag :ids %>
</div>
</div>
<div class="form-actions">
<%= submit_tag("Go", :class => 'btn btn-primary') %>
</div>
<% end %>
<%= form_tag("/admin/go_latest", method: "get", :remote => true, :class => 'form-horizontal') do %>
<div class="control-group">
<%= label_tag(:limit, "limit", :class => 'control-label') %>
<div class="controls">
<%= text_field_tag :limit, 100 %>
</div>
</div>
<div class="form-actions">
<%= submit_tag("Go", :class => 'btn btn-primary') %>
</div>
<% end %>
12 changes: 12 additions & 0 deletions app/views/admin/process.html.erb
@@ -0,0 +1,12 @@
<div class="page-header"><h1>asdasd</h1></div>
<%= form_tag("go", method: "post", :remote => true, :class => 'form-horizontal') do %>
<div class="control-group">
<%= label_tag(:ids, "changeset ids", :class => 'control-label') %>
<div class="controls">
<%= text_area_tag :ids %>
</div>
</div>
<div class="form-actions">
<%= submit_tag("Go", :class => 'btn btn-primary') %>
</div>
<% end %>
85 changes: 85 additions & 0 deletions app/views/layouts/admin.html.erb
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= content_for?(:title) ? yield(:title) : "Owl" %></title>
<%= csrf_meta_tags %>

<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
<![endif]-->

<%= stylesheet_link_tag "application", :media => "all" %>

<!-- For third-generation iPad with high-resolution Retina display: -->
<!-- Size should be 144 x 144 pixels -->
<%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %>

<!-- For iPhone with high-resolution Retina display: -->
<!-- Size should be 114 x 114 pixels -->
<%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %>

<!-- For first- and second-generation iPad: -->
<!-- Size should be 72 x 72 pixels -->
<%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %>

<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<!-- Size should be 57 x 57 pixels -->
<%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %>

<!-- For all other devices -->
<!-- Size should be 32 x 32 pixels -->
<%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %>
<%= javascript_include_tag "application" %>
</head>
<body>

<div class="navbar navbar-fluid-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-target=".nav-collapse" data-toggle="collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">OWL</a>
<div class="container-fluid nav-collapse">
<ul class="nav">
<!--<li><%= link_to "Link1", "/path1" %></li>
<li><%= link_to "Link2", "/path2" %></li>
<li><%= link_to "Link3", "/path3" %></li>-->
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>

<div class="container-fluid">
<div class="row-fluid">
<div class="span3">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Process changesets</li>
<!--<li><%= link_to "by ids", "/admin/process" %></li>
<li><%= link_to "latest", "/admin/go_latest" %></li>-->
</ul>
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<%= bootstrap_flash %>
<%= yield %>
</div>
</div><!--/row-->

<footer>
<p>&copy; Company 2013</p>
</footer>

</div> <!-- /container -->

</body>
</html>
10 changes: 0 additions & 10 deletions app/views/layouts/application.html.erb

This file was deleted.

14 changes: 2 additions & 12 deletions app/workers/tiler_worker.rb
@@ -1,16 +1,10 @@
class TilerWorker
include Sidekiq::Worker
#include SidekiqStatus::Worker
@queue = :tiler

sidekiq_options :retry => false

def initialize
def self.perform(changeset_id)
@conn = ActiveRecord::Base.connection.raw_connection()
@conn.set_error_verbosity(0)
@tiler = Tiler::ChangesetTiler.new(@conn)
end

def perform(changeset_id)
zoom = 16
before = Time.now
puts "Generating tiles for changeset #{changeset_id}..."
Expand All @@ -19,8 +13,4 @@ def perform(changeset_id)
puts "Changeset #{changeset_id} took #{Time.now - before}s"
{ tiles: tile_count }
end

def self.job_name(changeset_id)
changeset_id
end
end
18 changes: 18 additions & 0 deletions config/locales/en.bootstrap.yml
@@ -0,0 +1,18 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
helpers:
actions: "Actions"
links:
back: "Back"
cancel: "Cancel"
confirm: "Are you sure?"
destroy: "Delete"
new: "New"
edit: "Edit"
titles:
edit: "Edit %{model}"
save: "Save %{model}"
new: "New %{model}"
delete: "Delete %{model}"

0 comments on commit 2733387

Please sign in to comment.