Last active
January 30, 2024 20:26
-
-
Save jasonleibowitz/4c141d29cbad315634fb82d4eb7358ab to your computer and use it in GitHub Desktop.
Manually Resolve Hanging Workflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import transaction | |
from fund_admin.express.task_management.services import WorkflowService | |
from fund_admin.express.task_management.constants import WorkflowStatus, WorkflowTemplateName, TaskStatus | |
from fund_admin.reporting.models.package import FinancialPackageReport | |
@transaction.atomic | |
def force_complete_workflow_for_package(package_id): | |
workflow = WorkflowService().get_active_workflow_for_object( | |
str(package_id), | |
FinancialPackageReport._meta.label, | |
WorkflowTemplateName.PUBLISH_FINANCIAL_PACKAGE.value, | |
) | |
tasks_to_cancel = workflow.tasks.filter(status__in=[TaskStatus.PENDING, TaskStatus.ACTIVE]) | |
# First, cancel all outstanding tasks | |
for task in tasks_to_cancel: | |
task.cancel() | |
# Next, mark the workflow as complete | |
workflow.state = "Completed" | |
workflow.status = WorkflowStatus.COMPLETE | |
# Finally, save the workflow | |
workflow.save() | |
force_complete_workflow_for_package(package_id=48530) |
I have also done something like this in the past
workflow_id = 1236053 last_task = Workflow.objects.get(id=workflow_id)._get_last_task() WorkflowMetric.objects.filter(workflow_id=workflow_id).delete() TaskService().apply_action( action=Action.RECONCILE_TRANSACTION.value, task_id=last_task.id, resolved_by=0, )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To resolve a situation where a Financial Package was published by the FA after being "Approved, but wait" by the GP. This resulted in the package being published and its status being updated to reflect that, but the package's workflow is still in
Approved, waiting to publish
.This Gist will force complete the workflow and cancel any outstanding tasks.
Note: Relevant Confluence Doc