fix blueprints not applying correctly
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
		| @ -44,10 +44,7 @@ class ApplyBlueprintMetaSerializer(PassiveSerializer): | |||||||
|             return MetaResult() |             return MetaResult() | ||||||
|         LOGGER.debug("Applying blueprint from meta model", blueprint=self.blueprint_instance) |         LOGGER.debug("Applying blueprint from meta model", blueprint=self.blueprint_instance) | ||||||
|  |  | ||||||
|         apply_blueprint.send_with_options( |         apply_blueprint(self.blueprint_instance.pk) | ||||||
|             args=(self.blueprint_instance.pk,), |  | ||||||
|             rel_obj=self.blueprint_instance, |  | ||||||
|         ).get_result(block=True) |  | ||||||
|         return MetaResult() |         return MetaResult() | ||||||
|  |  | ||||||
|  |  | ||||||
|  | |||||||
| @ -12,7 +12,7 @@ from dacite.core import from_dict | |||||||
| from django.db import DatabaseError, InternalError, ProgrammingError | from django.db import DatabaseError, InternalError, ProgrammingError | ||||||
| from django.utils.text import slugify | from django.utils.text import slugify | ||||||
| from django.utils.timezone import now | from django.utils.timezone import now | ||||||
| from django_dramatiq_postgres.middleware import CurrentTask | from django_dramatiq_postgres.middleware import CurrentTask, CurrentTaskNotFound | ||||||
| from dramatiq.actor import actor | from dramatiq.actor import actor | ||||||
| from dramatiq.middleware import Middleware | from dramatiq.middleware import Middleware | ||||||
| from structlog.stdlib import get_logger | from structlog.stdlib import get_logger | ||||||
| @ -191,7 +191,10 @@ def check_blueprint_v1_file(blueprint: BlueprintFile): | |||||||
|  |  | ||||||
| @actor(description=_("Apply single blueprint.")) | @actor(description=_("Apply single blueprint.")) | ||||||
| def apply_blueprint(instance_pk: UUID): | def apply_blueprint(instance_pk: UUID): | ||||||
|  |     try: | ||||||
|         self: Task = CurrentTask.get_task() |         self: Task = CurrentTask.get_task() | ||||||
|  |     except CurrentTaskNotFound: | ||||||
|  |         self = Task() | ||||||
|     self.set_uid(str(instance_pk)) |     self.set_uid(str(instance_pk)) | ||||||
|     instance: BlueprintInstance | None = None |     instance: BlueprintInstance | None = None | ||||||
|     try: |     try: | ||||||
|  | |||||||
| @ -41,6 +41,12 @@ class FullyQualifiedActorName(Middleware): | |||||||
|         actor.actor_name = f"{actor.fn.__module__}.{actor.fn.__name__}" |         actor.actor_name = f"{actor.fn.__module__}.{actor.fn.__name__}" | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class CurrentTaskNotFound(Exception): | ||||||
|  |     """ | ||||||
|  |     Not current task found. Did you call get_task outside a running task? | ||||||
|  |     """ | ||||||
|  |  | ||||||
|  |  | ||||||
| class CurrentTask(Middleware): | class CurrentTask(Middleware): | ||||||
|     def __init__(self): |     def __init__(self): | ||||||
|         self.logger = get_logger(__name__, type(self)) |         self.logger = get_logger(__name__, type(self)) | ||||||
| @ -55,7 +61,7 @@ class CurrentTask(Middleware): | |||||||
|     def get_task(cls) -> TaskBase: |     def get_task(cls) -> TaskBase: | ||||||
|         task = cls._TASKS.get() |         task = cls._TASKS.get() | ||||||
|         if not task: |         if not task: | ||||||
|             raise RuntimeError("CurrentTask.get_task() can only be called in a running task") |             raise CurrentTaskNotFound() | ||||||
|         return task[-1] |         return task[-1] | ||||||
|  |  | ||||||
|     def before_enqueue(self, broker: Broker, message: Message, delay: int): |     def before_enqueue(self, broker: Broker, message: Message, delay: int): | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Marc 'risson' Schmitt
					Marc 'risson' Schmitt