Jak odwołać się do aktywnego opóźnionego_obsługi w ramach rzeczywistej pracy
Pracuję nad rozwiązaniem, aby wyświetlić procent ukończenia opóźnionego zadania (przy użyciu klejnotu opóźnionego_obsługi). Obecnie mam migrację bazy danych, która wygląda następująco dla mojej tabeli delayed_jobs:
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.integer :progress
table.timestamps
end
add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority'
end
def self.down
drop_table :delayed_jobs
end
end
Używam procesu enqueue w metodzie kontrolera dla opóźnionego zadania, a odwołanie do klasy w lib / build_detail.rb:
Delayed::Job.enqueue(BuildDetail.new(@object, @com))
Plik lib / build_detail.rb jest następujący:
class BuildDetail < Struct.new(:object, :com)
def perform
total_count = object.person_ids.length
progress_count = 0
people = com.person object.person_ids do |abc|
progress_count += abc.size
Delayed::Job.current.update_attribute :progress, (progress_count/total_count)
end
end
end
Delayed :: Job.current nie działa. Widzę proponowaną metodę Delayed :: Job.currentten wpiswygląda na to, że metoda nigdy nie została uwzględniona w głównym projekcie github delayed_jobs.
Jak mogę uzyskać dostęp do bieżącej pracy (z poziomu rzeczywistej pracy), aby zaktualizować pole postępu za każdym razem, gdy moja praca przechodzi przez pętlę?