Skip to content
Snippets Groups Projects
Commit a89fa3b9 authored by Sam Kagan's avatar Sam Kagan
Browse files

Added new state machine for restore_cms

Mapped restore_cms to new SM
parent 11b73faa
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2023 Associated Universities, Inc. Washington DC, USA.
#
# This file is part of NRAO Workspaces.
#
# Workspaces is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Workspaces is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
#
"""change restore_cms StateMachine type
Revision ID: 66a7692b56b4
Revises: 5a1e335e6c13
Create Date: 2024-07-01 12:16:26.209422
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "66a7692b56b4"
down_revision = "5a1e335e6c13"
branch_labels = None
depends_on = None
def upgrade():
op.execute(
"""UPDATE capability_state_machines SET machine_type='simple_with_analyst_support' WHERE capability_name='restore_cms'"""
)
def downgrade():
op.execute("""UPDATE capability_state_machines SET machine_type='simple' WHERE capability_name='restore_cms'""")
......@@ -151,6 +151,54 @@ class SimpleStateMachine(StateMachine):
}
@mapper_registry.mapped
class SimpleStateMachineWithAnalystSupport(StateMachine):
"""
Class representation of your basic launch-workflow state machine
"""
def init_state_machine(self) -> StateMachineRepr:
"""
Initialize launch-workflow state machine
:return: Dict repr of workflow state machine
"""
workflow_name = self.associated_workflows["workflow_name"]
analyst_email = CapoConfig().get("edu.nrao.workspaces.NotificationSettings.analystEmail")
return {
"Start": {
("Queued", "capability-submitted"): [
QueueWorkflow(arguments=workflow_name),
SendNotification(arguments=json.dumps({"template": "workflow_submitted"})),
]
},
"Queued": {
("Executing", "resume"): [ExecuteWorkflow(arguments=workflow_name)],
("Cancelled", "cancel"): [SendMessage(arguments="capability_cancelled")],
},
"Executing": {
("Complete", "workflow-complete"): [
SendMessage(arguments="execution_complete"),
SendNotification(arguments=json.dumps({"template": "workflow_complete", "send_to_qa": False})),
],
("Error", "workflow-failed"): [
SendMessage(arguments="execution_error"),
SendNotification(
arguments=json.dumps(
{"template": "workflow_failed", "send_to_qa": False, "cc_emails": [analyst_email]}
)
),
],
("Cancelled", "cancel"): [
# Cancel action kills running workflow
Cancel(arguments=workflow_name),
SendMessage(arguments="capability_cancelled"),
],
},
}
@mapper_registry.mapped
class SingleQAStateMachine(StateMachine):
"""
......
......@@ -26,6 +26,7 @@ from workspaces.capability.schema import (
Action,
DoubleQAStateMachine,
SimpleStateMachine,
SimpleStateMachineWithAnalystSupport,
SingleQAStateMachine,
State,
StateMachine,
......@@ -123,6 +124,7 @@ class StateMachineInfo:
"simple": SimpleStateMachine,
"single_qa": SingleQAStateMachine,
"double_qa": DoubleQAStateMachine,
"simple_with_analyst_support": SimpleStateMachineWithAnalystSupport,
}
state_machines = self.session.query(StateMachine).all()
for machine in state_machines:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment