Safety Net
This module wraps your Google Cloud Function that subscribes to cloud pubsub topics to automatically decode data payloads and republish messages when your function fails
'use strict'; const SafetyNet = ;// SafetyNet.authenticate({ projectId: 'your-project', keyFilename: '/path/to/keyfile.json' });// if, for some reason, you need to pass credentials this is how // all configurable options listed below with their defaultsSafetyNet; exportsmyFunction = SafetyNet;
The message object will flow like so:
┌──────────────────┐
│ │
│ Original PubSub │
│ Topic │◀──────────────────┐
│ │ │
└──────────────────┘ │
│ │
▼ │
┌───────────────┐ │
│ │ │
│ Your Function │ │
│ │ │
└───────────────┘ │
┌───────┐ │ ┌───────┐ │
┌────┤Success├───┴───┤Failure├─┐ │
│ └───────┘ └───────┘ ▼ │
▼ ┌────────────────┐ │
┌──────┐ │ Increment │ │
│ Exit │ │ attempt count │ │
└──────┘ └────────────────┘ │
▲ │ │
└──────┐ ┌────────┴───────┐ │
│ ▼ ▼ │
┌────────────┐ ┌───────┐ ┌───────┐ │
│failBehavior│ │ over │ │ under │ │
│ = error │◀─┬─│ retry │ │ retry │──┘
└────────────┘ │ │ limit │ │ limit │
│ └───────┘ └───────┘
│
┌────────────┐ │
│failBehavior│ │
│= republish │◀┘
└────────────┘
│
▼
┌───────────────┐
│ │
│ PubSub │
│ errorTopic │
│ │
└───────────────┘