Class: Eyeloupe::Processors::Job

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/eyeloupe/processors/job.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJob

Returns a new instance of Job.



10
11
12
# File 'lib/eyeloupe/processors/job.rb', line 10

def initialize
  @subs = []
end

Instance Attribute Details

#subsArray

Returns:

  • (Array)


8
9
10
# File 'lib/eyeloupe/processors/job.rb', line 8

def subs
  @subs
end

Instance Method Details

#args_info(job) ⇒ Array?

Parameters:

  • job (ActiveJob::Base)

    The job object

Returns:

  • (Array, nil)


69
70
71
72
73
# File 'lib/eyeloupe/processors/job.rb', line 69

def args_info(job)
  if job.class.log_arguments? && job.arguments.any?
    job.arguments
  end
end

#complete(event) ⇒ Object

Parameters:

  • event (ActiveSupport::Notifications::Event)

    The event object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/eyeloupe/processors/job.rb', line 37

def complete(event)
  job = event.payload[:job]

  existing = Eyeloupe::Job.where(job_id: job.job_id).first

  if existing&.failed?
    Eyeloupe::Job.where(job_id: job.job_id).update(completed_at: Time.now.utc, retry: existing.retry + 1)
  else
    Eyeloupe::Job.where(job_id: job.job_id).update(
      status: :completed,
      completed_at: Time.now.utc,
      retry: (job.executions.zero? ? 1 : job.executions) - 1
    )
  end
end

#discard(event) ⇒ Object

Parameters:

  • event (ActiveSupport::Notifications::Event)

    The event object



61
62
63
64
65
# File 'lib/eyeloupe/processors/job.rb', line 61

def discard(event)
  job = event.payload[:job]

  Eyeloupe::Job.where(job_id: job.job_id).update(status: :discarded)
end

#failed(event) ⇒ Object

Parameters:

  • event (ActiveSupport::Notifications::Event)

    The event object



54
55
56
57
58
# File 'lib/eyeloupe/processors/job.rb', line 54

def failed(event)
  job = event.payload[:job]

  Eyeloupe::Job.where(job_id: job.job_id).update(status: :failed)
end

#process(event) ⇒ Object

Parameters:

  • event (ActiveSupport::Notifications::Event)

    The event object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/eyeloupe/processors/job.rb', line 15

def process(event)
  job = event.payload[:job]

  Eyeloupe::Job.create(
    classname: job.class.name,
    job_id: job.job_id,
    queue_name: queue_name(event),
    adapter: adapter_name(event),
    scheduled_at: scheduled_at(event),
    status: :enqueued,
    args: (args_info(job) || {}).to_json
  )
end

#run(event) ⇒ Object

Parameters:

  • event (ActiveSupport::Notifications::Event)

    The event object



30
31
32
33
34
# File 'lib/eyeloupe/processors/job.rb', line 30

def run(event)
  job = event.payload[:job]

  Eyeloupe::Job.where(job_id: job.job_id).update(status: :running, executed_at: Time.now.utc)
end