Documentation ¶
Index ¶
- Variables
- func Handler() (string, http.Handler)
- type ExternalTask
- type Function
- func (f *Function) Call(ctx context.Context, queue Queue, payload interface{}, opts ...TaskOption) error
- func (f *Function) CallTask(ctx context.Context, queue Queue, payload interface{}, opts ...TaskOption) (*Task, error)
- func (f *Function) Task(payload interface{}, opts ...TaskOption) (*Task, error)
- func (f *Function) TestCall(t *testing.T, payload interface{}) error
- type Queue
- type QueueOption
- type Task
- type TaskFn
- type TaskOption
Constants ¶
This section is empty.
Variables ¶
var ErrCannotSendTask = errors.New("cloudtasks: cannot send task")
ErrCannotSendTask is returned from a Send call when the task has been correctly prepared but cannot be sent to the remote service. It can give you an opportunity to call the underlying implementation directly instead.
Functions ¶
Types ¶
type ExternalTask ¶ added in v0.2.0
ExternalTask should be filled with the data of the task to call in an external Cloud Run application.
func (*ExternalTask) LogValue ¶ added in v0.3.0
func (task *ExternalTask) LogValue() slog.Value
LogValue implements slog.LogValuer.
type Function ¶
type Function struct {
// contains filtered or unexported fields
}
Function is a stored task implementation.
func (*Function) Call ¶
func (f *Function) Call(ctx context.Context, queue Queue, payload interface{}, opts ...TaskOption) error
Call builds a task invocation and directly sends it individually to the queue.
If you are going to send multiple tasks at the same time is more efficient to build all of them with Task() first and then send them in batches with queue.SendTasks(). If sending a single task this function will be similar in performance to the batch method described before.
func (*Function) CallTask ¶
func (f *Function) CallTask(ctx context.Context, queue Queue, payload interface{}, opts ...TaskOption) (*Task, error)
CallTask builds a task invocation, sends it and returns the built task.
func (*Function) Task ¶
func (f *Function) Task(payload interface{}, opts ...TaskOption) (*Task, error)
Task builds a task invocation to the function. You can later send the task in batches using queue.SendTasks() or directly invoke Call() to make both things at the same time.
The payload can be a proto.Message or any other kind of interface that can be serialized to JSON. It would then be read on the task.
type Queue ¶
type Queue interface { // Send a new task to the queue. Send(ctx context.Context, task *Task) error // SendExternal sends a new task to an external URL. SendExternal(ctx context.Context, task *ExternalTask) error }
Queue abstract any remote or local system that can execute a task.
func NewQueue ¶
func NewQueue(runProjectHash string, name string, opts ...QueueOption) Queue
NewQueue initializes a new queue. It needs: - The Cloud Run project hash. For example if you have URLs like "https://foo-service-9omj3qcv6b-ew.a.run.app/" the hash will be "9omj3qcv6b". - The queue name.
type QueueOption ¶
type QueueOption func(*gcloudQueue)
QueueOption configures queues when creating them.
func WithRegion ¶
func WithRegion(region string) QueueOption
WithRegion configures a custom region for the queue. By default it will use the region of the Cloud Run service.
type Task ¶
type Task struct { // Read only. The current retry count. Retries int64 // contains filtered or unexported fields }
Task is a task sent or receieved from a queue.
type TaskOption ¶
type TaskOption func(task *Task)
TaskOption configures tasks when creating them.
func WithName ¶
func WithName(name string) TaskOption
WithName configures a custom name for the task. By default it will be autogenerated. A custom name could be problematic with tombstones (task names that can't be repeated) and concurrency controls, so assign it with care and read Google Cloud Tasks documentation before using it.