Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/dispatch/tag/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,41 @@
"""
import logging

from schedule import every
from typing import NoReturn

from dispatch.database.core import SessionLocal
from dispatch.decorators import scheduled_project_task
from dispatch.incident import service as incident_service
from dispatch.plugin import service as plugin_service
from dispatch.project.models import Project
from dispatch.scheduler import scheduler
from dispatch.incident import service as incident_service
from dispatch.tag import service as tag_service
from dispatch.tag.models import TagCreate
from dispatch.tag.recommender import build_model
from schedule import every

log = logging.getLogger(__name__)


@scheduler.add(every(1).hour, name="tag-sync")
@scheduled_project_task
def sync_tags(db_session: SessionLocal, project: Project):
def sync_tags(db_session: SessionLocal, project: Project) -> NoReturn:
"""Syncs tags from external sources."""
plugin = plugin_service.get_active_instance(
db_session=db_session, plugin_type="tag", project_id=project.id
db_session=db_session,
project_id=project.id,
plugin_type="tag",
)

if not plugin:
log.debug(f"No active plugins were found. PluginType: 'tag' ProjectId: {project.id}")
log.warning(
f"Tags not synced using external sources. No tag plugin enabled in {project.name} project."
)
return

log.debug(f"Getting tags via: {plugin.plugin.slug}")
log.debug(f"Fetching tags using {plugin.plugin.slug} plugin...")
for t in plugin.instance.get():
log.debug(f"Adding Tag. Tag: {t}")
log.debug(f"Adding tag {t}...")

# we always use the plugin project when syncing
t["tag_type"].update({"project": project})
Expand All @@ -44,7 +50,7 @@ def sync_tags(db_session: SessionLocal, project: Project):

@scheduler.add(every(1).hour, name="tag-model-builder")
@scheduled_project_task
def build_tag_models(db_session: SessionLocal, project: Project):
def build_tag_models(db_session: SessionLocal, project: Project) -> NoReturn:
"""Builds the intensive tag recommendation models."""
# incident model
incidents = incident_service.get_all(db_session=db_session, project_id=project.id).all()
Expand Down