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()
|
||||
LOGGER.debug("Applying blueprint from meta model", blueprint=self.blueprint_instance)
|
||||
|
||||
apply_blueprint.send_with_options(
|
||||
args=(self.blueprint_instance.pk,),
|
||||
rel_obj=self.blueprint_instance,
|
||||
).get_result(block=True)
|
||||
apply_blueprint(self.blueprint_instance.pk)
|
||||
return MetaResult()
|
||||
|
||||
|
||||
|
@ -12,7 +12,7 @@ from dacite.core import from_dict
|
||||
from django.db import DatabaseError, InternalError, ProgrammingError
|
||||
from django.utils.text import slugify
|
||||
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.middleware import Middleware
|
||||
from structlog.stdlib import get_logger
|
||||
@ -191,7 +191,10 @@ def check_blueprint_v1_file(blueprint: BlueprintFile):
|
||||
|
||||
@actor(description=_("Apply single blueprint."))
|
||||
def apply_blueprint(instance_pk: UUID):
|
||||
self: Task = CurrentTask.get_task()
|
||||
try:
|
||||
self: Task = CurrentTask.get_task()
|
||||
except CurrentTaskNotFound:
|
||||
self = Task()
|
||||
self.set_uid(str(instance_pk))
|
||||
instance: BlueprintInstance | None = None
|
||||
try:
|
||||
|
@ -41,6 +41,12 @@ class FullyQualifiedActorName(Middleware):
|
||||
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):
|
||||
def __init__(self):
|
||||
self.logger = get_logger(__name__, type(self))
|
||||
@ -55,7 +61,7 @@ class CurrentTask(Middleware):
|
||||
def get_task(cls) -> TaskBase:
|
||||
task = cls._TASKS.get()
|
||||
if not task:
|
||||
raise RuntimeError("CurrentTask.get_task() can only be called in a running task")
|
||||
raise CurrentTaskNotFound()
|
||||
return task[-1]
|
||||
|
||||
def before_enqueue(self, broker: Broker, message: Message, delay: int):
|
||||
|
Reference in New Issue
Block a user