Documentation ¶
Index ¶
Constants ¶
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 ¶
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.
Types ¶
type TriggerCallbackFn ¶
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.