Socket
Socket
Sign inDemoInstall

steppe

Package Overview
Dependencies
66
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.2

2

lib/db/mongo/index.js

@@ -139,3 +139,3 @@ 'use strict';

// TODO: get max error count from queue def.
if (step.errorCount >= 3) {
if (step.errorCount >= 1) {
common.getLogger().error('[job:%s] Step %s: fatal error: %s. Job failed.',

@@ -142,0 +142,0 @@ jobId, job.currentStepIndex, error)

{
"name": "steppe",
"version": "0.2.0",
"version": "0.2.2",
"description": "Simple processor for jobs that have multiple steps",

@@ -5,0 +5,0 @@ "main": "lib/steppe.js",

@@ -1,22 +0,32 @@

# Steppe - a simply queueing system for linear jobs
# Steppe - a simple queueing system for linear jobs
## OUTDATED!
## Introduction
This is outdated documentation. Please do not use this module yet.
Sometimes, you have to process a task that consists of multiple steps, and that takes a bit longer than your normal read or write operation. It can be complex to handle such a task with a series of callbacks or promises, especially if you want to be able to retry individual steps in case of failure.
```
var Steppe = require('steppe');
var steppe = new Steppe({
db: {
type: 'mongo',
uri: 'mongodb://localhost/testdb'
},
Add to that the problem of your `node.js` server restarting in the middle of such a long-lived task - for example because a new version of your code is being deployed - and you have a challenge to solve.
});
Steppe is a module that helps you perform such tasks. You can create jobs with any number of steps, and define handler functions to handle steps. The state of the job, including any amount of additional custom data, is stored in a database for persistence. Each step can be retried a few times before it's considered to have errored.
// One-time setup, at the start of your app.
## Installation
// The function that handles a step returns a promise to indicate
```npm install steppe```
## Terminology
A *step* is a single task.
A *job* is a collection of 1 or more steps, which are processed in sequence.
A *queue* defines a type of job, with its accompanying handler functions. Each job that you create, is created in a queue. This determines which handler functions will be called to process each step.
## Synopsis
```
// You need 2 handler functions: one for each step, and one for when
// the whole job has been finished.
//
// This is the step handler. It returns a promise to indicate
// whether the step has been handled successfully or not.
function handleStep(data) {
function stepHandler(data) {
var stepData = data.stepData; // The data of this specific step.

@@ -29,3 +39,3 @@ var jobData = data.jobData; // The data of the job. The same for each step.

// Perform your
// Perform the action necessary for this step.
doStuff(action, stepData, jobData)

@@ -53,16 +63,27 @@ .then(function(result) {

// This function is called either after the last child has been processed,
// or after a child has errored in a fatal way.
function handleParent(parentData) {
if (parentData.status === steppe.status.error) {
console.error('Error: %s', parentData.error);
// This is the job finished handler. It is called either after the last step has been processed,
// or after a step has errored in a fatal way.
function jobFinished(job) {
if (job.status === steppe.status.error) {
console.error('Error: %s', job.error);
}
else {
console.info('Parent %s processed successfully', parentData.id);
console.info('Job %s processed successfully', job.id);
}
}
var Steppe = require('steppe');
// One-time setup, at the start of your app.
var steppe = new Steppe({
db: {
type: 'mongo',
url: 'mongodb://localhost/testdb'
},
});
// This defines a queue to create jobs in.
steppe.defineQueue({
name : 'makePhotoAlbum',
stepHandler: handleStep,
stepHandler: stepHandler,
jobFinished: jobFinished,

@@ -72,6 +93,7 @@ period : 'every 20 seconds'

// Starts steppe. This means steppe will start looking for unfinished jobs
// to process, for each queue that you have defined.
steppe.start();
// Now you can create jobs that will be handled.
steppe.createJob({

@@ -78,0 +100,0 @@ queueName: 'makePhotoAlbum',

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc