pubsub

package
v0.0.0-...-350d524 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package pubsub wraps all the pubsub API interactions that will be required by SuiteScheduler.

Package pubsub wraps all the pubsub API interactions that will be required by Kron.

Index

Constants

View Source
const (
	// MaxIdleTime is the maximum amount of time we will let the Pub/Sub receive
	// client sit idle.
	MaxIdleSeconds = 5
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Publish

type Publish struct {
	// contains filtered or unexported fields
}

Publish implements the PubsubClient interface.

func (*Publish) PublishMessage

func (c *Publish) PublishMessage(ctx context.Context, data []byte) error

PublishMessage sends the provided date to the clients pre-configured Pub/Sub topic.

type PublishClient

type PublishClient interface {
	PublishMessage(ctx context.Context, data []byte) error
}

PublishClient defines the minimum requires that this project will need of a Pub/Sub API.

func InitPublishClient

func InitPublishClient(ctx context.Context, projectID, topicID string) (PublishClient, error)

InitPublishClient returns a newly created Pub/Sub Client interface.

type ReceiveClient

type ReceiveClient interface {
	PullMessages() error
	// Deprecate: The finalize feature is now implemented by the build ingestion
	// handler.
	PullAllMessagesForProcessing(finalize func()) error
	// contains filtered or unexported methods
}

ReceiveClient defines the minimum requires that this project will need of a Pub/Sub API.

func InitReceiveClientWithTimer

func InitReceiveClientWithTimer(ctx context.Context, projectID, subscriptionID string, closeHandlerChan func(), handleMessage func(*pubsub.Message) error) (ReceiveClient, error)

InitReceiveClientWithTimer returns a newly created Pub/Sub Client interface.

type ReceiveTimer

type ReceiveTimer interface {
	Start(receiveCtxCancel context.CancelFunc, closeHandlerChan func())
	// Deprecate: The finalize feature is now implemented by the build ingestion
	// handler.
	FinalizeBeforeContextCancel(receiveCtxCancel context.CancelFunc, finalize func())
	Refresh()
	Decrement(duration time.Duration)
	// contains filtered or unexported methods
}

ReceiveTimer defines an interface with for an auto-decrementing timer.

type ReceiveWithTimer

type ReceiveWithTimer struct {
	// contains filtered or unexported fields
}

ReceiveWithTimer implements the ReceiveClient interface with an auto-decrementing timer to cap idle time.

NOTE: An idle timer is being implemented because the build reporting Pub/Sub feed is not a high QPS service so once we flush the channel, we do not expect more to arrive within the next hour(s). If any unexpectedly arrive after the receive is closed then they will be picked up in the next run.

func (*ReceiveWithTimer) PullAllMessagesForProcessing

func (r *ReceiveWithTimer) PullAllMessagesForProcessing(finalize func()) error

PullAllMessagesForProcessing pulls all messages from the Pub/Sub Subscription associated with the ReceiveWithTimer instance for processing. It begins a timer, and when it expires, it executes the provided "finalize" function and cancels the Receive client's context, ending the blocking receive operation.

func (*ReceiveWithTimer) PullMessages

func (r *ReceiveWithTimer) PullMessages() error

PullMessages does a streaming pull of all messages in the release pubsub feed.

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer implements the ReceiveTimer interface with thread-safe functionality.

func InitTimer

func InitTimer(maxSeconds int) *Timer

InitTimer returns a waiting Timer set to the maximum amount of milliseconds provided.

func (*Timer) Decrement

func (t *Timer) Decrement(duration time.Duration)

Decrement is a thread-safe function to reduce the amount of time left in the timer.

func (*Timer) FinalizeBeforeContextCancel

func (t *Timer) FinalizeBeforeContextCancel(receiveCtxCancel context.CancelFunc, finalize func())

FinalizeBeforeContextCancel starts a busy loop that will auto decrement the timer and executes finalize before cancelling the context.

Deprecate: The finalize feature is now implemented by the build ingestion handler.

func (*Timer) Refresh

func (t *Timer) Refresh()

Refresh sets the timer to the maximum amount of allotted time.

func (*Timer) Start

func (t *Timer) Start(receiveCtxCancel context.CancelFunc, closeHandlerChan func())

Start is a busy loop that will auto decrement the timer and call the provided cancel function when it has fully expired.

Jump to

Keyboard shortcuts

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