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

wendu-worker-test

v0.1.4

Published

A Typescript/Javascript client library to implement Wendu Workers

Downloads

1

Readme

wendu-worker-js

A lightweight Wendu Worker Typescript/Javascript lib for polling the Wendu Orchestration API

Worker Implementation

A worker is a micro-server that performs a task for the Wendu Orchestration engine. A woker should be implemented in the following pattern

  1. Register the TaskDefinition with a unique task name this worker performs. Task name should be lowercase with alpha-numerica chars and dashes. For example: copy-file
  2. The worker should periodically (interval) poll (GET) the API for tasks in the queue.
  3. Once a worker gets a task via polling it should immediately acknowledge (POST) it has received the task. An un-acked task will get requed for other workers.
  4. The worker should perform the unique task/work as necessary
  5. Once completed (success or failed) the result should be reported (POST) back to the API.

Installation

Install with

npm install wendu-worker-js

How to Use the Client

Create a client

Create and reuse this client. It uses https://github.com/microsoft/typed-rest-client/ under the hood for HTTP calls.

const opts: WenduApiOptions = {
	url: `http://localhost:1331`,
	pollInterval: 5*1000,
	workerIdentity: 'worker-joe',
};

const client = new WenduApiClient(opts);

Register a Task Definition

  • async register(taskDef: TaskDef): Promise<TaskDef>
await client.register({
			name: 'hello-world',
			timeoutPolicy: 'RETRY',
			timeoutSeconds: 5,
			retryLogic: 'FIXED',
			retryCount: 1,
			inputKeys: ['name', 'language'],
			outputKeys: ['greeting'],
			inputTemplate: {}
		});

Poll for Tasks

  • async poll(taskName: string, total: number): Promise<Task[] | null>
const tasks = await client.poll('move-file', 10);

Acknowledge a Task has been Received

  • async ack(task: { taskId: string }): Promise<boolean>
const acked = await client.ack(t);

Post Task Completion Results

  • async postResult(result: TaskResult): Promise<TaskResult>
const result: TaskResult = {
  status: 'COMPLETED',
  taskId: t.taskId,
  output: {
	 filePath: '//fileshare/temp/newfile.mp3'
  },
  logs: ['INFO: Moving file']
 };

await client.postResult(result);

Example Client Code

See example in /test subfolder

Getting Started: Writing a NodeJS Typescript Worker

  1. Create a new directory
  2. Use Node 10.8. nvm use 10.8.0
  3. Run npm init
  4. Run tsc --init (tsc > 3.0.3)

Use the following tsconfig.json options:

{ "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "typeRoots": [ "node_modules/@types" ]
}
  1. Run npm install --save-dev @types/node
  2. Run npm install --save-dev debug
  3. Run npm install --save wendu-worker-test
  4. Write a new worker with a new/unique task def
  5. Compile and run with tsc && DEBUG=wendu node index.js