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

airblast

v0.2.2

Published

Robust cloud function job processors up in minutes

Downloads

9

Readme

Airblast provides a simple framework to get cloud function jobs with retries up and running quickly so you can focus on building your jobs with minimal effort on interacting with cloud infrastructure.

Airblast handles dealing with pubub, express and datastore and you just handle processing the data.

The framework allows for building controllers that send jobs to one another for processing so you can logically breakup your background processing by logical concerns.

See the samples for examples of setting up simple controllers

Example of job chains

class JobController extends AirblastController {
  // Will return 400 if someone tries to post an invalid payload
  validate({ data }) {
    if (!data.about) {
      throw new this.AppError(400, 'validation', 'Data must contain about attribute');
    }
  }

  // Send the job to the email and airtable controller for processing
  async process({ key }) {
    return Promise.all([
      // Pass the key of this record to the other controllers
      this.controllers.email.enqueue({ key }),
      this.controllers.airtable.enqueue({ key }),      
    ])
  }
}

class EmailController extends AirblastController {
  async process({ data }) {
    // Load the record that was passed in
    const payload = await this.load(data.key);
    sendEmail({
      to: '[email protected]',
      subject: 'Job received',
      body: `The job is about ${data.about}`
    });
  }
}

class AirtableController extends AirblastController {
  async process({ data }) {
    const payload = await this.load(data.key);
    airtables.insert(payload);
  }
}

That's it, once you've written your process function, you've written cloud functions that are ready to deploy! See the sample directory for scripts to deploy them.

Setting up for deployment

  1. Install gcloud command line
gcloud auth login
gcloud config set project <your project id>
# List available zones to deploy functions
gcloud functions regions list
gcloud config set functions/region <preferred region>
# If you are also deploying the retry cron server, you will
# probably want to set the default app engine zone to the same
gcloud compute project-info add-metadata --metadata google-compute-default-region=<preferred region>
# Re-run gcloud init to make use of your new defaults
gcloud init

Testing

Most of the time you can test your controller simply by running controller.process(body) but if you need to test the webhook endpoint with authorization and validation, there is a helper to help you:

const runController = require('airblast/test/runController');

await runController(new MyController(), {
  body: { my: 'value' },
});

Options and default values that you can pass to

{
  // The controller function to execute (defaults to the function that receives and routes
  // the http requests, usuall you don't need to change this)
  function: 'http',
  // Mock the enqueue (avoids the need for datastore & pubsub emulators)
  mockEnqueue: true,
  // Throw an error if the response status is not 200
  throwOnError: true,
}