automation: establish an automation framework
This commit is contained in:
parent
1b53bf451c
commit
8abe5d60fa
31 changed files with 586 additions and 274 deletions
34
app/models/automation.py
Normal file
34
app/models/automation.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import datetime
|
||||
import enum
|
||||
|
||||
from app.extensions import db
|
||||
from app.models import AbstractConfiguration, AbstractResource
|
||||
|
||||
|
||||
class AutomationState(enum.Enum):
|
||||
IDLE = 0
|
||||
RUNNING = 1
|
||||
ERROR = 3
|
||||
|
||||
|
||||
class Automation(AbstractConfiguration):
|
||||
short_name = db.Column(db.String(25), nullable=False)
|
||||
state = db.Column(db.Enum(AutomationState), default=AutomationState.IDLE, nullable=False)
|
||||
enabled = db.Column(db.Boolean, nullable=False)
|
||||
last_run = db.Column(db.DateTime(), nullable=True)
|
||||
next_run = db.Column(db.DateTime(), nullable=True)
|
||||
next_is_full = db.Column(db.Boolean(), nullable=False)
|
||||
|
||||
logs = db.relationship("AutomationLogs", back_populates="automation")
|
||||
|
||||
def kick(self):
|
||||
self.enabled = True
|
||||
self.next_run = datetime.datetime.utcnow()
|
||||
self.updated = datetime.datetime.utcnow()
|
||||
|
||||
|
||||
class AutomationLogs(AbstractResource):
|
||||
automation_id = db.Column(db.Integer, db.ForeignKey(Automation.id), nullable=False)
|
||||
logs = db.Column(db.Text)
|
||||
|
||||
automation = db.relationship("Automation", back_populates="logs")
|
Loading…
Add table
Add a link
Reference in a new issue