periodic

package
v0.0.0-...-47e0bda Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: BSD-3-Clause Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// Authentication scope required for periodic triggers.
	AUTH_SCOPE = pubsub.ScopePubSub

	// PubSub topic used for periodic triggers. A single topic is used for
	// all triggers, with each message containing an attribute indicating
	// which trigger promted it.
	PUBSUB_TOPIC = "periodic-trigger"

	// Attribute sent with all pubsub messages; the name of the periodic
	// trigger which prompted the message.
	PUBSUB_ATTR_TRIGGER_NAME = "trigger"

	// Attribute sent with all pubsub messages; the unique ID of the call
	// to Trigger() which prompted the message.
	PUBSUB_ATTR_TRIGGER_ID = "id"

	// Acknowledgement deadline for pubsub messages; all TriggerCallbackFns
	// must be faster than this deadline. If this is changed, all
	// subscriptions will need to be deleted and recreated.
	PUBSUB_ACK_DEADLINE = 5 * time.Minute

	// Google Cloud project name used for pubsub.
	PUBSUB_PROJECT = "skia-public"

	// Names of periodic triggers.
	TRIGGER_NIGHTLY = "nightly"
	TRIGGER_WEEKLY  = "weekly"
)

Variables

View Source
var (
	VALID_TRIGGERS = []string{TRIGGER_NIGHTLY, TRIGGER_WEEKLY}
)

Functions

func Listen

func Listen(ctx context.Context, subscriberName string, ts oauth2.TokenSource, cb TriggerCallbackFn) error

Listen creates a background goroutine which listens for pubsub messages for periodic triggers. The subscriber name is used as part of the pubsub subscription ID; if there are multiple instances of a server which all need to receive every message, they should use different subscriber names.

func Trigger

func Trigger(ctx context.Context, triggerName, triggerId string, ts oauth2.TokenSource) error

Send a pubsub message for the given periodic trigger. The triggerId may be used for de-duplication on the subscriber side and should therefore be unique for each invocation of Trigger.

Types

type TriggerCallbackFn

type TriggerCallbackFn func(context.Context, string, string) bool

TriggerCallbackFn is a function called when handling requests for periodic triggers. The string parameters are the name of the periodic trigger and the unique ID of the call to Trigger() which generated the message. The return value determines whether or not the pubsub message should be ACK'd. If the TriggerCallbackFn returns false, it may be called again. TriggerCallbackFns must finish within the PUBSUB_ACK_DEADLINE.

Jump to

Keyboard shortcuts

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