Class: ThreadsPad::JobReflection
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ThreadsPad::JobReflection
- Defined in:
- lib/threads_pad/job_reflection.rb
Instance Attribute Summary collapse
-
#job ⇒ Object
Returns the value of attribute job.
Instance Method Summary collapse
- #init_attributes ⇒ Object
-
#initialize(job, **options) ⇒ JobReflection
constructor
A new instance of JobReflection.
- #reload_if_needed ⇒ Object
- #save_if_needed ⇒ Object
- #start ⇒ Object
- #thread_alive? ⇒ Boolean
Constructor Details
#initialize(job, **options) ⇒ JobReflection
Returns a new instance of JobReflection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/threads_pad/job_reflection.rb', line 11 def initialize job, ** @job = job @current_iteration = 0 if [:iteration_sync] @iteration_sync = [:iteration_sync].to_i else @iteration_sync = 100 end @job.job_reflection = self if @job.present? super() init_attributes end |
Instance Attribute Details
#job ⇒ Object
Returns the value of attribute job.
5 6 7 |
# File 'lib/threads_pad/job_reflection.rb', line 5 def job @job end |
Instance Method Details
#init_attributes ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/threads_pad/job_reflection.rb', line 26 def init_attributes self.current = 0 self.max = 100 self.min = 0 self.started = false self.destroy_on_finish = false self.save! end |
#reload_if_needed ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/threads_pad/job_reflection.rb', line 46 def reload_if_needed @current_iteration += 1 if @current_iteration > @iteration_sync @current_iteration = 0 reload end end |
#save_if_needed ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/threads_pad/job_reflection.rb', line 38 def save_if_needed @current_iteration += 1 if @current_iteration > @iteration_sync @current_iteration = 0 save! end end |
#start ⇒ Object
35 36 37 |
# File 'lib/threads_pad/job_reflection.rb', line 35 def start @job.start end |
#thread_alive? ⇒ Boolean
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/threads_pad/job_reflection.rb', line 53 def thread_alive? ret = false Thread.list.each do |t| if t.object_id.to_s == self.thread_id #get our job from found thread @job = t[:job] ret = @job.present? end end ret end |