# prism.task.PrismTask

## Constructor

<details>

<summary><code>prism.task.PrismTask</code></summary>

*`class`*` ``prism.task.PrismTask(`*`bool_run: bool = True, func: Optional[Callable[..., Any]] = None`*`)`

* **Parameters**
  * `bool_run`: a boolean indicating whether to run the task. Default is `True`.
  * `func`: optional callable that overwrites the `run` function. Default is `None`.

</details>

{% hint style="warning" %}
**Warning**: you will *never* need to worry about instantiating a `PrismTask` class and setting `bool_run` / `func` when working with your tasks. This is all handled on the backend.
{% endhint %}

## Methods

<details>

<summary><code>PrismTask.done(tasks: TaskManager, hooks: PrismHooks) -> bool</code></summary>

Check if this task is already done. If this task is already done, then the task will be skipped. If not, it will be executed.

Note that if the `--full-refresh` option is specified, then all tasks are run from scratch (even the ones that are done).

* Parameters
  * `tasks`: Instance of the [TaskManager](https://docs.runprism.com/v0.2.4/api-reference/taskmanager) class. This allows users to reference the output of other tasks within their task.
  * `hooks`: Instance of the [PrismHooks](https://docs.runprism.com/v0.2.4/api-reference/prismhooks) class. This allows users to access adapter connections using a low-level API.
* Outputs:
  * `True` if the task is already done. `False` otherwise.

</details>

<details>

<summary><code>PrismTask.run(tasks: TaskManager, hooks: PrismHooks) -> Any</code></summary>

Core logic for your task. This task must return a non-null output.

* Parameters
  * `tasks`: Instance of the [TaskManager](https://docs.runprism.com/v0.2.4/api-reference/taskmanager) class. This allows users to reference the output of other tasks within their task.
  * `hooks`: Instance of the [PrismHooks](https://docs.runprism.com/v0.2.4/api-reference/prismhooks) class. This allows users to access adapter connections using a low-level API.
* Outputs:
  * Any non-null output.

</details>

## Attributes and underlying data

<details>

<summary><code>PrismTask.RETRIES</code></summary>

Number of times to retry a task upon failure. Default is 0.

```python
# tasks/example_task.py

import prism.task

class ExampleTask(prism.task.PrismTask):
    
    RETRIES = 1
    
    def run(self, tasks, hooks):
        test_str = "Hello, world!"
        return test_str
```

</details>

<details>

<summary><code>PrismTask.RETRY_DELAY_SECONDS</code></summary>

Number of seconds to wait in between task retries. Default is 0. Must be specified alongside [`RETRIES`](#prismtask.retries).

```python
# tasks/example_task.py

import prism.task

class ExampleTask(prism.task.PrismTask):
    
    RETRIES = 1
    RETRY_DELAY_SECONDS = 60
    
    def run(self, tasks, hooks):
        test_str = "Hello, world!"
        return test_str
```

</details>
