Skip to content

Commit

Permalink
Implemented [delayed_jobs] zafu method to list current jobs in the qu…
Browse files Browse the repository at this point in the history
…eue.
  • Loading branch information
gaspard committed Mar 21, 2011
1 parent 5a4baa0 commit a56154d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 1 deletion.
37 changes: 37 additions & 0 deletions bricks/worker/lib/bricks/worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Bricks
module Worker
class Job < ActiveRecord::Base
include RubyLess
set_table_name :delayed_jobs

safe_method :run_at => Time, :created_at => Time
safe_method :info => String

def info
obj = YAML.load(self[:handler])
if obj.respond_to?(:info)
obj.info
else
obj.inspect
end
end
end # Job

module ViewMethods
include RubyLess

safe_method :delayed_jobs => [Job]

def delayed_jobs
Bricks::Worker::Job.find(:all,
# FIXME: find a way to add site_id to delayed_jobs...
#:conditions => ['site_id = ?', current_site.id],
:order => 'run_at ASC'
)
end
end # ViewMethods
end # Worker
end

# Make sure the class is loaded before first YAML.load
Zena::SiteWorker
1 change: 1 addition & 0 deletions bricks/worker/zena/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
Delayed::Job.const_set("MAX_RUN_TIME", 5.minutes)
end

Zena::Use.module Bricks::Worker
16 changes: 16 additions & 0 deletions bricks/worker/zena/test/sites/zena/delayed_jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
zena_index:
run_at: 2011-03-21 10:41
handler: |
--- !ruby/struct:Zena::SiteWorker
site_id: 705790410
action: :rebuild_index
page: 1
ocean_vhash:
run_at: 2011-03-21 10:05
handler: |
--- !ruby/struct:Zena::SiteWorker
site_id: 740511775
action: :rebuild_vhash
page: 1
8 changes: 8 additions & 0 deletions bricks/worker/zena/test/zafu/worker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# test_file: ../../../../test/integration/zafu_compiler_test.rb
default:
context:
node: 'status'
visitor: 'anon'
src: "<r:delayed_jobs do='each' join=', '>[<r:run_at format='%Y-%m-%d %H:%M'/> <r:info/>]</r:delayed_jobs>"
tem: "/delayed_jobs/"
res: "[2011-03-21 10:05 -], [2011-03-21 10:41 rebuild_index, page 1/1]"
2 changes: 1 addition & 1 deletion config/bricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test:
tags: ON
captcha: ON
sphinx: OFF
worker: OFF
worker: ON

development:
asset_port: 7999
Expand Down
10 changes: 10 additions & 0 deletions lib/zena/site_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,15 @@ def get_nodes
def page_count
(Node.count(:conditions => ['site_id = ?', site_id]) / CHUNK_SIZE) + 1
end

# Return a textual description of the operation.
def info
if site_id == current_site.id
"#{action}, #{_('page')} #{page}/#{page_count}"
else
# Do not show jobs from other sites
"-"
end
end
end
end # Zena
1 change: 1 addition & 0 deletions test/integration/zafu_compiler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ZafuCompilerTest < Zena::Controller::TestCase
'search',
'site',
'tags', # bricks/tags/zena/test/zafu
'worker', # bricks/worker/zena/test/zafu
'urls',
'user',
'version',
Expand Down

0 comments on commit a56154d

Please sign in to comment.