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
// Will return 400 if someone tries to post an invalid payload { if !dataabout throw 400 'validation' 'Data must contain about attribute'; } // Send the job to the email and airtable controller for processing async { return Promiseall // Pass the key of this record to the other controllers thiscontrollersemail thiscontrollersairtable } async { // Load the record that was passed in const payload = await this; ; } async { const payload = await this; airtables; }
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
- Install gcloud command line
gcloud auth logingcloud config set project <your project id># List available zones to deploy functions gcloud functions regions listgcloud 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 = ; await ;
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,
}