Fivebeans: различия между версиями

Материал из support.qbpro.ru
imported>Supportadmin
imported>Supportadmin
Строка 147: Строка 147:


===Server statistics===
===Server statistics===
====peek====
<code>client.peek(id, function(err, jobid, payload) {});</code>
Peek at the data for the specified job. Payload is a Buffer object.
====pause_tube====
<code>client.pause_tube(tubename, delay, function(err) {});</code>
Pause the named tube for the given number of seconds. No new jobs may be reserved from the tube while it is paused.
====list_tubes====
<code>client.list_tubes(function(err, tubenames) {});</code>
List all the existing tubes. Responds with an array of tube names.
====stats_job====
<code>client.stats_job(jobid, function(err, response) {});</code>
Request statistics for the specified job. Responds with a hash containing information about the job. See the beanstalkd documentation for a complete list of stats.
====stats_tube====
<code>client.stats_tube(tubename, function(err, response) {});</code>
Request statistics for the specified tube. Responds with a hash containing information about the tube. See the beanstalkd documentation for a complete list of stats.
====stats====
<code>client.stats(function(err, response) {});</code>
Request statistics for the beanstalkd server. Responds with a hash containing information about the server. See the beanstalkd documentation for a complete list of stats.
==FiveBeansWorker==
==FiveBeansWorker==
===API===
===API===

Версия от 18:24, 11 мая 2014

beanstalkd client & worker daemon for node

оригинал

FiveBeansClient

Heavily inspired by node-beanstalk-client, which is a perfectly usable client but somewhat dusty. I wanted more complete support of the beanstalkd protocol in a project written in plain javascript.

All client method names are the same case & spelling as the beanstalk text command, with hyphens replaced by underscore. The single exception is delete, which is renamed to destroy().

For complete details on the beanstalkd commands, see its protocol documentation.

Creating a client

The client constructor takes two arguments:

  • host: The address of the beanstalkd server. Defaults to 127.0.0.1.
  • port: Port to connect to. Defaults to 11300.

The client emits three events that you should listen for: connect, error, and close.

The client is not usable until you call its connect() method. Here's an example of setting up a client:

var fivebeans = require('fivebeans');
var client = new fivebeans.client('10.0.1.1', 11300);
client
   .on('connect', function()
   {
       // client can now be used
   })
   .on('error', function(err)
   {
       // connection failure    
   })
   .on('close', function()
   {
       // underlying connection has closed
   })
   .connect();

Producing jobs

use

client.use(tube, function(err, tubename) {});

Use the specified tube. Reponds with the name of the tube being used.

list_tube_used

client.list_tube_used(function(err, tubename) {});

Responds with the name of the tube currently being used by the client.

put

client.put(priority, delay, ttr, payload, function(err, jobid) {});

Submit a job with the specified priority (smaller integers are higher priority), delay in seconds, and allowed time-to-run in seconds. The payload contains the job data the server will return to clients reserving jobs; it can be either a Buffer object or a string. No processing is done on the data. Responds with the id of the newly-created job.

peek_ready

client.peek_ready(function(err, jobid, payload) {});

Peek at the data for the job at the top of the ready queue of the tube currently in use. Responds with the job id and payload of the next job, or 'NOT_FOUND' if there are no qualifying jobs in the tube. The payload is a Buffer object.

peek_delayed

client.peek_delayed(function(err, jobid, payload) {});

Peek at the data for the delayed job with the shortest delay in the tube currently in use. Responds with the job id and payload of the next job, or 'NOT_FOUND' in err if there are no qualifying jobs in the tube. The payload is a Buffer object.

peek_buried

client.peek_buried(function(err, jobid, payload) {});

Peek at the data for the next buried job in the tube currently in use. Responds with the job id and payload of the next job, or 'NOT_FOUND' in err if there are no qualifying jobs in the tube. The payload is a Buffer object.

Consuming jobs

watch

client.watch(tube, function(err, numwatched) {});

Watch the named tube. Responds with the number of tubes currently watched by the client.

ignore

client.ignore(tube, function(err, numwatched) {});

Ignore the named tube. Responds with the number of tubes currently watched by the client.

list_tubes_watched

client.list_tubes_watched(function(err, tubelist) {});

Responds with an array containing the names of the tubes currently watched by the client.

reserve

client.reserve(function(err, jobid, payload) {});

Reserve a job. Responds with the id and the job data. The payload is a Buffer object.

reserve_with_timeout

client.reserve_with_timeout(seconds, function(err, jobid, payload) {});

Reserve a job, waiting the specified number of seconds before timing out. err contains the string "TIMED_OUT" if the specified time elapsed before a job became available. Payload is a buffer.

touch

client.touch(jobid, function(err) {});

Inform the server that the client is still processing a job, thus requesting more time to work on it.

destroy

client.destroy(jobid, function(err) {});

Delete the specified job. Responds with null if successful, a string error otherwise. This is the only method not named identically to its beanstalkd counterpart, because delete is a reserved word in Javascript.

release

client.release(jobid, priority, delay, function(err) {});

Release the specified job and assign it the given priority and delay (in seconds). Responds with null if successful, a string error otherwise.

bury

client.bury(jobid, priority, function(err) {});

Bury the specified job and assign it the given priority. Responds with null if successful, a string error otherwise.

kick

client.kick(maxToKick, function(err, numkicked) {});

Kick at most maxToKick delayed and buried jobs back into the active queue. Responds with the number of jobs kicked.

kick_job

client.kick_job(jobID, function(err) {});

Kick the specified job id. Responds with NOT_FOUND if the job was not found. Supported in beanstalkd versions >= 1.6.

Server statistics

peek

client.peek(id, function(err, jobid, payload) {});

Peek at the data for the specified job. Payload is a Buffer object.

pause_tube

client.pause_tube(tubename, delay, function(err) {});

Pause the named tube for the given number of seconds. No new jobs may be reserved from the tube while it is paused.

list_tubes

client.list_tubes(function(err, tubenames) {});

List all the existing tubes. Responds with an array of tube names.

stats_job

client.stats_job(jobid, function(err, response) {});

Request statistics for the specified job. Responds with a hash containing information about the job. See the beanstalkd documentation for a complete list of stats.

stats_tube

client.stats_tube(tubename, function(err, response) {});

Request statistics for the specified tube. Responds with a hash containing information about the tube. See the beanstalkd documentation for a complete list of stats.

stats

client.stats(function(err, response) {});

Request statistics for the beanstalkd server. Responds with a hash containing information about the server. See the beanstalkd documentation for a complete list of stats.

FiveBeansWorker

API

constructor

Events

Jobs

Handlers

Example

FiveBeansRunner

bin/beanworker

Configuration file