fix(arch-043): repair indentation of cron job registration guard
This commit is contained in:
@@ -248,7 +248,7 @@ class AutomationPlugin(BasePlugin):
|
|||||||
from sqlalchemy import select as sa_select
|
from sqlalchemy import select as sa_select
|
||||||
|
|
||||||
# Get first tenant + admin user for seeding
|
# Get first tenant + admin user for seeding
|
||||||
from app.models.user import User, UserTenant
|
from app.models.user import User
|
||||||
from app.models.tenant import Tenant
|
from app.models.tenant import Tenant
|
||||||
tenant_result = await db.execute(sa_select(Tenant).limit(1))
|
tenant_result = await db.execute(sa_select(Tenant).limit(1))
|
||||||
tenant = tenant_result.scalar_one_or_none()
|
tenant = tenant_result.scalar_one_or_none()
|
||||||
@@ -388,29 +388,30 @@ class AutomationPlugin(BasePlugin):
|
|||||||
logger.exception("Failed to register contributed automation '%s' from plugin '%s'", prefixed_name, plugin_name)
|
logger.exception("Failed to register contributed automation '%s' from plugin '%s'", prefixed_name, plugin_name)
|
||||||
self._contributed_automations[plugin_name] = automation_names
|
self._contributed_automations[plugin_name] = automation_names
|
||||||
|
|
||||||
# Register cron jobs
|
# Register cron jobs (skip if no tenant exists yet)
|
||||||
cron_job_names: list[str] = []
|
cron_job_names: list[str] = []
|
||||||
for cron_def in manifest.cron_jobs:
|
if default_tenant_id is not None:
|
||||||
prefixed_name = f"{plugin_name}.{cron_def.name}"
|
for cron_def in manifest.cron_jobs:
|
||||||
cron_job_names.append(prefixed_name)
|
prefixed_name = f"{plugin_name}.{cron_def.name}"
|
||||||
try:
|
cron_job_names.append(prefixed_name)
|
||||||
# Check if cron job already exists
|
try:
|
||||||
result = await db.execute(
|
# Check if cron job already exists
|
||||||
select(AutomationCronJob).where(AutomationCronJob.name == prefixed_name).limit(1)
|
result = await db.execute(
|
||||||
)
|
select(AutomationCronJob).where(AutomationCronJob.name == prefixed_name).limit(1)
|
||||||
existing = result.scalar_one_or_none()
|
)
|
||||||
if existing is None:
|
existing = result.scalar_one_or_none()
|
||||||
await CronJobService.create(db, default_tenant_id, {
|
if existing is None:
|
||||||
"name": prefixed_name,
|
await CronJobService.create(db, default_tenant_id, {
|
||||||
"cron_expression": cron_def.cron_expression,
|
"name": prefixed_name,
|
||||||
"job_type": cron_def.job_type,
|
"cron_expression": cron_def.cron_expression,
|
||||||
"target_name": cron_def.target_name,
|
"job_type": cron_def.job_type,
|
||||||
"plugin_name": plugin_name,
|
"target_name": cron_def.target_name,
|
||||||
"is_active": True,
|
"plugin_name": plugin_name,
|
||||||
})
|
"is_active": True,
|
||||||
|
})
|
||||||
logger.info("Registered contributed cron job '%s' from plugin '%s'", prefixed_name, plugin_name)
|
logger.info("Registered contributed cron job '%s' from plugin '%s'", prefixed_name, plugin_name)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("Failed to register contributed cron job '%s' from plugin '%s'", prefixed_name, plugin_name)
|
logger.exception("Failed to register contributed cron job '%s' from plugin '%s'", prefixed_name, plugin_name)
|
||||||
self._contributed_cron_jobs[plugin_name] = cron_job_names
|
self._contributed_cron_jobs[plugin_name] = cron_job_names
|
||||||
|
|
||||||
# Register heartbeat configs
|
# Register heartbeat configs
|
||||||
|
|||||||
Reference in New Issue
Block a user