feat: script jobs scheduler and manager page for Fortigate, UniFi and Grandstream scripts
This commit is contained in:
@@ -2,7 +2,7 @@ from datetime import datetime, timezone
|
||||
import uuid
|
||||
from sqlalchemy import (
|
||||
Column, String, Integer, BigInteger, Boolean, DateTime,
|
||||
ForeignKey, Text, Index
|
||||
ForeignKey, Text, Index, Float
|
||||
)
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.core.database import Base
|
||||
@@ -213,3 +213,29 @@ class SystemSetting(Base):
|
||||
|
||||
key = Column(String(100), primary_key=True, index=True)
|
||||
value = Column(String(1024), nullable=False)
|
||||
|
||||
class ScriptJob(Base):
|
||||
__tablename__ = "script_jobs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(255), nullable=False)
|
||||
script_type = Column(String(50), nullable=False) # python, bash
|
||||
script_path = Column(String(1024), nullable=False) # relative to app/scripts/ or absolute
|
||||
schedule_cron = Column(String(100), default="0 2 * * *", nullable=False)
|
||||
is_active = Column(Boolean, default=True, nullable=False)
|
||||
created_at = Column(DateTime(timezone=True), default=utc_now, nullable=False)
|
||||
|
||||
runs = relationship("ScriptJobRun", back_populates="job", cascade="all, delete-orphan")
|
||||
|
||||
class ScriptJobRun(Base):
|
||||
__tablename__ = "script_job_runs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
script_job_id = Column(Integer, ForeignKey("script_jobs.id", ondelete="CASCADE"), nullable=False)
|
||||
started_at = Column(DateTime(timezone=True), default=utc_now, nullable=False)
|
||||
completed_at = Column(DateTime(timezone=True), nullable=True)
|
||||
status = Column(String(50), default="RUNNING", nullable=False) # RUNNING, SUCCESS, FAILED
|
||||
duration_seconds = Column(Float, default=0.0, nullable=False)
|
||||
log_output = Column(Text, nullable=True)
|
||||
|
||||
job = relationship("ScriptJob", back_populates="runs")
|
||||
|
||||
Reference in New Issue
Block a user