AsyncService is a library to create asynchronous SOA daemons
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.autotest
.gitignore
.rspec
.rvmrc
Gemfile
Guardfile
README.md
Rakefile
async_service.gemspec

README.md

Description

AsyncService provides an abstraction for workers/daemons that processes work from a queue. Often an AsyncService::Worker will get work from a queue, process it and push the result back into another queue.

You can also take a look at SyncService which provides abstractions for synchronous SOA.

Install

$ gem install async_service

Creating a Worker

class CalculatorMachine < AsyncService::Worker
  # You need to set a service name
  @service_name = 'in.mobme.calculator_machine'

  # This function is called on run
  def work
    loop do
      queue.remove("work_queue") do |item|
        result = item[:a] + item[:b]

        queue.add("result_queue", result)
      end
      sleep 5
    end
  end
end

calculator = CalculatorMachine.new
calculator.run