This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#7398) Use DelayedJob for background processing.
Delayed_Job is a gem that implements robust background processing for Ruby tasks. Now we have vendored it, we can start to use it to process report import in the background. This has two advantages: one, we can import in parallel, since we can have more than one worker in the background working on the YAML transformation and database updating. Two, we now return to the report submitter in short order: all we have to do is spool the YAML to disk, and register the background job, and we are assured that we will eventually get that into the database. This eliminates a lot of the master => dashboard submission pipeline delay, so that the master gets back to serving clients immediately, rather than having to wait until the report is entirely ingested. Reviewed-By: Daniel Pittman <[email protected]> Reviewed-By: Matt Robinson <[email protected]>
- Loading branch information
Pieter van de Bruggen
authored and
Daniel Pittman
committed
Jun 17, 2011
1 parent
6aefc60
commit 58c2b52
Showing
6 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
DELAYED_JOB_PID_PATH = "#{Rails.root}/tmp/pids/delayed_job.pid" | ||
|
||
Delayed::Worker.destroy_failed_jobs = false | ||
Delayed::Worker.max_attempts = 3 | ||
|
||
def start_delayed_job | ||
Thread.new do | ||
`#{Rails.root}/script/delayed_job -p dashboard -m start` | ||
end | ||
end | ||
|
||
def process_is_dead? | ||
begin | ||
pid = File.read(DELAYED_JOB_PID_PATH).strip | ||
Process.kill(0, pid.to_i) | ||
false | ||
rescue | ||
true | ||
end | ||
end | ||
|
||
if !File.exist?(DELAYED_JOB_PID_PATH) && process_is_dead? | ||
start_delayed_job | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class CreateDelayedJobs < ActiveRecord::Migration | ||
def self.up | ||
create_table :delayed_jobs, :force => true do |table| | ||
# Allows some jobs to jump to the front of the queue | ||
table.integer :priority, :default => 0 | ||
# Provides for retries, but still fail eventually. | ||
table.integer :attempts, :default => 0 | ||
# YAML-encoded string of the object that will do work | ||
table.text :handler, :limit => 16.megabytes | ||
# reason for last failure (See Note below) | ||
table.text :last_error | ||
# When to run. Could be Time.zone.now for immediately, or sometime in | ||
# the future. | ||
table.datetime :run_at | ||
# Set when a client is working on this object | ||
table.datetime :locked_at | ||
# Set when all retries have failed (actually, by default, the record is | ||
# deleted instead) | ||
table.datetime :failed_at | ||
# Who is working on this object (if locked) | ||
table.string :locked_by | ||
table.timestamps | ||
end | ||
|
||
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' | ||
end | ||
|
||
def self.down | ||
drop_table :delayed_jobs | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) | ||
require 'delayed/command' | ||
Delayed::Command.new(ARGV).daemonize |