---
title: "workflows.SubmitSubtask"
description: "Submit a subtask to the runner."
image: "https://tilebox.com/images/tilebox-docs-social-preview.png"
---

> Documentation Index
> Fetch the complete documentation index at: https://tilebox.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# workflows.SubmitSubtask

import { Fragment } from "astro/jsx-runtime";

import ApiReference from "@docs/components/ApiReference.astro";

import ParamField from "@docs/components/ParamField.astro";

```go
workflows.SubmitSubtask(
	ctx context.Context,
	task workflows.Task,
	options ...subtask.SubmitOption,
) (subtask.FutureTask, error)
```

Submit a subtask to the runner.

This function is intended to be used in tasks.

## Parameters

**task**

type: Task

A subtask to submit
**options**

type: []subtask.SubmitOption

Options for the subtask

## Options

**WithDependencies(dependencies ...FutureTask)**

Set dependencies for the task
**WithClusterSlug(clusterSlug string)**

default: cluster of the runner

Set the cluster slug of the cluster where the task will be executed.
**WithMaxRetries(maxRetries int64)**

default: 0

Set the maximum number of [retries](/docs/workflows/concepts/tasks#retry-handling) for the subtask in case it fails
**WithOptional()**

default: false

Mark the subtask as [optional](/docs/workflows/concepts/tasks#optional-tasks). An optional subtask will not fail the job if it fails. Tasks that depend on it will still execute even if it failed.

## Returns

A future task that can be used to set dependencies between tasks.

<h2 id="request-example">Usage example</h2>

```go

type MySubTask struct {
	Sensor string
	Value  float64
}

type Task struct{}

func (t *Task) Execute(ctx context.Context) error {
	err := workflows.SubmitSubtask(ctx, 
		&MySubTask{
			Sensor: "A",
			Value:  42,
		},
	)
	if err != nil {
		return fmt.Errorf("failed to submit subtasks: %w", err)
	}

	return nil
}
```

Source: https://tilebox.com/docs/api-reference/go/workflows/SubmitSubtask/index.mdx
