paperap.resources.tasks module


METADATA:

File: tasks.py

Project: paperap

Created: 2025-03-04

Version: 0.0.9

Author: Jess Mann Email: jess@jmann.me

Copyright (c) 2025 Jess Mann


LAST MODIFIED:

2025-03-04 By Jess Mann

class paperap.resources.tasks.TaskStatus(*values)[source]

Bases: Enum

Status of a task.

PENDING = 'PENDING'
STARTED = 'STARTED'
RETRY = 'RETRY'
SUCCESS = 'SUCCESS'
FAILURE = 'FAILURE'
REVOKED = 'REVOKED'
class paperap.resources.tasks.TaskResource(client)[source]

Bases: StandardResource[Task, TaskQuerySet]

Resource for managing tasks.

Parameters:

client (PaperlessClient)

model_class

alias of Task

queryset_class

alias of TaskQuerySet

acknowledge(task_id)[source]

Acknowledge a task.

Parameters:

task_id (int) – ID of the task to acknowledge.

Return type:

None

bulk_acknowledge(task_ids)[source]

Acknowledge multiple tasks.

Parameters:

task_ids (list[int]) – list of task IDs to acknowledge.

Return type:

None

wait_for_task(task_id, max_wait=300, poll_interval=1.0, success_callback=None, failure_callback=None)[source]

Wait for a task to complete.

Parameters:
  • task_id (str) – The task ID to wait for.

  • max_wait (int) – Maximum time (in seconds) to wait for completion.

  • poll_interval (float) – Seconds between polling attempts.

  • success_callback (Optional[Callable[[Task], None]]) – Optional callback to execute when task succeeds.

  • failure_callback (Optional[Callable[[Task], None]]) – Optional callback to execute when task fails.

Return type:

Task

Returns:

The completed Task instance.

Raises:
wait_for_tasks(task_ids, max_wait=300, poll_interval=1.0)[source]

Wait for multiple tasks to complete.

Parameters:
  • task_ids (list[str]) – List of task IDs to wait for.

  • max_wait (int) – Maximum time (in seconds) to wait for all tasks.

  • poll_interval (float) – Seconds between polling attempts.

Return type:

dict[str, Task]

Returns:

Dictionary mapping task IDs to completed Task instances.

Raises:

APIError – If any task fails or times out.

get_task_result(task_id, wait=True, max_wait=300)[source]

Get the result of a task.

Parameters:
  • task_id (str) – The task ID.

  • wait (bool) – Whether to wait for the task to complete if it’s not already.

  • max_wait (int) – Maximum time (in seconds) to wait if wait=True.

Return type:

str | None

Returns:

The result of the task.

Raises:
execute_task(method, endpoint, data=None, max_wait=300)[source]

Execute a task synchronously.

This is a helper method that executes a task and waits for its completion.

Parameters:
  • method (str) – HTTP method (GET, POST, etc.)

  • endpoint (str) – API endpoint to call

  • data (dict[str, Any] | None) – Optional data to send with the request

  • max_wait (int) – Maximum time to wait for task completion

Return type:

Task

Returns:

The task object, once completed.

Raises:

APIError – If the task fails or times out

endpoints: ClassVar[Endpoints] = {'create': <string.Template object>, 'delete': <string.Template object>, 'detail': <string.Template object>, 'list': <string.Template object>, 'update': <string.Template object>}
client: PaperlessClient
name: str