Skip to content

Commit dd9da20

Browse files
authored
Merge pull request #90 from octue/task-emulation
Allow Task Queue Emulation
2 parents dceaf70 + 0a7b984 commit dd9da20

20 files changed

+587
-196
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252

5353
// Use 'forwardPorts' to make a list of ports inside the container available locally.
54-
"forwardPorts": [80, 443, 5000, 7045, 7046, 7047, 7048, 7049, 8000, 8080],
54+
"forwardPorts": [5432, 6379, 8000, 8132],
5555

5656
// Use 'postAttachCommand' to run commands after the container is created and attached (ie git is available).
5757
// This is preferential to postCreateCommand as invoking git (eg for private poetry installs or addition of

.devcontainer/docker-compose.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
version: '3.8'
2-
31
# Developers:
42
#
53
# This file is under version control; changes made here will affect everyone.
64
# If you need to customise just for yourself, add your personal overrides to docker-compose.developer.yml
5+
6+
# Networking:
77
#
8+
# This setup runs containers on the same network as the database container, with the
9+
# network_mode: service:db
10+
# definition. This allows "forwardPorts" in devcontainer.json to include 5432 (postgres),
11+
# 6437 (redis), 8123 (tasks emulator). Use "forwardPorts instead of "ports" properties here,
12+
# to enable forwarding from a Codespace (which doesn't work otherwise).
13+
814
services:
915
web:
1016
build:
@@ -27,9 +33,7 @@ services:
2733
# Overrides default command so things don't shut down after the process ends
2834
command: sleep infinity
2935

30-
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function to include 5432
31-
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally, because adding the "ports" property to this
32-
# file will not forward from a Codespace.
36+
# Run on the same network as the database container
3337
network_mode: service:db
3438

3539
# Use the non-root user for all processes
@@ -45,6 +49,13 @@ services:
4549
depends_on:
4650
- db
4751

52+
tasks:
53+
image: ghcr.io/aertje/cloud-tasks-emulator:latest
54+
command: -host 0.0.0.0 -port 8123 -queue "projects/octue-django-gcp/locations/europe-west1/queues/example-primary"
55+
network_mode: service:db
56+
depends_on:
57+
- db
58+
4859
db:
4960
image: postgres:13.0
5061
environment:

django_gcp/exceptions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class IncorrectTaskUsageError(Exception):
1010
"""Raised when one of the Task classes is directly instantiated, instead of subclassed"""
1111

1212

13-
class InvalidEndpointError(Exception):
14-
"""Raised when a specified endpoint isn't valid"""
13+
class InvalidTaskDomainError(Exception):
14+
"""Raised when the specified tasks domain isn't valid"""
1515

1616
def __init__(self, endpoint):
17-
message = f"The endpoint is invalid for use with a GCP pub/sub push subscription. Endpoints need to be valid and secure. ({endpoint}) "
17+
message = f"The GCP_TASKS_DOMAIN setting is invalid for use with GCP Tasks or PubSub push subscriptions. Domain must use https:// protocol in production. Given value: {endpoint}"
1818
super().__init__(message)
1919

2020

django_gcp/tasks/_patch_cloud_scheduler.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

django_gcp/tasks/_patch_cloud_tasks.py

Lines changed: 0 additions & 23 deletions
This file was deleted.

django_gcp/tasks/_pilot/README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
This module is extracted from gcp_pilot, a third party library.
44

5-
We were relying on gcp_pilot, which is mostly well engineered, to provide a better abstraction than the google cloud apis themselves. However,
6-
the authors of gcp_pilot keep shifting their python dependency range - it's super tight for no clear reason and that prevents downstream users
7-
from being abole to maintain systems. It's a headache.
5+
We were relying on gcp_pilot, which is mostly well engineered, to provide a better abstraction than the google cloud apis themselves. However, the authors of gcp_pilot keep shifting their python dependency range - it's super tight for no clear reason and that prevents downstream users from being able to maintain systems. It's a headache.
86

9-
We also have the probelm that they don't bother producing any release notes, so updating is a bear.
7+
We also have the problem that they don't bother producing any release notes, so updating is a bear.
108

11-
But, we've got very little time right now, so are simply porting some of their code here for the time being to overcome the dependency problems.
12-
We will come back and refacotr the required aspects to remove this private module.
9+
But, we've got very little time right now, so are simply porting some of their code here for the time being to overcome the dependency problems. We will come back and refactor the required aspects to remove this private module.
10+
11+
YOU SHOULD NOT IMPORT FROM OR PATCH THIS MODULE, IT IS PRIVATE AND WILL BE REMOVED WITHOUT NOTIFYING BREAKING CHANGES.

django_gcp/tasks/_pilot/app_engine.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

django_gcp/tasks/_pilot/base.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -287,25 +287,6 @@ def _unbind_email_from_policy(self, email: str, role: str, policy: Dict):
287287
return policy
288288

289289

290-
class AppEngineBasedService:
291-
# This mixin must be used for all clients that uses GCP's resources that are based on App Engine
292-
# such as Cloud Scheduler.
293-
# They have a peculiar behaviour because the App Engine, when enabled the first time,
294-
# is created in a region and this region cannot be changed ever.
295-
# So these clients cannot just choose a desired region to work on, they must use the App Engine's
296-
# previously chosen region.
297-
def _set_location(self, location: str = None):
298-
project_location = self._get_project_default_location()
299-
300-
explicit_location = location
301-
if explicit_location and explicit_location != project_location:
302-
logger.warning(
303-
f"Location {explicit_location} cannot be set in {self.__class__.__name__}. "
304-
f"It uses App Engine's default location for your project: {project_location}"
305-
)
306-
return project_location
307-
308-
309290
def friendly_http_error(func):
310291
_reasons = {
311292
"notFound": exceptions.NotFound,

django_gcp/tasks/_pilot/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class FailedPrecondition(Exception):
2121
pass
2222

2323

24+
class DoesNotExist(Exception):
25+
def __init__(self, resource):
26+
message = f"{resource} does not exist."
27+
super().__init__(message)
28+
29+
2430
class DeletedRecently(FailedPrecondition):
2531
def __init__(self, resource, blocked_period="1 week"):
2632
message = f"{resource} was probably deleted recently. Cannot reuse name for {blocked_period}."

django_gcp/tasks/_pilot/mocker.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(self, project_id: str = "potato-dev", location: str = "moon-dark1",
1818
managers = [
1919
patch("google.auth.default", return_value=(credentials, project_id)),
2020
patch("django_gcp.tasks._pilot.base.GoogleCloudPilotAPI._set_location", return_value=location),
21-
patch("django_gcp.tasks._pilot.base.AppEngineBasedService._set_location", return_value=location),
2221
]
2322
self.stack = ExitStack()
2423
for mgr in managers:

0 commit comments

Comments
 (0)