Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/igrigorik/em-jack
An Evented Beanstalk Client
https://github.com/igrigorik/em-jack
Last synced: about 2 months ago
JSON representation
An Evented Beanstalk Client
- Host: GitHub
- URL: https://github.com/igrigorik/em-jack
- Owner: igrigorik
- License: other
- Created: 2009-03-08T05:57:09.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2012-07-27T23:58:55.000Z (over 12 years ago)
- Last Synced: 2024-05-08T18:35:47.096Z (8 months ago)
- Language: Ruby
- Homepage: http://dj2.github.com/jack
- Size: 210 KB
- Stars: 64
- Watchers: 5
- Forks: 17
- Open Issues: 5
-
Metadata Files:
- Readme: README.rdoc
- License: COPYING
Awesome Lists containing this project
README
= EMJack
An attempt to wrap portions of the Beanstalk protocol with EventMachine. Every command
will return a deferrable object. That object will succeed or fail depending on the
reply returned from Beanstalk.One thing to keep in mind. The Beanstalk protocol executes all commands serially.
So, if you send a reserve command and there are no jobs Beanstalk _won't_ process
any of the commands that come after the reserve until the reserve completes.This is a bit of a gotcha when sending a series of reserve, delete, etc and there
are no available jobs.= Dependencies
- EventMachine
- RSpec (to run the tests)= Examples
EM.run {
jack = EMJack::Connection.newr = jack.use('mytube')
r.callback { |tube| puts "Using #{tube}" }r = jack.reserve
r.callback do |job|
puts job.jobidr2 = jack.delete(job) { puts "Successfully deleted" }
endr = jack.put("my message", :ttr => 300) { |jobid| puts "put successful #{jobid}" }
r = jack.stats
r.callback { |stats| puts "Server up for #{stats['uptime']} seconds" }r = jack.stats(:tube, "mytube")
r.callback { |stats| puts "Total jobs #{stats['total-jobs']}" }r = jack.list(:used)
r.callback { |tubes| puts "There are #{tubes.length} tubes defined" }
}Each of the Jack commands allows an optional block to be provided. If the block is given
it will be setup as the callback on the deferrable.EMJack#each_job is useful for scenarios where the client is a job worker
and intended to process jobs continuously as they become available. Once
the queue is empty, the client will block and wait for a new job.If multiple workers connect to the queue Beanstalkd will round-robin between
the workers.EM.run {
jack = EMJack::Connection.newjack.each_job do |job|
puts "Got job ##{job.jobid}: #{job}"if process(job)
r = jack.delete(job)
r.callback { puts "*Deleted #{job}*" }
else
end
enddef process(job)
# Some kind of job processing
end
}= Contact
If you've got any questions, comments or bugs, please let me know. You can
contact me by email at dj2 at everburning dot com.= Contributors
Charles Melbye (cmelbye)
Peter Kieltyka (pkieltyka)
Martyn Loughran (mloughran)
Mike Perham (mperham)