Class: BrokenRecord::Job
- Inherits:
-
Object
- Object
- BrokenRecord::Job
- Defined in:
- lib/broken_record/job.rb
Constant Summary collapse
- JOBS_PER_PROCESSOR =
1
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#klass ⇒ Object
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Job
constructor
A new instance of Job.
- #perform ⇒ Object
Constructor Details
#initialize(options) ⇒ Job
Returns a new instance of Job.
23 24 25 |
# File 'lib/broken_record/job.rb', line 23 def initialize() .each { |k, v| send("#{k}=", v) } end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
7 8 9 |
# File 'lib/broken_record/job.rb', line 7 def index @index end |
#klass ⇒ Object
Returns the value of attribute klass.
7 8 9 |
# File 'lib/broken_record/job.rb', line 7 def klass @klass end |
Class Method Details
.build_jobs(classes) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/broken_record/job.rb', line 13 def self.build_jobs(classes) jobs = [] classes.each do |klass| jobs_per_class.times do |index| jobs << Job.new(:klass => klass, :index => index) end end jobs end |
.jobs_per_class ⇒ Object
9 10 11 |
# File 'lib/broken_record/job.rb', line 9 def self.jobs_per_class JOBS_PER_PROCESSOR * Parallel.processor_count end |
Instance Method Details
#perform ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/broken_record/job.rb', line 27 def perform result = BrokenRecord::JobResult.new(self) result.start_timer records.each do |r| begin if !r.valid? = " Invalid record in #{klass} id=#{r.id}." r.errors.each { |attr,msg| << "\n #{attr} - #{msg}" } result.add_error end rescue Exception => e = " Exception for record in #{klass} id=#{r.id} - #{e}.\n" << e.backtrace.map { |line| " #{line}"}.join("\n") result.add_error end end result.stop_timer result end |