Skip to content

Commit

Permalink
fix: set tasks_max_eta default value to None
Browse files Browse the repository at this point in the history
In GCP documentation (https://cloud.google.com/tasks/docs/quotas) the maximum schedule time for a task is 30 days from current date and time.
  • Loading branch information
Iasmini Gomes authored and lucasgomide committed Jun 27, 2024
1 parent 80c689b commit 6450b00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Additionally, you can configure with more settings or environment variables:
- `DJANGO_CLOUD_TASKS_SUBSCRIBERS_URL_NAME`: Django URL-name that process Subscribers. We provide a view for that, but if you want to create your own, set this value. Default: `subscriptions-endpoint`.
- `DJANGO_CLOUD_TASKS_PROPAGATED_HEADERS`: . Default: `["traceparent"]`.
- `DJANGO_CLOUD_TASKS_PROPAGATED_HEADERS_KEY`: when propagating headers in PubSub, use a key to store the values in the Message data. Default: `_http_headers`.
- `DJANGO_CLOUD_TASKS_MAXIMUM_ETA_TASK`: maximum time in seconds to schedule a task in the future. Default: `86400`.
- `DJANGO_CLOUD_TASKS_MAXIMUM_ETA_TASK`: maximum time in seconds to schedule a task in the future. Default: `None`. In [GCP documentation](https://cloud.google.com/tasks/docs/quotas) the maximum schedule time for a task is 30 days from current date and time.

## On Demand Task

Expand Down
2 changes: 1 addition & 1 deletion django_cloud_tasks/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, *args, **kwargs):
self.delimiter = self._fetch_config(name="DELIMITER", default="--")
self.eager = self._fetch_config(name="EAGER", default=False)
self.tasks_url_name = self._fetch_config(name="URL_NAME", default="tasks-endpoint")
self.tasks_max_eta = self._fetch_config(name="MAXIMUM_ETA_TASK", default=60 * 60 * 24) # 1 day
self.tasks_max_eta = self._fetch_config(name="MAXIMUM_ETA_TASK", default=None)
self.subscribers_url_name = self._fetch_config(name="SUBSCRIBERS_URL_NAME", default="subscriptions-endpoint")

self.subscribers_max_retries = self._fetch_config(name="SUBSCRIBER_MAX_RETRIES", default=None)
Expand Down
7 changes: 5 additions & 2 deletions sample_project/sample_app/tests/tests_tasks/tests_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,13 @@ def test_task_later_delay_exceeds_maximum_eta(self):
task_kwargs = dict(price=30, quantity=4, discount=0.2)
excessive_delay = int(60 * 60 * 24 * 2) # 2 days

with self.assertRaises(ValueError) as context:
max_eta_task = 60 * 60 * 24 # 1 day
with (
patch("django_cloud_tasks.tasks.task.get_config", return_value=max_eta_task),
self.assertRaises(ValueError) as context,
):
tasks.CalculatePriceTask.later(eta=excessive_delay, task_kwargs=task_kwargs)

max_eta_task = get_config("tasks_max_eta")
self.assertEqual(f"Invalid delay time {excessive_delay}, maximum is {max_eta_task}", str(context.exception))

def test_singleton_client_on_task(self):
Expand Down

0 comments on commit 6450b00

Please sign in to comment.