public int tryUnblockFailedWorkflowInstances(String workflowId, int limit, TimelineEvent event) {
    return withMetricLogError(
        () ->
            withRetryableUpdate(
                UNBLOCK_INSTANCES_FAILED_STATUS,
                stmt -> {
                  int idx = 0;
                  stmt.setString(++idx, toJson(event));
                  stmt.setString(++idx, workflowId);
                  stmt.setInt(++idx, limit);
                }),
        "tryUnblockFailedWorkflowInstances",
        "Failed to try to unblock the failed workflow instances for workflow id[{}]",
        workflowId);
  }
@Test
  public void testTryUnblockFailedWorkflowInstances() {
    wfi.setWorkflowUuid("test-uuid");
    wfi.setWorkflowInstanceId(0L);
    int res = runStrategyDao.startWithRunStrategy(wfi, Defaults.DEFAULT_RUN_STRATEGY);
    assertEquals(1, res);
    int cnt =
        instanceDao.terminateQueuedInstances(
            TEST_WORKFLOW_ID, 2, WorkflowInstance.Status.FAILED, "test-reason");
    assertEquals(2L, cnt);
    String status = instanceDao.getWorkflowInstanceRawStatus(TEST_WORKFLOW_ID, 1L, 1L);
    assertEquals("FAILED", status);
    status = instanceDao.getWorkflowInstanceRawStatus(TEST_WORKFLOW_ID, 2L, 1L);
    assertEquals("FAILED", status);

    int ret = instanceDao.tryUnblockFailedWorkflowInstances(TEST_WORKFLOW_ID, 1, null);
    assertEquals(1, ret);
    status = instanceDao.getWorkflowInstanceRawStatus(TEST_WORKFLOW_ID, 1L, 1L);
    assertEquals("FAILED_1", status);
    status = instanceDao.getWorkflowInstanceRawStatus(TEST_WORKFLOW_ID, 2L, 1L);
    assertEquals("FAILED", status);

    ret = instanceDao.tryUnblockFailedWorkflowInstances(TEST_WORKFLOW_ID, 2, null);
    assertEquals(1, ret);
    status = instanceDao.getWorkflowInstanceRawStatus(TEST_WORKFLOW_ID, 1L, 1L);
    assertEquals("FAILED_1", status);
    status = instanceDao.getWorkflowInstanceRawStatus(TEST_WORKFLOW_ID, 2L, 1L);
    assertEquals("FAILED_1", status);

    MaestroTestHelper.removeWorkflowInstance(dataSource, TEST_WORKFLOW_ID, 2);
  }