Class: JobDispatch::Broker::InternalJob

Inherits:
Object
  • Object
show all
Defined in:
lib/job_dispatch/broker/internal_job.rb

Overview

a class to represent a worker processing a broker command that is not a job. It is still tracked by the broker as if it was a job, though. If the worker does not reply, they will be timed out. And status report will show the worker state as executing this command.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, queue) ⇒ InternalJob

Returns a new instance of InternalJob.



10
11
12
13
14
15
# File 'lib/job_dispatch/broker/internal_job.rb', line 10

def initialize(command, queue)
  @id = SecureRandom.uuid
  @command = command
  @timeout_at = Time.now + JobDispatch::Job::DEFAULT_EXECUTION_TIMEOUT
  @queue = queue
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



8
9
10
# File 'lib/job_dispatch/broker/internal_job.rb', line 8

def command
  @command
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/job_dispatch/broker/internal_job.rb', line 8

def id
  @id
end

#queueObject (readonly)

Returns the value of attribute queue.



8
9
10
# File 'lib/job_dispatch/broker/internal_job.rb', line 8

def queue
  @queue
end

Instance Method Details

#as_jsonObject



21
22
23
24
25
26
27
28
29
# File 'lib/job_dispatch/broker/internal_job.rb', line 21

def as_json
  {
      command: command,
      id: id,
      queue: queue,
      target: "JobDispatch",
      method: command
  }
end

#timed_out?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/job_dispatch/broker/internal_job.rb', line 17

def timed_out?
  Time.now > @timeout_at
end