Permalink
Browse files

some simple job logging

  • Loading branch information...
1 parent a3d248f commit 77dab5a9232506138d9c5090a8c7826227414b6a @adamwiggins adamwiggins committed Mar 26, 2010
Showing with 14 additions and 1 deletion.
  1. +1 −1 examples/jobs.rb
  2. +13 −0 lib/stalker.rb
View
@@ -5,7 +5,7 @@
priority :high do
job 'send.email' do |args|
- puts "Sending email: #{args.inspect}"
+ puts "Sending email to args['email']"
end
job 'transform.image' do |args|
View
@@ -42,6 +42,7 @@ class NoSuchJob < RuntimeError; end
def work_one_job
job = beanstalk.reserve
name, args = JSON.parse job.body
+ log_job(name, args)
handler = @@handlers[name]
raise(NoSuchJob, name) unless handler
handler.call(args)
@@ -51,6 +52,18 @@ def work_one_job
job.bury
end
+ def log_job(name, args)
+ args_flat = args.inject("") do |accum, (key,value)|
+ accum += "#{key}=#{value} "
+ end
+
+ log sprintf("%-15s :: #{args_flat}", name)
+ end
+
+ def log(msg)
+ puts "[#{Time.now}] #{msg}"
+ end
+
def jobs(priorities=['all'])
jobs = []
@@priorities.each do |job, priority|

0 comments on commit 77dab5a

Please sign in to comment.