Class: Cod::Beanstalk::Service

Inherits:
Service
  • Object
show all
Defined in:
lib/cod/beanstalk/service.rb

Overview

Beanstalk services specialize for the beanstalk channels in that they support a second service block argument, the control. Using this argument, your service can refuse to accept a request or bury it for debugging inspection.

Examples:

Additional block argument

service.one { |request, control|
  control.retry_in(1) # release message with delay
}

Defined Under Namespace

Classes: Client, Control

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Cod::Service

Instance Method Details

#one(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cod/beanstalk/service.rb', line 13

def one(&block)
  @channel.try_get { |(rq, answer_chan), control| 
    result = if block.arity == 2
      block.call(rq, Control.new(control))
    else
      block.call(rq)
    end
    
    unless control.command_given?
      # The only way to respond to the caller is by exiting the block 
      # without giving metacommands.
      answer_chan.put result if answer_chan
    end
  }
end