Skip to content

Instantly share code, notes, and snippets.

@jasonleibowitz
Last active January 30, 2024 20:26
Show Gist options
  • Save jasonleibowitz/4c141d29cbad315634fb82d4eb7358ab to your computer and use it in GitHub Desktop.
Save jasonleibowitz/4c141d29cbad315634fb82d4eb7358ab to your computer and use it in GitHub Desktop.
Manually Resolve Hanging Workflow
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)
@simranjaising30
Copy link

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