Class: Rapid::Task
- Inherits:
-
Object
- Object
- Rapid::Task
- Defined in:
- lib/rapid/task.rb
Instance Method Summary collapse
- #args=(args) ⇒ Object
- #enqueue ⇒ Object
-
#initialize(klass, content, attr) ⇒ Task
constructor
A new instance of Task.
- #metaclass ⇒ Object
- #method_name=(method_name) ⇒ Object
- #to_json ⇒ Object
- #underscore(camel_cased_word) ⇒ Object
Constructor Details
#initialize(klass, content, attr) ⇒ Task
Returns a new instance of Task.
7 8 9 10 11 12 13 14 |
# File 'lib/rapid/task.rb', line 7 def initialize klass, content, attr @klass = klass @content = content @message_ttl = attr[:message_ttl] @routing_key = attr[:routing_key] @max_attempts = attr[:max_attempts] || 1 @attempt_counter = 0 end |
Instance Method Details
#args=(args) ⇒ Object
16 17 18 |
# File 'lib/rapid/task.rb', line 16 def args= args @args = args end |
#enqueue ⇒ Object
45 46 47 48 |
# File 'lib/rapid/task.rb', line 45 def enqueue q = Rapid::get_channel.queue(underscore('rapid_'+@klass.to_s), durable: true) q.publish(to_json, persisted: true)# TODO: message_ttl, routing_key end |
#metaclass ⇒ Object
3 4 5 |
# File 'lib/rapid/task.rb', line 3 def class << self; self; end end |
#method_name=(method_name) ⇒ Object
20 21 22 |
# File 'lib/rapid/task.rb', line 20 def method_name= method_name @method_name = method_name end |
#to_json ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rapid/task.rb', line 24 def to_json { klass: @klass, content: @content, message_ttl: @message_ttl, routing_key: @routing_key, max_attempts: @max_attempts, attempt_counter: @attempt_counter, method_name: @method_name, args: @args, }.to_json end |
#underscore(camel_cased_word) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rapid/task.rb', line 37 def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr('-', '_'). downcase end |