lib/cloudtasker/worker.rb in cloudtasker-0.12.rc5 vs lib/cloudtasker/worker.rb in cloudtasker-0.12.rc6

- old
+ new

@@ -331,10 +331,26 @@ def job_dead? job_retries > job_max_retries end # + # Return true if the job arguments are missing. + # + # This may happen if a job + # was successfully run but retried due to Cloud Task dispatch deadline + # exceeded. If the arguments were stored in Redis then they may have + # been flushed already after the successful completion. + # + # If job arguments are missing then the job will simply be declared dead. + # + # @return [Boolean] True if the arguments are missing. + # + def arguments_missing? + job_args.empty? && [0, -1].exclude?(method(:perform).arity) + end + + # # Return the time taken (in seconds) to perform the job. This duration # includes the middlewares and the actual perform method. # # @return [Float] The time taken in seconds as a floating point number. # @@ -382,17 +398,12 @@ self.perform_started_at = Time.now Cloudtasker.config.server_middleware.invoke(self) do # Immediately abort the job if it is already dead flag_as_dead if job_dead? + flag_as_dead(MissingWorkerArgumentsError.new('worker arguments are missing')) if arguments_missing? begin - # Abort if arguments are missing. This may happen with redis arguments storage - # if Cloud Tasks times out on a job but the job still succeeds - if job_args.empty? && [0, -1].exclude?(method(:perform).arity) - raise(MissingWorkerArgumentsError, 'worker arguments are missing') - end - # Perform the job perform(*job_args) rescue StandardError => e run_callback(:on_error, e) return raise(e) unless job_must_die?