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

rest-agenda

v0.2.0

Published

middleware for scheduling actions

Downloads

2

Readme

REST-Agenda

NPM

Code Climate

Introduction

rest-agenda is middleware that allows the creation and management of special tasks. Think about it as an API to cron w/ persistence and clustering, not all tasks are automations. This is a dumb system.

Getting started

Mongo

Currently agenda only supports Mongo 2.6.x - <3.0 A Dockerfile is included in this project for convenience

please note that NODE_ENV must be set per environment, example files are included in the repo

$ cp .env.sample .env

then edit .env as required, the default mongo docker container does not require dbuser or dbpassword

{
  MONGOSTRING: "mongodb://<dbuser>:<dbpassword>@<domain>:<port>/<database>", // use whatever mongo connect string you need
  "NODE_ENV": "development"                                                  // set whatever environment you want
}

Start REST-Agenda

Now that we have our environment variables taken care of

Run Mongo then start the server

$ node run docker
$ node server.js                                        // if you want stdout
or
$ pm2 start server.js --name=rest-agenda --watch     // if you want the awesomeness of pm2

Start Agendash

to run agendash, in a separate process (open a new terminal window) run:

$ ./node_modules/.bin/agendash --db=mongodb://<mongouser>:<mongopass>@<mongoserver>:<mongoport>/<mongodb> --port=3001

alternatively .env may be used to specify this value

This service only exposes a single endpoint... /action

Sending a request to the agenda

Each request must be sent via POST and contain a request object. Currently only 3 keys are required

{
"when":"in 3 second",                       // a relative amount of time
"url":"http://localhost:3000/testcburl",    // a callback url (all callback urls will be requested via POST)
"name":"3 job"                              // a name for the job. unique value is encouraged, but not required
}

Using HTTP

POST /action HTTP/1.1
Host: localhost:3000
Content-Type: application/json

{
"when":"in 3 second",
"url":"http://localhost:3000/testcburl",
"name":"3 job"
}

Using cURL

curl -X POST -H "Content-Type: application/json" -d '{
"when":"in 3 second",
"url":"http://localhost:3000/testcburl",
"name":"3 job"
}' "http://localhost:3000/action"

Response objects

As REST-Agenda is really just designed to fire a dumb request to a callback URI after a set period of time, any request object sent to REST-Agenda will get sent do the callback URI specified in the original request. This can include any arbitrary JSON the original caller desires.

Below is an example of a current response object

{
  "meta": {
    "time": "2016-03-18T06:54:25.567Z",
    "request": {
      "name": "1 job",
      "data": {
        "when": "in 1 second",
        "url": "http://localhost:3000/testcburl",
        "name": "1 job"
      },
      "type": "normal",
      "priority": 0,
      "nextRunAt": "2016-03-18T06:54:26.568Z",
      "_id": "56eba62139a48fc980b3495d"
    }
  }
}

Though the original request object can be found at meta.request.data in the near future a payload key may be made available as a top level value.

Users are not be limited to a single payload key, and any key in the original request object named other than meta, when, url, or name will be passed forward as top level keys and sent to the callback url

{
  "meta": {
    "time": "2016-03-18T06:54:25.567Z",
    "request": {
      "name": "1 job",
      "data": {
        "when": "in 1 second",
        "url": "http://localhost:3000/testcburl",
        "name": "1 job",
        "foo": ["bar","baz"]            // this is the arbitrarily named payload to make available to the callback url when the scheduled event gets fired
      },
      "type": "normal",
      "priority": 0,
      "nextRunAt": "2016-03-18T06:54:26.568Z",
      "_id": "56eba62139a48fc980b3495d"
    }
  },
  "foo": ["bar","baz"]                  // this is the payload available as a top level key in the request object that gets sent to the callback url
}