do not try to queue task if the pi cannot be found and delete future tasks if parent task deleted w/ burnettk (#1761)

Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
jasquat 2024-06-18 16:54:09 -04:00 committed by GitHub
parent 95ed415bab
commit 6fad14ae6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 3 deletions

View File

@ -0,0 +1,32 @@
"""empty message
Revision ID: 7eaec0e12079
Revises: 43afc70a7016
Create Date: 2024-06-18 16:45:06.102210
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7eaec0e12079'
down_revision = '43afc70a7016'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('future_task', schema=None) as batch_op:
batch_op.create_foreign_key('future_task_task_guid_fk', 'task', ['guid'], ['guid'], ondelete='CASCADE')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('future_task', schema=None) as batch_op:
batch_op.drop_constraint('future_task_task_guid_fk', type_='foreignkey')
# ### end Alembic commands ###

View File

@ -80,7 +80,7 @@ class BackgroundProcessingService:
.filter(TaskModel.guid == future_task.guid) .filter(TaskModel.guid == future_task.guid)
.first() .first()
) )
if process_instance.allowed_to_run(): if process_instance and process_instance.allowed_to_run():
queue_future_task_if_appropriate( queue_future_task_if_appropriate(
process_instance, eta_in_seconds=future_task.run_at_in_seconds, task_guid=future_task.guid process_instance, eta_in_seconds=future_task.run_at_in_seconds, task_guid=future_task.guid
) )

View File

@ -2,6 +2,7 @@ import time
from dataclasses import dataclass from dataclasses import dataclass
from flask import current_app from flask import current_app
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.mysql import insert as mysql_insert from sqlalchemy.dialects.mysql import insert as mysql_insert
from sqlalchemy.dialects.postgresql import insert as postgres_insert from sqlalchemy.dialects.postgresql import insert as postgres_insert
from sqlalchemy.dialects.sqlite import insert as sqlite_insert from sqlalchemy.dialects.sqlite import insert as sqlite_insert
@ -9,17 +10,17 @@ from sqlalchemy.sql import false
from spiffworkflow_backend.models.db import SpiffworkflowBaseDBModel from spiffworkflow_backend.models.db import SpiffworkflowBaseDBModel
from spiffworkflow_backend.models.db import db from spiffworkflow_backend.models.db import db
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
@dataclass @dataclass
class FutureTaskModel(SpiffworkflowBaseDBModel): class FutureTaskModel(SpiffworkflowBaseDBModel):
__tablename__ = "future_task" __tablename__ = "future_task"
guid: str = db.Column(db.String(36), primary_key=True) guid: str = db.Column(ForeignKey(TaskModel.guid, ondelete="CASCADE", name="future_task_task_guid_fk"), primary_key=True)
run_at_in_seconds: int = db.Column(db.Integer, nullable=False, index=True) run_at_in_seconds: int = db.Column(db.Integer, nullable=False, index=True)
completed: bool = db.Column(db.Boolean, default=False, nullable=False, index=True) completed: bool = db.Column(db.Boolean, default=False, nullable=False, index=True)
archived_for_process_instance_status: bool = db.Column( archived_for_process_instance_status: bool = db.Column(
# db.Boolean, default=False, server_default=db.sql.False_(), nullable=False, index=True
db.Boolean, db.Boolean,
default=False, default=False,
server_default=false(), server_default=false(),