Module: Beez::Worker::ClassMethods

Defined in:
lib/beez/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)


80
81
82
# File 'lib/beez/worker.rb', line 80

def get_max_jobs_to_activate
  @max_jobs_to_activate || 1
end

#get_nameString

Returns the worker’s name.

Returns:

  • (String)


154
155
156
157
158
# File 'lib/beez/worker.rb', line 154

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)


101
102
103
# File 'lib/beez/worker.rb', line 101

def get_poll_interval
  @poll_interval || 5
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)


124
125
126
# File 'lib/beez/worker.rb', line 124

def get_timeout
  @timeout || 30
end

#get_typeString

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

Returns:

  • (String)


55
56
57
# File 'lib/beez/worker.rb', line 55

def get_type
  @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>)


147
148
149
# File 'lib/beez/worker.rb', line 147

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 ::Beez::Worker
  max_jobs_to_activate 5
end

Parameters:

  • max_jobs_to_activate (Integer)

Returns:

  • (Integer)


71
72
73
# File 'lib/beez/worker.rb', line 71

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 ::Beez::Worker
  poll_interval 5
end

Parameters:

  • poll_interval (Integer)

Returns:

  • (Integer)


94
95
96
# File 'lib/beez/worker.rb', line 94

def poll_interval(poll_interval)
  @poll_interval = poll_interval
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 ::Beez::Worker
  timeout 30
end

Parameters:

  • timeout (Integer)

Returns:

  • (Integer)


116
117
118
# File 'lib/beez/worker.rb', line 116

def timeout(timeout)
  @timeout = timeout
end

#type(type) ⇒ String

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

Examples:

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

Parameters:

  • type (String)

Returns:

  • (String)


48
49
50
# File 'lib/beez/worker.rb', line 48

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 ::Beez::Worker
  variables [:foo, :bar]
end

Parameters:

  • variables (Array<String, Symbol>)

Returns:

  • (Array<String, Symbol>)


139
140
141
# File 'lib/beez/worker.rb', line 139

def variables(variables)
  @variables = variables
end