lib/resque/plugins/multi_step_task.rb
# Finalize this job group.  Finalization entails running all
# finalization jobs serially in the order they were defined.
#
# @raise [NotReadyForFinalization] When called before all normal
#   jobs have been attempted.
#
# @raise [FinalizationAlreadyBegun] If some other process has
#   already started (and/or finished) the finalization process.
Finalize this job group.  Finalization entails running all
finalization jobs serially in the order they were defined.
Finalize this job group . Finalization entails running all finalization jobs serially in the order they were defined .
def finalize!
        logger.debug("[Resque Multi-Step-Task] Attempting to finalize #{task_id}")
        raise FinalizationAlreadyBegun unless MultiStepTask.active?(task_id)
        raise NotReadyForFinalization if !ready_for_finalization? || incomplete_because_of_errors?
        raise FinalizationAlreadyBegun unless redis.setnx("i_am_the_finalizer", 1)
        if synchronous?
          sync_finalize!
        else
          if fin_job_info = redis.lpop('finalize_jobs')
            fin_job_info = Yajl::Parser.parse(fin_job_info)
            Resque::Job.create(queue_name, FinalizationJob, self.task_id, *fin_job_info)
          else
            logger.debug "[Resque Multi-Step-Task] \"#{task_id}\" finalized successfully at #{Time.now}, taking #{(Time.now - redis.get('start-time').to_i).to_i} seconds."
            nuke
          end
        end
      end
def finalize! logger . debug ( "[Resque Multi-Step-Task] Attempting to finalize #{task_id}" ) raise FinalizationAlreadyBegun unless MultiStepTask . active? ( task_id ) raise NotReadyForFinalization if ! ready_for_finalization? || incomplete_because_of_errors? raise FinalizationAlreadyBegun unless redis . setnx ( "i_am_the_finalizer" , 1 ) if synchronous? sync_finalize! else if fin_job_info = redis . lpop ( 'finalize_jobs' ) fin_job_info = Yajl :: Parser . parse ( fin_job_info ) Resque :: Job . create ( queue_name , FinalizationJob , self . task_id , * fin_job_info ) else logger . debug "[Resque Multi-Step-Task] \"#{task_id}\" finalized successfully at #{Time.now}, taking #{(Time.now - redis.get('start-time').to_i).to_i} seconds." nuke end end end
Finalize this job group.
Finalize this job group .
# Only one process is allowed to start the finalization # process.  This setnx acts a global mutex for other processes # that finish about the same time. # There is nothing left to do so cleanup.
[NotReadyForFinalization] When called before all normal jobs have been attempted.
[ NotReadyForFinalization ] When called before all normal jobs have been attempted .
[FinalizationAlreadyBegun] If some other process has already started (and/or finished) the finalization process.
[ FinalizationAlreadyBegun ] If some other process has already started ( and / or finished ) the finalization process .