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

oneoff

v0.1.1

Published

Manage running one-off tasks for Cloud Foundry applications

Downloads

6

Readme

oneoff

Manage running one-off tasks for NodeJS applications on Cloud Foundry.

Cloud Foundry doesn't provide access to the host machine or bound services running your application. This makes running manual configuration tasks (initialize this database, upgrade this table schema, etc.) during deployment a challenge...

There are a number of ways to ~~hack~~ work around this but they rely on manual deployment steps, e.g. temporarily deploy a single instance of your application with a custom start command. Yuck.

Using oneoff, you define your tasks as code which are automatically run during the normal deployment.

oneoff provides the following features...

  • ensure tasks are completed before application startup
  • coordinating app instances to ensure at-most once task execution
  • automagically discovering tasks from the task directory
  • dependency ordering, ensure task a completes before task b starts
  • parallel task execution
  • ignore completed tasks in future deployments

No more snowflake ops.

install

usage

Once onceoff has been installed, you will need to write your tasks and then hook the module into your application startup.

defining tasks

Tasks are NodeJS modules that implement the following interface:

name, done & task are mandatory attributes, order is optional and defaults to zero.

done will execute callback with two arguments, the error parameter (or null) and the boolean value with the results of the test which determines whether the task has been executed previously.

task will execute callback with one argument, the error parameter or null, when the task has finished.

For example, creating a new task to set up the database schema for our application would follow the outline below.

These modules will be loaded using require() at runtime and executed according to the following ordering rules.

  1. Tasks with the same order value are executed concurrently.
  2. Tasks with order value N will only be executed when all tasks with order value < N have finished.
  3. Tasks without an explicitly order property defined are assigned the default order value (0).

All tasks must live under the same parent directory. Files without the ".js" postfix or with the . prefix will be ignored.

Any NPM packages defined in your package.json will be available to your tasks.

application startup

Set the oneoff command to run before your application starts, e.g. using prestart or start NPM scripts.

By default, oneoff will search for tasks under the ./lib/tasks directory. This location can be modified using the --tasks ./path/to/tasks command line argument.

If the oneoff command has been correctly registered into application startup, the following log entries should appear:

Errors from the tasks will cause the command to exit with a failure status code and force the application startup to fail.

limitations

Cloud Foundry default application startup time is limited to sixty seconds. If task execution pushes the startup time over this threshold, the health check will restart the application.

This value can be increased to a maximum of three minutes using the timeout property in the application manifest.

tests