Skip to content

Commit

Permalink
feat: add dispatch_deadline parameter to tasks_v2.Task
Browse files Browse the repository at this point in the history
  • Loading branch information
frnsimoes committed Jan 29, 2025
1 parent 933a112 commit 5dae9b4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gcp_pilot/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def push(
use_oidc_auth: bool = True,
content_type: str | None = None,
headers: dict[str, str] | None = None,
dispatch_deadline: timedelta | None = None,
) -> tasks_v2.Task:
queue_path = self.client.queue_path(
project=project_id or self.project_id,
Expand Down Expand Up @@ -81,6 +82,9 @@ def push(
),
)

if dispatch_deadline is not None:
task.dispatch_deadline = self.timedelta_to_duration(self.dispatch_deadline)

if delay_in_seconds:
target_date = datetime.now(tz=UTC) + timedelta(seconds=delay_in_seconds)
timestamp = timestamp_pb2.Timestamp()
Expand Down Expand Up @@ -116,6 +120,9 @@ def create_queue(
queue=queue,
)

def timedelta_to_duration(delta: timedelta) -> str:
return f"{int(delta.total_seconds())}s"

def get_queue(
self,
queue_name: str,
Expand All @@ -137,6 +144,7 @@ def get_task(self, queue_name: str, task_name: str, project_id: str | None = Non
)
return self.client.get_task(request=request)


def delete_task(
self,
queue_name: str,
Expand Down

0 comments on commit 5dae9b4

Please sign in to comment.