Permalink
Browse files

Added more fields to the row to denormalize a bit and make it easier …

…to run analytics over the items in the row.
  • Loading branch information...
1 parent 9679027 commit 8afeb5ecd7b5a4727d92840cddbb4ee7dec2c170 @PatrickTulskie committed Jul 28, 2009
Showing with 16 additions and 6 deletions.
  1. +3 −0 generators/delayed_job/templates/migration.rb
  2. +13 −6 lib/delayed/job.rb
@@ -12,6 +12,9 @@ def self.up
t.datetime :first_started_at # Needed for task tracking
t.datetime :last_started_at # Needed for task tracking
t.datetime :finished_at # Needed for when you are not deleting items from the table on completion
+ t.float :completion_time # Time in seconds that it took for the job to complete
+ t.float :time_in_queue # Time in seconds that the item sat in queue
+ t.string :completed_by # The name of the worker that completed the job
t.timestamps
end
View
@@ -96,14 +96,21 @@ def run_with_lock(max_run_time, worker_name)
end
begin
- runtime = Benchmark.realtime do
- now = Time.now
- update_attribute(:first_started_at, now) if first_started_at.nil?
- update_attribute(:last_started_at, now)
+ begin_time = Time.now
+ runtime = Benchmark.realtime do
+ update_attribute(:first_started_at, begin_time) if first_started_at.nil?
+ update_attribute(:last_started_at, begin_time)
+ update_attribute(:time_in_queue, begin_time - created_at )
invoke_job # TODO: raise error if takes longer than max_run_time
end
- destroy_successful_jobs ? destroy :
- update_attribute(:finished_at, Time.now)
+ if destroy_successful_jobs
+ destroy
+ else
+ end_time = Time.now
+ update_attribute(:finished_at, end_time)
+ update_attribute(:completion_time, ( end_time - begin_time ))
+ update_attribute(:completed_by, worker_name)
+ end
# TODO: warn if runtime > max_run_time ?
logger.info "* [JOB] #{name} completed after %.4f" % runtime
return true # did work

0 comments on commit 8afeb5e

Please sign in to comment.