Module: Cloudmunda::Worker

Defined in:
lib/cloudmunda/cli/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.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def client
  @client
end

#max_jobs_to_activateObject

Returns the value of attribute max_jobs_to_activate.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def max_jobs_to_activate
  @max_jobs_to_activate
end

#poll_intervalObject

Returns the value of attribute poll_interval.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def poll_interval
  @poll_interval
end

#runs_in_developmentObject

Returns the value of attribute runs_in_development.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def runs_in_development
  @runs_in_development
end

#timeoutObject

Returns the value of attribute timeout.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def timeout
  @timeout
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def type
  @type
end

#variablesObject

Returns the value of attribute variables.



7
8
9
# File 'lib/cloudmunda/cli/worker.rb', line 7

def variables
  @variables
end

Class Method Details

.included(base) ⇒ Object



9
10
11
12
# File 'lib/cloudmunda/cli/worker.rb', line 9

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

Instance Method Details

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



18
19
20
21
22
23
24
# File 'lib/cloudmunda/cli/worker.rb', line 18

def complete_job(job, variables: {})
  logger.info "Completed processing job #{job.type} #{job.key}"
  client.complete_job(
    jobKey: job.key,
    variables: Hash(variables).to_json
  )
end

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



26
27
28
29
30
31
32
33
34
35
# File 'lib/cloudmunda/cli/worker.rb', line 26

def fail_job(job, reason: '')
  logger.error "Failed processing job #{job.type} #{job.key}: #{reason}"
  client.fail_job(
    jobKey: job.key,
    retries: job.retries - 1,
    errorMessage: reason
  )
rescue StandardError => e
  logger.error e.message
end

#initialize(client) ⇒ Object



14
15
16
# File 'lib/cloudmunda/cli/worker.rb', line 14

def initialize(client)
  @client = client
end

#loggerObject



37
38
39
# File 'lib/cloudmunda/cli/worker.rb', line 37

def logger
  ::Cloudmunda.logger
end