Skip to content
Snippets Groups Projects

Fix issues with validation workflow schedule

Merged Karel van Klink requested to merge fix/prefix-list-email into develop
3 files
+ 35
27
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -10,11 +10,11 @@ From this list, each workflow is selected that meets the following:
import structlog
from celery import shared_task
from orchestrator.services.processes import get_execution_context
from orchestrator.services.subscriptions import TARGET_DEFAULT_USABLE_MAP
from orchestrator.services.subscriptions import TARGET_DEFAULT_USABLE_MAP, WF_USABLE_WHILE_OUT_OF_SYNC
from orchestrator.targets import Target
from gso.schedules.scheduling import CronScheduleConfig, scheduler
from gso.services.subscriptions import get_active_insync_subscriptions
from gso.services.subscriptions import get_active_subscriptions
logger = structlog.get_logger(__name__)
@@ -22,8 +22,16 @@ logger = structlog.get_logger(__name__)
@shared_task
@scheduler(CronScheduleConfig(name="Subscriptions Validator", minute="10", hour="3"))
def validate_subscriptions() -> None:
"""Validate all subscriptions using their corresponding validation workflow."""
subscriptions = get_active_insync_subscriptions()
"""Validate all subscriptions using their corresponding validation workflow.
Validation workflows only run on subscriptions that are active, even when they could be run on provisioning
subscriptions. E.g. for routers, they can manually be validated when provisioning, but are not included in this
schedule.
Validation workflows will, in principle, only run on subscriptions that are in sync. Except when a specific
validation workflow is marked as usable while out of sync in the list `WF_USABLE_WHILE_OUT_OF_SYNC`.
"""
subscriptions = get_active_subscriptions()
if not subscriptions:
logger.info("No subscriptions to validate")
return
@@ -35,18 +43,18 @@ def validate_subscriptions() -> None:
if workflow.target == Target.SYSTEM and workflow.name.startswith("validate_"):
validation_workflow = workflow.name
if validation_workflow:
# Validation workflows only run on subscriptions that are active, even when they could be run on
# provisioning subscriptions. E.g. for routers, they can manually be validated when provisioning, but are
# not included in this schedule.
usable_when = TARGET_DEFAULT_USABLE_MAP[Target.SYSTEM]
if validation_workflow:
validation_workflow_usable = (subscription.status in TARGET_DEFAULT_USABLE_MAP[Target.SYSTEM]) and (
subscription.insync or (workflow in WF_USABLE_WHILE_OUT_OF_SYNC)
)
if validation_workflow_usable:
json = [{"subscription_id": str(subscription.subscription_id)}]
if subscription.status in usable_when:
json = [{"subscription_id": str(subscription.subscription_id)}]
validate_func = get_execution_context()["validate"]
validate_func(validation_workflow, json=json)
validate_func = get_execution_context()["validate"]
validate_func(validation_workflow, json=json)
else:
if not validation_workflow:
logger.warning(
"SubscriptionTable has no validation workflow",
subscription=subscription,
Loading