Method: Funktor::WorkQueueHandler#dispatch

Defined in:
lib/funktor/work_queue_handler.rb

#dispatch(job) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/funktor/work_queue_handler.rb', line 30

def dispatch(job)
  begin
    @tracker.track(:processingStarted, job)
    if Funktor.enable_work_queue_visibility
      update_job_category(job, "processing")
    end
    Funktor.work_queue_handler_middleware.invoke(job) do
      job.execute
    end
    @processed_counter.incr(job)
    @tracker.track(:processingComplete, job)

    if Funktor.enable_work_queue_visibility
      delete_job_from_dynamodb(job)
    end
  # rescue Funktor::Job::InvalidJsonError # TODO Make this work
  rescue Exception => e
    handle_error(e, job)
    @failed_counter.incr(job)
    job.error = e
    if job.can_retry
      @tracker.track(:retrying, job)

      if Funktor.enable_work_queue_visibility
        update_job_category(job, "retry")
      end
      trigger_retry(job)
    else
      @tracker.track(:bailingOut, job)

      if Funktor.enable_work_queue_visibility
        update_job_category(job, "dead")
      end
      Funktor.logger.error "We retried max times. We're bailing on this one."
      Funktor.logger.error job.to_json
    end
    @tracker.track(:processingFailed, job)
  end
end