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

katar-worker-http

v0.0.2

Published

HTTP Server for interacting with polling katar workers

Downloads

3

Readme

Katar HTTP Polling Workers

Creates a HTTP server that binds to a katar server and listens for incoming workers to:

  • Distribute tasks to workers
  • Update tasks on the queue

The worker does not need to be written in node.js. It can be written in any language and on any platform that is able to do HTTP requests.

Usage

// create a katar queue server with default configuration
var katar = require('katar')();
// create a dummy queue that deletes tasks when they are done
var queue = katar.queue('queue', { persistent: false });

// create a server that workers can poll to fetch tasks
var workerServer = require('http-queue-worker')({
	katar: katar, // required
	port: 3000, // required
	host: host // optional
});

// let the workers know:
// - they should poll for tasks in this queue every 1000 milliseconds
// - the custom configuration required to execute tasks
workerServer.config(queue, { interval: 1000, custom: 'config' });

Authentication

Authentication is not supported currently. This is a big security risk if workers are not in an isolated network segment. This will be fixed in a future release.

Routes

Get configuration

Request

GET /v1/queue/:queue

Response

A json payload is returned that contains the interval at which the worker should poll the server and any other custom application level configuration.

{
	configuration: {
		// 10 seconds, specified in milliseconds
		interval: 10000,
		some: 'other',
		data: { can: { go: 'here' } },
	}
}

Poll for next queued task

Request

POST /v1/queue/:queue

{}

Response

The server sends a 204 No Content status code if there are no more tasks to execute

Otherwise, the server will send a JSON payload with a 200 OK status code. The returned response is an array of tasks that have been assigned to the worker. Currently, only one task at a time is supported due to a limitation in katar.

{
	tasks: [{ _id: 1, data: 'data' }]
}

Mark task/tasks as done

The exact same route can be used to specify when a task has been completed. Upon receiving the request, the server will issue a new task or return 204 No Content.

Request

POST /v1/queue/:queue

{
	tasks: [
	 { _id: 'abc', status: 'done' },
	 { _id: 'def', status: 'failed', error: 'some error' }
	]
}

Response

The server sends a 204 No Content status code if there are no more tasks to execute

Otherwise, the server will send a JSON payload with a 200 OK status code and a list of tasks. See Poll for next queued task above for a description of the response.

Configuration

Application specific configuration can be sent to workers for each of the queues. Any arbitrary configuration setting hash can be set based on the requirements of the application.

Polling interval

The only required configuration setting is interval which lets the workers know how often they should poll the server. By default, a 30 second interval is specified.

Example

// create a katar queue server with default configuration
var katar = require('katar')();
// create a dummy queue
var queue = katar.queue('queue', { persistent: false });

// create a server that workers can poll to fetch tasks
var workerServer = require('http-queue-worker')({
	katar: katar, // required
	port: 3000, // required
	host: host // optional
});

// queue configuration settings
workerServer.config(queue, {
	interval: 1000,
	custom: 'config',
	some: {
		more: 'config'
	},
	date: new Date()
});

Clients

Clients that interact with the server can be written in any language. Simply call a GET method to get the queue configuration, then send POST requests to fetch new tasks or mark tasks as done/failed.

Changelog

v0.0.1 - Alpha

  • Initial commit