lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.9 vs lib/rufus/sc/jobs.rb in rufus-scheduler-2.0.10

- old
+ new

@@ -65,26 +65,20 @@ # The identifier for this job. # attr_reader :job_id - attr_accessor :running - # Instantiating the job. # def initialize(scheduler, t, params, &block) @scheduler = scheduler @t = t @params = params @block = block || params[:schedulable] @running = false - @allow_overlapping = true - if !params[:allow_overlapping].nil? - @allow_overlapping = params[:allow_overlapping] - end raise ArgumentError.new( 'no block or :schedulable passed, nothing to schedule' ) unless @block @@ -93,10 +87,19 @@ @job_id = params[:job_id] || "#{self.class.name}_#{self.object_id.to_s}" determine_at end + # Returns true if this job is currently running (in the middle of #trigger) + # + def running + + @running + end + + alias running? running + # Returns the list of tags attached to the job. # def tags @params[:tags] @@ -124,13 +127,14 @@ @last = t job_thread = nil to_job = nil - return if @running && !@allow_overlapping + return if @running and (params[:allow_overlapping] == false) @running = true + @scheduler.send(:trigger_job, @params[:blocking]) do # # Note that #trigger_job is protected, hence the #send # (Only jobs know about this method of the scheduler) @@ -145,16 +149,16 @@ trigger_block job_thread = nil to_job.unschedule if to_job - @running = false - rescue Exception => e @scheduler.handle_exception(self, e) end + + @running = false end # note that add_job and add_cron_job ensured that :blocking is # not used along :timeout @@ -167,10 +171,9 @@ if job_thread && job_thread.alive? job_thread.raise(Rufus::Scheduler::TimeOutError) end end end - end # Simply encapsulating the block#call/trigger operation, for easy # override. #