function

NewTask

Define a compiled typed durable task.

Example

go
var RebuildSearch = ridu.NewTask(
  "rebuild-search",
  func(
    ctx ridu.TaskContext,
    input RebuildInput,
  ) (RebuildOutput, error) {
    // compiled application work
    return RebuildOutput{}, nil
  },
  ridu.TaskQueue("maintenance"),
  ridu.TaskRetries(
    3,
    time.Second,
    time.Minute,
    ridu.TaskBackoffExponential,
  ),
)

Arguments

ArgumentTypeDescription
slugstringThe slug value.
handlerTaskHandler[Input, Output]The handler value.
options[]TaskOptionThe options value.

Returns

The declared result.

TypedTask[Input, Output]

How it works

Add the returned definition to Config.Tasks. Input and output use strict JSON contracts, are capped by MaxTaskPayloadBytes, and never select executable code from serialized data. The backing store must implement store.TaskStore.

Full signature

func NewTask[Input, Output any]( slug string, handler TaskHandler[Input, Output], options ...TaskOption, ) TypedTask[Input, Output]

Source ridu.go:263

Related types

  • TaskHandler

    A compiled typed durable task function.

  • TaskOption

    One typed task policy option.

  • TypedTask

    A registered typed handle for durable admission, status, and cancellation.