Skip to content

Instantly share code, notes, and snippets.

@nicotaing
Created October 17, 2012 02:12
Show Gist options
  • Save nicotaing/3903332 to your computer and use it in GitHub Desktop.
Save nicotaing/3903332 to your computer and use it in GitHub Desktop.
Beaneater API Draft
# Connection, Tubes, Jobs, Stats
@beaneater_connection = Beaneater::Connection.new(['localhost:11300'])
### Producer
@beaneater_tube = @beaneater_connection.tubes.find_or_create('tube2')
@beaneater_tube.put "data", :priority => 1000, :ttr => 10, :delay => 5
# => true
### Worker
@beaneater_connection.jobs.register('tube2', :retry_on => [Timeout::Error]) do |job|
process_one(job)
end
@beaneater_connection.jobs.register('tube3', 'tube4') do |job|
process_two(job)
end
@beaneater_connection.jobs.process # all described tubes
# watch all described tubes
# ignore all other tubes
# loop do
# reserve
# invoke describe block based on tube
# success => delete, fail => bury
# Custom reserve
@beaneater_connection.tubes.reserve('tube2', 'tube3') { |job| process(job) }
@beaneater_connection.jobs.peek(123)
@beaneater_connection.tubes.find('tube2').peek(:ready)
@beaneater_connection.tubes.find('tube2').peek(:delayed)
@beaneater_connection.tubes.find('tube2').peek(:buried)
# => <Beaneater::Job>
@beaneater_connection.tubes.kick(10)
#=> true
@beaneater_connection.jobs.find(123).kick
### Stats
@beaneater_connection.jobs.find(123).ttr # id, state, pro, age, ...
@beaneater_connection.tubes.find('tube1').name # total-jobs, name ...
@beaneater_connection.stats.current_jobs_urgent
@beaneater_connection.tubes.all
# => [<Beaneater::Tube>, <Beaneater::Tube>....]
@beaneater_connection.tubes.watched
@beaneater_connection.tubes.used
# Other
@beaneater_connection.tubes.find(123).pause(120)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment