move job scheduling to DB
This commit is contained in:
@@ -8,6 +8,7 @@ from sqlalchemy.orm import selectinload
|
||||
from app.models.subscription import Subscription
|
||||
from app.models.source import Source
|
||||
from app.tasks.downloads import download_source
|
||||
from app.api.settings import get_setting_value
|
||||
|
||||
bp = Blueprint("subscriptions", __name__)
|
||||
|
||||
@@ -85,6 +86,11 @@ async def create_subscription():
|
||||
metadata_=data.get("metadata", {}),
|
||||
)
|
||||
|
||||
# Get default check interval from database settings
|
||||
default_interval = await get_setting_value(
|
||||
session, "download.schedule_interval", 3600
|
||||
)
|
||||
|
||||
# Add sources if provided
|
||||
sources_data = data.get("sources", [])
|
||||
for source_data in sources_data:
|
||||
@@ -94,7 +100,7 @@ async def create_subscription():
|
||||
platform=source_data["platform"],
|
||||
url=source_data["url"],
|
||||
enabled=source_data.get("enabled", True),
|
||||
check_interval=source_data.get("check_interval", 3600),
|
||||
check_interval=source_data.get("check_interval", default_interval),
|
||||
metadata_=source_data.get("metadata", {}),
|
||||
)
|
||||
subscription.sources.append(source)
|
||||
@@ -254,12 +260,17 @@ async def add_source_to_subscription(subscription_id: int):
|
||||
# Store name before commit (attributes expire after commit)
|
||||
subscription_name = subscription.name
|
||||
|
||||
# Get default check interval from database settings
|
||||
default_interval = await get_setting_value(
|
||||
session, "download.schedule_interval", 3600
|
||||
)
|
||||
|
||||
source = Source(
|
||||
subscription_id=subscription_id,
|
||||
platform=data["platform"],
|
||||
url=data["url"],
|
||||
enabled=data.get("enabled", True),
|
||||
check_interval=data.get("check_interval", 3600),
|
||||
check_interval=data.get("check_interval", default_interval),
|
||||
metadata_=data.get("metadata", {}),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user