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

exframe-scheduler

v2.9.3

Published

Schedules actions for state machines

Downloads

131

Readme

exframe-scheduler

A module for managing and executing scheduled state changes.

Usage

const scheduler = require('exframe-scheduler').create(stateMachine);

Configuration Settings

  • stateMachine - The name of the state machine being managed.

Methods

startProcessing

Starts polling the database for actions that need to be executed.

scheduler.startProcessing(interval, actionProcessor);

Arguments:

  • interval integer The interval, in seconds, the module will wait between database polls. (default = 60)
  • actionProcessor function Required. A callback function to execute when an action is triggered. The relevant documentActions document (see below) will be passed to the callback function.

insertOrGetDocument

Retrieves the documentActions document for the given documentNumber. Creates a documentActions document if one does not exist.

Returns a Promise that resolves with an object containing the documentActions and a flag indicating whether or not a new document was created.

scheduler.insertOrGetDocument(documentActions);

Arguments

  • documentActions object Required. A full or partial documentActions object
    • documentNumber string Required. The document number of interest.
    • actions array An array of actions objects. (default = [])
      • name string Required. The name of the action.
      • date datetime Required. The datetime the action should be executed.

Resolves with

  • new boolean true if a new documentActions document was created. Otherwise, false.
  • document object The documentActions document (see below).

Example

const result = await insertOrGetDocument({ documentNumber: policyNumber });
console.log(result);
/*
{
  new: false,
  document: {
    _id : ObjectId('5bc8d51e6f5461df54193d34'),
    documentNumber : '24-8412753-01',
    stateMachine : 'policy',
    nextRunAt : '2018-10-28T18:46:53.000Z',
    editHash : 'Oc2ajQTQop',
    lockEnd : null,
    lockId : null,
    actions : [
        {
            _id : '5bc8d522b635cb001d0799cb',
            name : 'sendNonPaymentNotice',
            date : '2018-10-28T18:46:53.000Z'
        },
        {
            _id : '5bc8d522b635cb001d0799ca',
            name : 'cancelForNonPayment',
            date : '2018-11-17T19:46:53.000Z'
        },
        {
            _id : '5bc8d522b635cb001d0799c9',
            name : 'renewPolicy',
            date : '2019-08-19T18:46:53.000Z'
        },
        {
            _id : '5bc8d522b635cb001d0799c8',
            name : 'setToNotInForce',
            date : '2019-10-18T18:46:53.000Z'
        }
    ]
  }
}  
*/

updateDocument

Updates an existing documentActions document.

Returns a promise that resolves with the new document if the update succeeded or null if the update did not occur.

scheduler.updateDocument(documentActions);

Arguments:

  • documentActions object Required. A documentActions object:
    • documentNumber string Required. The document number of interest.
    • editHash string Required. The edit hash that ensures no updates have occurred since this document was retrieved.
    • lockId string The lockId acquired when the document was locked. If the document is locked and the lockId matches, the document will be updated. Otherwise, the document will only be updated if it is not locked.
    • actions array An array of actions objects. (default = [])
      • name string Required. The name of the action.
      • date datetime Required. The datetime the action should be executed.

Example

    const result = await updateDocument('Oc2ajQTQop', { documentNumber: '24-8412753-01', actions: [], lockId: 'P-2a_QTWoi' });
    console.log(result);
    /*
    {
      _id : ObjectId('5bc8d51e6f5461df54193d34'),
      documentNumber : '24-8412753-01',
        stateMachine : 'policy',
        nextRunAt : null,
        editHash : 'Gc6a-QTQ21',
        lockEnd : '2018-10-28T18:10:23.000Z',
        lockId : 'P-2a_QTWoi',
        actions : []
      }
    }  
    */

lockDocument

Locks an existing documentActions document for a specified amount of time, indicating to other processes that something else is working on it.

Returns a promise that resolves with the lockId if the lock was successful or null if a lock was not able to be obtained.

scheduler.lockDocument(documentNumber, timeout);

Arguments:

  • documentNumber string Required. The documentNumber of the document of interest.
  • timeout integer The amount of time for which to lock the document in seconds. (default = 600)

Example

    const result = await lockDocument('24-8412753-01', 120);
    console.log(result);
    /*
    {
      lockId: 'Oc2ajQTQop'
    }  
    */

unlockDocument

Unlocks an existing documentActions document.

Returns a promise that resolves with the object { lockId: null }, indicating that the document has been unlocked when successful, or null if unsuccessful.

scheduler.unlockDocument(documentNumber, lockId);

Arguments:

  • documentNumber string Required. The documentNumber of the document of interest.
  • lockId string The lockId obtained when the document was initially locked.

Example

    const result = await unlockDocument('24-8412753-01', 'Oc2ajQTQop');
    console.log(result);
    /*
    {
      lockId: null
    }  
    */

countActiveDocuments

Counts documentactions where nextRunAt != null.

Returns a promise that resolves with an integer, indicating the number of document actions meeting the criteria.

scheduler.countActiveDocuments(args);

Arguments:

  • earliest string Optional. The earliest (inclusive) nextRunAt DateTime to consider in the count.
  • latest string Optional. The latest (inclusive) nextRunAt DateTime to consider in the count.

Example

    const result = await countActiveDocuments({ earliest: '2020-01-01T04:00:00.000Z', latest: '2020-02-01T03:59:59.999Z'});
    console.log(result);
    /*
      452  
    */