taskdistrib

package module
v0.0.0-...-3d84a2e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2023 License: MIT-0 Imports: 17 Imported by: 0

README

The Fulfillment Task Distribution Function

The Fulfillment Task Distribution Function is a Cloud Function that receives Pub/Sub push messages from the Fulfillment Task Firestore Trigger Function when fulfillment task is recorded or updated.

This function maps the task description to a task (and status) specific Cloud Function and invokes that as function as a CloudEvents event handler. In other words, fulfillment task task distribution is a source of CloudEvents; if and when Google gets around to properly implementing EventArc as a true event bus for custom events that does not require two PubSub topics for every event type, we would be able to ditch the distributor and simply configure EventArc rules much as we might with AWS EventBridge.

In a real world implementation, the mapping of task type and status to task execution function would be soft configured and loaded when Fulfillment Task Distribution Function was instantiated, perhaps checked every 15 minutes, but for this POC the mapping is hard coded in the handler.go source file.

Unit Testing

Since the Task Distribution function includes code to obtain a OAuth token, and CloudEvents requires that this token must be either for a service account or a service account impersonator, a couple of hoops have to be jumped in order for unit tests to be run successfully.

See Allow Cloud Functions to Invoke Cloud Functions for instructions on how to set this up.

Documentation

Overview

Package taskdistrib implements a Google Cloud Function to receive fulfillment task descriptions via a Pub/Sub topic. The handler maps the task description to the identity of another Cloud Function that has the know how to execute the task, then invokes that function.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TaskDistributor

func TaskDistributor(w http.ResponseWriter, r *http.Request)

TaskDistributor is the Cloud Function entry point. The payload of the Pub/Sub push request is a task description expressed as a base64 encoded Protocol Buffer message wrapped in a JSON envelop.

See https://cloud.google.com/pubsub/docs/push for documentation of the request body JSON content.

func WithHttpClient

func WithHttpClient(httpClient *nethttp.Client) cehttp.Option

WithHttpClient defines an http.Option that sets the given http.Client into a CloudEvents HTTP protocol handler allowing the caller to provide a client with OAuth token authorization configure.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL