0.0
No commit activity in last 3 years
No release in over 3 years
wraps resugan listeners inside a worker
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
~> 3.0

Runtime

 Project Readme

Gem Version CircleCI

Resugan::Worker

Background worker extension to the resugan gem. Uses redis and parallel_queue as a backend.

Installation

Add this line to your application's Gemfile:

gem 'resugan-worker'

And then execute:

$ bundle

Or install it yourself as:

$ gem install resugan-worker

Usage

Transparently works with the resugan gem to turn your event listeners into background workers. When this gem is included it will use Resugan::Worker::ParallelQueueDispatcher as the default dispatcher. What this dispatcher does is it queues all fired events into a redis queue to be consumed by an event worker.

You can start a monitor for namespace group1 using (note that this blocks):

  Resugan::Worker::Monitor.new('group1').start

Ideally you can create a rake task with something like this:

# monitor.rake

namespace :monitor do
  desc "Starts the environment monitor"
  task :start =>[:namespace] do |t, args|

    # sample listeners, can be placed somewhere else
    _listener :hello do
      #do stuff that happens when hello is fired
    end

    Resugan::Worker::Monitor.new(args[:namespace] || '').start
  end
end
  rake monitor:start[group1]

This will create a blocking process that listens for events on the default namespace and sends them to the listeners

Firing events is the same, but the event generators can be in another process or machine

resugan {
  _fire :hello
}

Error and exception handling

If you want to handle exceptions showing up in a listener, you can define a handler that gets called when something bad happens.

   monitor = Resugan::Worker::Monitor.new
   monitor.configure do |config|
     config.error_handler = ->(namespace, event, args, exception) {
       puts exception.backtrace
     }
   end

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/resugan-worker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.