Module: Beez::Worker

Defined in:
lib/beez/worker.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client.



5
6
7
# File 'lib/beez/worker.rb', line 5

def client
  @client
end

#max_jobs_to_activateObject

Returns the value of attribute max_jobs_to_activate.



5
6
7
# File 'lib/beez/worker.rb', line 5

def max_jobs_to_activate
  @max_jobs_to_activate
end

#poll_intervalObject

Returns the value of attribute poll_interval.



5
6
7
# File 'lib/beez/worker.rb', line 5

def poll_interval
  @poll_interval
end

#timeoutObject

Returns the value of attribute timeout.



5
6
7
# File 'lib/beez/worker.rb', line 5

def timeout
  @timeout
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/beez/worker.rb', line 5

def type
  @type
end

#variablesObject

Returns the value of attribute variables.



5
6
7
# File 'lib/beez/worker.rb', line 5

def variables
  @variables
end

Class Method Details

.included(base) ⇒ Object



7
8
9
10
# File 'lib/beez/worker.rb', line 7

def self.included(base)
  base.extend(ClassMethods)
  Beez.register_worker(base)
end

Instance Method Details

#complete_job(job, variables: {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/beez/worker.rb', line 16

def complete_job(job, variables: {})
  client.complete_job(
    jobKey: job.key,
    variables: Hash(variables).to_json
  )
end

#fail_job(job, reason: '') ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/beez/worker.rb', line 23

def fail_job(job, reason: '')
  client.fail_job(
    jobKey: job.key,
    retries: job.retries - 1,
    errorMessage: reason
  )
rescue StandardError => e
  logger.error e.message
end

#initialize(client) ⇒ Object



12
13
14
# File 'lib/beez/worker.rb', line 12

def initialize(client)
  @client = client
end

#loggerObject



33
34
35
# File 'lib/beez/worker.rb', line 33

def logger
  ::Beez.logger
end