function

NewTask

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

Define a compiled typed durable task.

Source ridu.go:199

@param slug
The slug value.
@param handler
The handler value.
@param options
The options value.
@returns
The declared result.

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.

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,
  ),
)

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.