npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cababunga/beanstalkd

v0.6.1

Published

Beanstalkd client with async/await API, auto-reconnect and zero dependencies

Downloads

10

Readme

Beanstalkd Client

Node.js beanstalkd client with async/await API, auto-reconnect and zero dependencies.

Install

npm i @cababunga/beanstalkd

Example

const assert = require("node:assert").strict;
const Beanstalk = require("@cababunga/beanstalkd");

const bs = await Beanstalk.connect();
await bs.watch("test");
await bs.ignore("default");
await bs.use("test");
await bs.put(JSON.stringify({task: "make coffee"}), {ttr: 600});

const job = await bs.reserve();
const [jobId, payload] = job;
assert.equal(JSON.parse(payload.toString()).task, "make coffee");
await bs.delete(jobId);

beanstalk

Returns a Beanstalk object, a handle to communicate with beanstalkd. It take one optional parameter, which is an options object. Here are the options with their default values:

{
    host: "localhost",
    port: 11300,
    parseYaml: null,
    delay: 10,
    maxDelay: 5000,
    logger: null
}

host and port are the endpoint of your beanstalkd.

parseYaml is a function that takes YAML document and produces JavaScript object out of it. You only need to provide it if you are planning to issue beanstalkd commands that return YAML documents, such as stats, stats-tube, list-tubes, etc. These commands are mostly used in the interactive sessions and rarely in scripts. If you do not provide YAML parser, YAML response will be returned unparsed as a Buffer.

delay is an initial delay in milliseconds before new connection attempt is made after failed one. Delay will exponentially increase until it reach maxDelay value. A negative value provided for this option will make connection fail instead of attempting to connect again. If an attempt of initial connection failed connect() will throw an exception. If connection was lost after successful connect, the connection object will emit "error".

maxDelay maximum delay between connection attempts.

logger a function that can take a text message generated on successful connection, failed connection and dropped connection.

beanstalkd API methods

For most of the beanstalkd commands in form of

COMMAND arg1 arg2 ...

there is a method with signature

client.COMMAND(arg1, arg2, ...);

Please refer to the beanstalkd wire protocol documentation: https://github.com/beanstalkd/beanstalkd/blob/master/doc/protocol.txt

Exceptions are:

reserve-with-timeout command, which it issued by reserve method when you pass it an optional numeric parameter, which is a timeout in seconds.

put client.put(payload, options) takes payload as string or Buffer and a single options object. Here are the defaults:

{
    priority: 65536,
    delay: 0,
    ttr: 60
}

release `client.release(id, options={}) takes job ID and options object:

{
    priority: 65536,
    delay: 0
}

burry `client.bury(id, options={}) takes job ID and options object:

{
    priority: 65536,
}

Commands that return no data make methods that return undefined.

Commands that return a single item, typically job ID or tube count, will return that single item as a string.

Commands that return more than one item, for example reserve returns job ID and payload, will return an array.