Compare commits
2 Commits
blueprints
...
blueprint-
Author | SHA1 | Date | |
---|---|---|---|
563c274d70 | |||
a9fee67b44 |
@ -5,8 +5,9 @@ from hashlib import sha512
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from sys import platform
|
from sys import platform
|
||||||
|
|
||||||
|
import pglock
|
||||||
from dacite.core import from_dict
|
from dacite.core import from_dict
|
||||||
from django.db import DatabaseError, InternalError, ProgrammingError
|
from django.db import DatabaseError, InternalError, ProgrammingError, connection
|
||||||
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.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
@ -152,6 +153,18 @@ def blueprints_find() -> list[BlueprintFile]:
|
|||||||
@prefill_task
|
@prefill_task
|
||||||
def blueprints_discovery(self: SystemTask, path: str | None = None):
|
def blueprints_discovery(self: SystemTask, path: str | None = None):
|
||||||
"""Find blueprints and check if they need to be created in the database"""
|
"""Find blueprints and check if they need to be created in the database"""
|
||||||
|
with pglock.advisory(
|
||||||
|
lock_id=f"goauthentik.io/{connection.schema_name}/blueprints/discovery",
|
||||||
|
timeout=0,
|
||||||
|
side_effect=pglock.Return,
|
||||||
|
) as lock_acquired:
|
||||||
|
if not lock_acquired:
|
||||||
|
LOGGER.debug("Not running blueprint discovery, lock was not acquired")
|
||||||
|
self.set_status(
|
||||||
|
TaskStatus.SUCCESSFUL,
|
||||||
|
_("Blueprint discovery lock could not be acquired. Skipping discovery."),
|
||||||
|
)
|
||||||
|
return
|
||||||
count = 0
|
count = 0
|
||||||
for blueprint in blueprints_find():
|
for blueprint in blueprints_find():
|
||||||
if path and blueprint.path != path:
|
if path and blueprint.path != path:
|
||||||
@ -197,6 +210,18 @@ def check_blueprint_v1_file(blueprint: BlueprintFile):
|
|||||||
def apply_blueprint(self: SystemTask, instance_pk: str):
|
def apply_blueprint(self: SystemTask, instance_pk: str):
|
||||||
"""Apply single blueprint"""
|
"""Apply single blueprint"""
|
||||||
self.save_on_success = False
|
self.save_on_success = False
|
||||||
|
with pglock.advisory(
|
||||||
|
lock_id=f"goauthentik.io/{connection.schema_name}/blueprints/apply/{instance_pk}",
|
||||||
|
timeout=0,
|
||||||
|
side_effect=pglock.Return,
|
||||||
|
) as lock_acquired:
|
||||||
|
if not lock_acquired:
|
||||||
|
LOGGER.debug("Not running blueprint discovery, lock was not acquired")
|
||||||
|
self.set_status(
|
||||||
|
TaskStatus.SUCCESSFUL,
|
||||||
|
_("Blueprint apply lock could not be acquired. Skipping apply."),
|
||||||
|
)
|
||||||
|
return
|
||||||
instance: BlueprintInstance | None = None
|
instance: BlueprintInstance | None = None
|
||||||
try:
|
try:
|
||||||
instance: BlueprintInstance = BlueprintInstance.objects.filter(pk=instance_pk).first()
|
instance: BlueprintInstance = BlueprintInstance.objects.filter(pk=instance_pk).first()
|
||||||
|
Reference in New Issue
Block a user