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(name string, opts ...QueueOption) Queue
NewQueue initializes a new queue.
type QueueOption ¶
type QueueOption func(*gcloudQueue)
QueueOption configures queues when creating them.
func WithForcedProductionMode ¶ added in v1.3.4
func WithForcedProductionMode() QueueOption
WithForcedProductionMode forces the queue to use the production mode. This is useful for testing purposes.
func WithHostname ¶ added in v1.1.1
func WithHostname(hostname string) QueueOption
WithHostname configures the queue for an application outside of Cloud Run. Pass only the hostname, without the protocol or trailing slash.
func WithProject ¶ added in v1.3.4
func WithProject(project, numericProject string) QueueOption
WithProject configures the project and numeric project ID for the queue. By default it will use the project and numeric project ID obtained from the metadata server.
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.
func WithServiceAccountEmail ¶ added in v1.3.4
func WithServiceAccountEmail(serviceAccountEmail string) QueueOption
WithServiceAccountEmail configures the service account email for the queue. By default it will use the default service account email obtained from the metadata server.
type Task ¶
type Task struct {
// Read only. The current retry count.
Retries int64
// Queue that received the task.
Queue Queue
// 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 WithDelay ¶ added in v1.3.5
func WithDelay(delay time.Duration) TaskOption
WithDelay schedules the task to run after the given delay. This overrides the schedule time.
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.
func WithScheduleTime ¶ added in v1.3.5
func WithScheduleTime(time time.Time) TaskOption
WithScheduleTime schedules the task to run at the given time.