Module: Cloudmunda::Worker::ClassMethods

Defined in:
lib/cloudmunda/cli/worker.rb

Instance Method Summary collapse

Instance Method Details

#get_max_jobs_to_activateInteger

Returns the maximum number of jobs to send to the worker for processing at once. As jobs get completed by the worker, more jobs will be sent to the worker but always within this limit.

Returns:

  • (Integer)


84
85
86
# File 'lib/cloudmunda/cli/worker.rb', line 84

def get_max_jobs_to_activate
  @max_jobs_to_activate || 1
end

#get_nameString

Returns the worker’s name.

Returns:

  • (String)


179
180
181
182
183
# File 'lib/cloudmunda/cli/worker.rb', line 179

def get_name
  name = self.name.gsub(/::/, ':')
  name.gsub!(/([^A-Z:])([A-Z])/) { "#{Regexp.last_match(1)}_#{Regexp.last_match(2)}" }
  name.downcase
end

#get_poll_intervalInteger

Returns the interval duration in seconds between polls to the broker.

Returns:

  • (Integer)


105
106
107
# File 'lib/cloudmunda/cli/worker.rb', line 105

def get_poll_interval
  @poll_interval || 5
end

#get_runs_in_developmentBoolean

Returns if this service task should run in development mode.

Returns:

  • (Boolean)


172
173
174
# File 'lib/cloudmunda/cli/worker.rb', line 172

def get_runs_in_development
  @runs_in_development || false
end

#get_timeoutInteger

Returns the time in seconds the worker has to process the job before the broker consider it as expired and can schedule it to another worker.

Returns:

  • (Integer)


128
129
130
# File 'lib/cloudmunda/cli/worker.rb', line 128

def get_timeout
  @timeout || 30
end

#get_typeString

Returns the type of service task the worker should subscribe to.

Returns:

  • (String)


59
60
61
# File 'lib/cloudmunda/cli/worker.rb', line 59

def get_type
  get_runs_in_development && Cloudmunda.env == 'development' ? "#{@type}-dev" : @type
end

#get_variables_to_fetchArray<String, Symbol>

Returns the worker’s variables to fetch from the broker when polling for new jobs.

Returns:

  • (Array<String, Symbol>)


151
152
153
# File 'lib/cloudmunda/cli/worker.rb', line 151

def get_variables_to_fetch
  @variables.to_a
end

#max_jobs_to_activate(max_jobs_to_activate) ⇒ Integer

Sets the maximum number of jobs to send to the worker for processing at once. As jobs get completed by the worker, more jobs will be sent to the worker but always within this limit.

Examples:

class MyWorker
  include ::Cloudmunda::Worker
  max_jobs_to_activate 5
end

Parameters:

  • max_jobs_to_activate (Integer)

Returns:

  • (Integer)


75
76
77
# File 'lib/cloudmunda/cli/worker.rb', line 75

def max_jobs_to_activate(max_jobs_to_activate)
  @max_jobs_to_activate = max_jobs_to_activate
end

#poll_interval(poll_interval) ⇒ Integer

Sets the interval duration in seconds between polls to the broker.

Examples:

class MyWorker
  include ::Cloudmunda::Worker
  poll_interval 5
end

Parameters:

  • poll_interval (Integer)

Returns:

  • (Integer)


98
99
100
# File 'lib/cloudmunda/cli/worker.rb', line 98

def poll_interval(poll_interval)
  @poll_interval = poll_interval
end

#runs_in_development(runs_in_development) ⇒ Boolean

Sets if this service task runs in development mode or not.

Examples:

class MyWorker
  include ::Cloudmunda::Worker
  runs_in_development true
end

Parameters:

  • runs_in_development (Boolean)

Returns:

  • (Boolean)


165
166
167
# File 'lib/cloudmunda/cli/worker.rb', line 165

def runs_in_development(runs_in_development)
  @runs_in_development = runs_in_development
end

#timeout(timeout) ⇒ Integer

Sets the time in seconds the worker has to process the job before the broker consider it as expired and can schedule it to another worker.

Examples:

class MyWorker
  include ::Cloudmunda::Worker
  timeout 30
end

Parameters:

  • timeout (Integer)

Returns:

  • (Integer)


120
121
122
# File 'lib/cloudmunda/cli/worker.rb', line 120

def timeout(timeout)
  @timeout = timeout
end

#type(type) ⇒ String

Sets the type of service task the worker should subscribe to.

Examples:

class MyWorker
  include ::Cloudmunda::Worker
  type "some-service-task-type"
end

Parameters:

  • type (String)

Returns:

  • (String)


52
53
54
# File 'lib/cloudmunda/cli/worker.rb', line 52

def type(type)
  @type = type
end

#variables(variables) ⇒ Array<String, Symbol>

Sets the worker’s variables to fetch from the broker when polling for new jobs.

Examples:

class MyWorker
  include ::Cloudmunda::Worker
  variables [:foo, :bar]
end

Parameters:

  • variables (Array<String, Symbol>)

Returns:

  • (Array<String, Symbol>)


143
144
145
# File 'lib/cloudmunda/cli/worker.rb', line 143

def variables(variables)
  @variables = variables
end