No release in over 3 years
Low commit activity in last 3 years
The "resque" dispatch strategy for the emittance gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
>= 0
~> 10.0
~> 3.0
>= 0

Runtime

~> 1.1
>= 0
 Project Readme

Emittance::Resque

Build Status Maintainability Inline docs

This is the Resque broker for the Emittance gem.

Installation

Add this line to your application's Gemfile:

gem 'emittance', '=> 0.0.6'
gem 'emittance-resque'

And then execute:

$ bundle

Emittance::Resque requires any version of Emittance from 0.0.6 onward.

Or install it yourself as:

$ gem install emittance
$ gem install emittance-resque

Usage

Use this as you would the standard Emittance gem. There are some limitations, which we'll get to in the next section.

First, we need to set the backend:

Emittance.use_broker :resque

Then, we can watch for events:

class MyKlass
  extend Emittance::Watcher

  def self.something_happened(event)
    puts 'something happened!'
  end
end

MyKlass.watch :happening, :something_happened

Per the Emittance core library, this sets MyKlass up to call .something_happened whenever a :happening event (wrapped in an instance of HappeningEvent) gets emitted. Since we're using the Resque broker, this will occur in a Resque job.

class MyEmitter
  extend Emittance::Emitter

  def self.make_something_happen
    puts 'something will happen'
    emit :happening
  end
end

MyEmitter.make_something_happen
# In the parent process log:
# something will happen!
#
# In the Resque process log:
# something happened!

Serialization

By default, this library will piggyback on Resque's default serialization scheme. When used in a Rails app, it will detect persisted (i.e. ActiveRecord::Base) objects (even inside of a hash or enumerable object) and pass on the type and ID, deserializing those values back into the correct objects. The callback method should expect a single argument in the form of the correct Emittance::Event object.

Serialization and deserialization are accomplished with an object (typically a singleton class) that respond to serialize and deserialize methods, which take an Emittance::Event object and the serialized Emittance::Event object, respectively. You can write your own serializer if your needs are not met with the built-in schemes--just create a class or an object that meets the criteria discussed earlier in this paragraph. Let Emittance know which serializer to use like so:

Emittance::Resque.use_serializer(MyCoolSerializer)

Limitations

At this time, Emittance::Resque can only register listeners as

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]/emittance-resque. 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.

Code of Conduct

Everyone interacting in the Emittance::Resque project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.