Class: Resque::Reports::ReportJob
- Inherits:
-
Object
- Object
- Resque::Reports::ReportJob
- Extended by:
- Extensions::EnqueueToFix
- Includes:
- Integration
- Defined in:
- app/jobs/resque/reports/report_job.rb
Overview
ReportJob accepts report_type, its arguments in json and building report in background @example:
ReportJob.enqueue('Resque::Reports::MyReport', [1, 2].to_json)
ReportJob.enqueue_to(:my_queue, 'Resque::Reports::MyReport', [1, 2].to_json)
Class Method Summary collapse
-
.execute(report_type, args_json) ⇒ Object
resque-integration main job method.
-
.init_report(report_class, args_array) ⇒ Object
Initializes report of given class with given arguments.
Methods included from Extensions::EnqueueToFix
Class Method Details
.execute(report_type, args_json) ⇒ Object
resque-integration main job method
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/jobs/resque/reports/report_job.rb', line 24 def self.execute(report_type, args_json) report_class = report_type.constantize # избавиться от ActiveSupport unless report_class < BaseReport fail "Supports only successors of BaseReport, but got #{report_class}" end args = JSON.parse(args_json) force = args.pop init_report(report_class, args).build(force) end |
.init_report(report_class, args_array) ⇒ Object
Initializes report of given class with given arguments
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/jobs/resque/reports/report_job.rb', line 40 def self.init_report(report_class, args_array) report = report_class.new(*args_array) report_class.on_progress do |progress, total| unless total.zero? at(progress, total, report.(progress, total)) end end report_class.on_error do |error| = () ['payload'] ||= {'error_messages' => []} ['payload']['error_messages'] << report.(error) .save end report end |