{"modulePath":"github.com/microsoft/durabletask-go","version":"v0.6.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package task\n\n## Variables\n\n```go\nvar ErrTaskBlocked = errors.New(\"the current task is blocked\")\n```\nErrTaskBlocked is not an error, but rather a control flow signal indicating that an orchestrator function has executed as far as it can and that it now needs to unload, dispatch any scheduled tasks, and commit its current execution progress to durable storage.\n\n```go\nvar ErrTaskCanceled = errors.New(\"the task was canceled\") // CONSIDER: More specific info about the task\n\n```\nErrTaskCanceled is used to indicate that a task was canceled. Tasks can be canceled, for example, when configured timeouts expire.\n\n## Functions\n\n```go\nfunc NewTaskExecutor(registry *TaskRegistry) backend.Executor\n```\nNewTaskExecutor returns a [backend.Executor](/github.com/microsoft/durabletask-go/backend#Executor) implementation that executes orchestrator and activity functions in-memory.\n\n```go\nfunc WithActivityInput(input any) callActivityOption\n```\nWithActivityInput configures an input for an activity invocation. The specified input must be JSON serializable.\n\n```go\nfunc WithActivityRetryPolicy(policy *RetryPolicy) callActivityOption\n```\n\n```go\nfunc WithRawActivityInput(input string) callActivityOption\n```\nWithRawActivityInput configures a raw input for an activity invocation.\n\n```go\nfunc WithRawSubOrchestratorInput(input string) subOrchestratorOption\n```\nWithRawSubOrchestratorInput is a functional option type for the CallSubOrchestrator orchestrator method that takes a raw input value.\n\n```go\nfunc WithSubOrchestrationInstanceID(instanceID string) subOrchestratorOption\n```\nWithSubOrchestrationInstanceID is a functional option type for the CallSubOrchestrator orchestrator method that specifies the instance ID of the sub-orchestration.\n\n```go\nfunc WithSubOrchestrationRetryPolicy(policy *RetryPolicy) subOrchestratorOption\n```\n\n```go\nfunc WithSubOrchestratorInput(input any) subOrchestratorOption\n```\nWithSubOrchestratorInput is a functional option type for the CallSubOrchestrator orchestrator method that takes an input value and marshals it to JSON.\n\n## Types\n\n```go\ntype Activity func(ctx ActivityContext) (any, error)\n```\nActivity is the functional interface for activity implementations.\n\n```go\ntype ActivityContext interface {\n\tGetInput(resultPtr any) error\n\tContext() context.Context\n}\n```\nActivityContext is the context parameter type for activity implementations.\n\n```go\ntype ContinueAsNewOption func(*OrchestrationContext)\n```\nContinueAsNewOption is a functional option type for the ContinueAsNew orchestrator method.\n\n```go\nfunc WithKeepUnprocessedEvents() ContinueAsNewOption\n```\nWithKeepUnprocessedEvents returns a ContinueAsNewOptions struct that instructs the runtime to carry forward any unprocessed external events to the new instance.\n\n```go\ntype OrchestrationContext struct {\n\tID             api.InstanceID\n\tName           string\n\tIsReplaying    bool\n\tCurrentTimeUtc time.Time\n\t// contains filtered or unexported fields\n}\n```\nOrchestrationContext is the parameter type for orchestrator functions.\n\n```go\nfunc NewOrchestrationContext(registry *TaskRegistry, id api.InstanceID, oldEvents []*protos.HistoryEvent, newEvents []*protos.HistoryEvent) *OrchestrationContext\n```\nNewOrchestrationContext returns a new [OrchestrationContext](#OrchestrationContext) struct with the specified parameters.\n\n```go\nfunc (ctx *OrchestrationContext) CallActivity(activity interface{}, opts ...callActivityOption) Task\n```\nCallActivity schedules an asynchronous invocation of an activity function. The \\[activity] parameter can be either the name of an activity as a string or can be a pointer to the function that implements the activity, in which case the name is obtained via reflection.\n\n```go\nfunc (ctx *OrchestrationContext) CallSubOrchestrator(orchestrator interface{}, opts ...subOrchestratorOption) Task\n```\n\n```go\nfunc (ctx *OrchestrationContext) ContinueAsNew(newInput any, options ...ContinueAsNewOption)\n```\n\n```go\nfunc (ctx *OrchestrationContext) CreateTimer(delay time.Duration) Task\n```\nCreateTimer schedules a durable timer that expires after the specified delay.\n\n```go\nfunc (octx *OrchestrationContext) GetInput(v any) error\n```\nGetInput unmarshals the serialized orchestration input and stores it in \\[v].\n\n```go\nfunc (octx *OrchestrationContext) SetCustomStatus(cs string)\n```\n\n```go\nfunc (ctx *OrchestrationContext) WaitForSingleEvent(eventName string, timeout time.Duration) Task\n```\nWaitForSingleEvent creates a task that is completed only after an event named \\[eventName] is received by this orchestration or when the specified timeout expires.\n\nThe \\[timeout] parameter can be used to define a timeout for receiving the event. If the timeout expires before the named event is received, the task will be completed and will return a timeout error value [ErrTaskCanceled](#ErrTaskCanceled) when awaited. Otherwise, the awaited task will return the deserialized payload of the received event. A Duration value of zero returns a canceled task if the event isn't already available in the history. Use a negative Duration to wait indefinitely for the event to be received.\n\nOrchestrators can wait for the same event name multiple times, so waiting for multiple events with the same name is allowed. Each event received by an orchestrator will complete just one task returned by this method.\n\nNote that event names are case-insensitive.\n\n```go\ntype Orchestrator func(ctx *OrchestrationContext) (any, error)\n```\nOrchestrator is the functional interface for orchestrator functions.\n\n```go\ntype RetryPolicy struct {\n\t// Max number of attempts to try the activity call, first execution inclusive\n\tMaxAttempts int\n\t// Timespan to wait for the first retry\n\tInitialRetryInterval time.Duration\n\t// Used to determine rate of increase of back-off\n\tBackoffCoefficient float64\n\t// Max timespan to wait for a retry\n\tMaxRetryInterval time.Duration\n\t// Total timeout across all the retries performed\n\tRetryTimeout time.Duration\n\t// Optional function to control if retries should proceed\n\tHandle func(error) bool\n}\n```\n\n```go\nfunc (policy *RetryPolicy) Validate() error\n```\n\n```go\ntype Task interface {\n\tAwait(v any) error\n}\n```\nTask is an interface for asynchronous durable tasks. A task is conceptually similar to a future.\n\n```go\ntype TaskRegistry struct {\n\t// contains filtered or unexported fields\n}\n```\nTaskRegistry contains maps of names to corresponding orchestrator and activity functions.\n\n```go\nfunc NewTaskRegistry() *TaskRegistry\n```\nNewTaskRegistry returns a new [TaskRegistry](#TaskRegistry) struct.\n\n```go\nfunc (r *TaskRegistry) AddActivity(a Activity) error\n```\nAddActivity adds an activity function to the registry. The name of the activity function is determined using reflection.\n\n```go\nfunc (r *TaskRegistry) AddActivityN(name string, a Activity) error\n```\nAddActivityN adds an activity function to the registry with a specified name.\n\n```go\nfunc (r *TaskRegistry) AddOrchestrator(o Orchestrator) error\n```\nAddOrchestrator adds an orchestrator function to the registry. The name of the orchestrator function is determined using reflection.\n\n```go\nfunc (r *TaskRegistry) AddOrchestratorN(name string, o Orchestrator) error\n```\nAddOrchestratorN adds an orchestrator function to the registry with a specified name.\n\n","path":"github.com/microsoft/durabletask-go/task","name":"task","synopsis":"","isRedistributable":true}
