Facebooker Queue
Facebooker Queue is an easy way to background your Facebooker API calls.
Features/Problems
- Simplest possible implementation
- Easy setup
- Transparent, drop-in queueing
- Can always override to perform synchronous requests
- Queue-service agnostic; interface with the messaging queue service of your choice using a simple adapter class
- Support for Beanstalkd out of the box; more to come?
Installation
script/plugin install git://github.com/cvincent/Facebooker-Queue.git
Make sure you rename the plugin directory from “Facebooker-Queue” to “facebooker_queue”. Alternatively, you can install as a git submodule:
git submodule add git://github.com/cvincent/Facebooker-Queue.git vendor/plugins/facebooker_queue
Setup
facebooker.yml
You will need to add a queue_service_adapter
line to your facebooker.yml config. Currently, only beanstalked
is supported out of the box, which also requires a queue_pool_address
line. For example:
development:
api_key: XXXX
secret_key: XXXX
canvas_page_name: XXXX
callback_url: http://XXXX:3000
pretty_errors: true
set_asset_host_to_callback_url: true
tunnel:
public_host_username:
public_host:
public_port: 4007
local_port: 3000
queue_service_adapter: beanstalked
queue_pool_address: localhost:11300
Note that only environments which have specified a queue_service_adapter
will queue requests. This allows you, for example, to activate queueing only in production.
Worker daemon
The worker script requires the daemons
gem:
sudo gem install daemons
Generate the queue daemon by running:
script/generate facebooker_queue_daemon
Start, stop, or restart the daemon using:
lib/daemons/facebooker_queue_ctl (start|stop|restart)
Usage
Just use Facebooker as you normally would and the following API calls will be queued:
- facebook.notifications.send
- facebook.notifications.sendEmail
- facebook.feed.publishUserAction
- facebook.profile.setFBML
- facebook.liveMessage.send
If you need to get the results of an API request, you will need to override the queue and call the method synchronously. This is easily achieved:
facebooker_session.sync do
# anything here will be run synchronously
end
Writing your own queueing service adapter
The interface for the queueing service is simple. Simply write a class which mimics the interface of lib/queue_adapters/beanstalked_adapter.rb
.
If you do write an adapter for other popular queueing services, please let me know and it will be included with this plugin.
Todo
- Support custom post-processing of queued requests for any API method
- Include adapters for more message queueing services, such as Starling
Contributors
© 2009 Chris Vincent, released under the MIT license