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

@ambassify/queue

v1.1.8

Published

Queue implementation for node

Downloads

147

Readme

Queue

CircleCI

This library acts as a wrapper around different queue implementations that we might end up using.

Currently implemented backends: SQS

API

The public API that each queue exposes is defined as in Queue. An implementation for a new backend can be created using a new class that extends the public API. The public API is:

  • Queue.create( QueueType : class, ...args ) args is passed to the constructor of the QueueType.
  • constructor( queueName : string, options : object )
  • Available options are: itemPoolSize : int
  • getName() : string
  • getItemPool() : ItemPool ( see item-pool.js )
  • receive( count : int ) : Promise Attempt to receive at most count items
  • release( item : object, handled : boolean ) : Promise Release the item, if not handled the item will not be deleted from the queue. handled defaults to false.
  • touch( item : object, options : object ) : Promise touch / ping a message to keep it in use.
  • send( body : object ) : Promise submit a new queue item
  • connect() : Promise
  • start() : Promise Start watching the queue for new items
  • stop() : void Stop watching the queue for new items, a final batch might still arrive after calling stop()
  • lock( item : object, options: object ) : Promise Prevents a message from re-entering the queue.
  • unlock( item : object ) : Promise Release an earlier acquired lock.
  • on( event : string, callback : function ) : void Attach an eventhandler to the queue.
  • message event is triggered for each queue item that arrives.
  • error event is triggered for errors in the _eventLoop or _lock.

The public API will then call into the implementation specific methods through an internal API that each implementation should implement. The required private methods are:

  • _fetch( itemsToFetch : int ) : Promise Request itemsToFetch items from the queue. Do not perform any mutations on the raw object before resolving them.
  • _transform( item : object ) : object This method will receive the items retrieved using _fetch one by one, you can return altered objects from this method to change the queue items.
  • _delete( item : object ) : Promise Remove the item from the queue / mark as finished. This method should always receive the instance from the _transform step, such that you could add hidden fields to identify the item.
  • _touch( item : object, options: object ) : Promise Touch the message to keep it from becoming visible again.
  • _send( item : object ) : Promise Add item to the queue.
  • _connect() : Promise Start to connect with the backend.
  • _lock() : Promise Prevents a message from re-entering the queue. Default implementation uses queue.touch.
  • _unlock() : Promise Releases the lock and allows the item to re-enter the queue.

Libraries

  • BatchOperation Utility to batch batchSize items unless timeout expires. The SQS implementation uses this to batch delete and send operations.
  • ItemPool Currently only a counter which ensure no more than the poolsize amount of items are in flight.
  • sleep Returns a promise that resolves after a timeout.

Runtime configuration options

Configuration can be done through environment variables, options are:

  • BATCH_SIZE defaults to 10
  • QUEUE_POOL_SIZE defaults to 20
  • SQS_AWS_REGION defaults to AWS_REGION environment variable.
  • SQS_FETCH_WAIT defaults to 20 seconds