Permalink
Browse files

Made the call to Matterhorn asynchronous so Hydrant doesn't have to wait

  • Loading branch information...
1 parent 3be9328 commit e1fbd6b395b2bfd1363c0e065b2ff9aec70d2019 @phuongdh phuongdh committed Nov 9, 2012
View
@@ -52,6 +52,7 @@
gem 'daemons'
gem 'guard'
gem 'guard-hydrant', :git => 'git://github.com/variations-on-video/guard-hydrant'
+ gem 'delayed_job_active_record'
group :assets, :production do
gem 'coffee-rails', "~> 3.2.1"
@@ -91,8 +91,8 @@ def create
def update
@masterfile = MasterFile.find(params[:id])
if params[:workflow_id].present?
- puts "Matterhorn called!"
- @masterfile.updateProgress
+ logger.debug "Matterhorn called!"
+ @masterfile.updateProgress params[:workflow_id]
else
@mediaobject = @masterfile.container
authorize! :edit, @mediaobject
@@ -91,8 +91,8 @@ def status_description
end
end
- def updateProgress
- matterhorn_response = Rubyhorn.client.instance_xml(self.workflow_id)
+ def updateProgress workflow_id
+ matterhorn_response = Rubyhorn.client.instance_xml(workflow_id)
self.percent_complete = calculate_percent_complete(matterhorn_response)
self.status_code = matterhorn_response.workflow.state[0]
@@ -146,6 +146,8 @@ def sendToMatterhorn
self.workflow_id = workflow_doc.workflow.id[0]
end
+ handle_asynchronously :sendToMatterhorn
+
def saveOriginal(file, original_name)
realpath = File.realpath(file.path)
if !original_name.nil?
@@ -0,0 +1,22 @@
+class CreateDelayedJobs < ActiveRecord::Migration
+ def self.up
+ create_table :delayed_jobs, :force => true do |table|
+ table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue
+ table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually.
+ table.text :handler # YAML-encoded string of the object that will do work
+ table.text :last_error # reason for last failure (See Note below)
+ table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
+ table.datetime :locked_at # Set when a client is working on this object
+ table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
+ table.string :locked_by # Who is working on this object (if locked)
+ table.string :queue # The name of the queue this job is in
+ table.timestamps
+ end
+
+ add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
+ end
+
+ def self.down
+ drop_table :delayed_jobs
+ end
+end
View
@@ -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

0 comments on commit e1fbd6b

Please sign in to comment.