private void DeleteAllScopeJobs(IExecutionEntity scopeExecution, ITimerJobEntityManager timerJobEntityManager) { ICollection <ITimerJobEntity> timerJobsForExecution = timerJobEntityManager.FindJobsByExecutionId(scopeExecution.Id); foreach (ITimerJobEntity job in timerJobsForExecution) { timerJobEntityManager.Delete(job); } IJobEntityManager jobEntityManager = commandContext.JobEntityManager; ICollection <IJobEntity> jobsForExecution = jobEntityManager.FindJobsByExecutionId(scopeExecution.Id); foreach (IJobEntity job in jobsForExecution) { jobEntityManager.Delete(job); } ISuspendedJobEntityManager suspendedJobEntityManager = commandContext.SuspendedJobEntityManager; ICollection <ISuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.FindJobsByExecutionId(scopeExecution.Id); foreach (ISuspendedJobEntity job in suspendedJobsForExecution) { suspendedJobEntityManager.Delete(job); } IDeadLetterJobEntityManager deadLetterJobEntityManager = commandContext.DeadLetterJobEntityManager; ICollection <IDeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.FindJobsByExecutionId(scopeExecution.Id); foreach (IDeadLetterJobEntity job in deadLetterJobsForExecution) { deadLetterJobEntityManager.Delete(job); } }
/// <summary> /// /// </summary> /// <param name="timerEntity"></param> protected internal virtual void ExecuteTimerJob(IJobEntity timerEntity) { ITimerJobEntityManager timerJobEntityManager = processEngineConfiguration.TimerJobEntityManager; IVariableScope variableScope = null; if (!(timerEntity.ExecutionId is null)) { variableScope = ExecutionEntityManager.FindById <VariableScopeImpl>(timerEntity.ExecutionId); } if (variableScope == null) { variableScope = NoExecutionVariableScope.SharedInstance; } // set endDate if it was set to the definition RestoreExtraData(timerEntity, variableScope); if (timerEntity.Duedate != null && !IsValidTime(timerEntity, timerEntity.Duedate.GetValueOrDefault(DateTime.Now), variableScope)) { if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug($"Timer {timerEntity.Id} fired. but the dueDate is after the endDate. Deleting timer."); } processEngineConfiguration.JobEntityManager.Delete(timerEntity); return; } ExecuteJobHandler(timerEntity); processEngineConfiguration.JobEntityManager.Delete(timerEntity); if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug($"Timer {timerEntity.Id} fired. Deleting timer."); } if (!(timerEntity.Repeat is null)) { ITimerJobEntity newTimerJobEntity = timerJobEntityManager.CreateAndCalculateNextTimer(timerEntity, variableScope); if (newTimerJobEntity != null) { ScheduleTimerJob(newTimerJobEntity); } } }
/// <summary> /// /// </summary> protected override void RunOperation() { try { // Find the actual scope that needs to be destroyed. // This could be the incoming execution, or the first parent execution where isScope = true // Find parent scope execution IExecutionEntity scopeExecution = execution.IsScope ? execution : FindFirstParentScopeExecution(execution); if (scopeExecution == null) { throw new ActivitiException("Programmatic error: no parent scope execution found for boundary event"); } IExecutionEntityManager executionEntityManager = commandContext.ExecutionEntityManager; DeleteAllChildExecutions(executionEntityManager, scopeExecution); // Delete all scope tasks ITaskEntityManager taskEntityManager = commandContext.TaskEntityManager; DeleteAllScopeTasks(scopeExecution, taskEntityManager); // Delete all scope jobs ITimerJobEntityManager timerJobEntityManager = commandContext.TimerJobEntityManager; DeleteAllScopeJobs(scopeExecution, timerJobEntityManager); // Remove variables associated with this scope IVariableInstanceEntityManager variableInstanceEntityManager = commandContext.VariableInstanceEntityManager; RemoveAllVariablesFromScope(scopeExecution, variableInstanceEntityManager); commandContext.HistoryManager.RecordActivityEnd(scopeExecution, scopeExecution.DeleteReason); executionEntityManager.Delete(scopeExecution); } catch (Exception ex) { logger.LogError(ex, ex.Message); throw; } }
public virtual void DeleteDataForExecution(IExecutionEntity executionEntity, string deleteReason, bool cancel) { // To start, deactivate the current incoming execution executionEntity.Ended = true; executionEntity.IsActive = false; bool enableExecutionRelationshipCounts = IsExecutionRelatedEntityCountEnabled(executionEntity); if (executionEntity.Id.Equals(executionEntity.ProcessInstanceId) && (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).IdentityLinkCount > 0))) { IIdentityLinkEntityManager identityLinkEntityManager = IdentityLinkEntityManager; ICollection <IIdentityLinkEntity> identityLinks = identityLinkEntityManager.FindIdentityLinksByProcessInstanceId(executionEntity.ProcessInstanceId); foreach (IIdentityLinkEntity identityLink in identityLinks) { identityLinkEntityManager.Delete(identityLink); } } // Get variables related to execution and delete them if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).VariableCount > 0)) { ICollection <IVariableInstance> executionVariables = executionEntity.VariableInstancesLocal.Values; foreach (IVariableInstance variableInstance in executionVariables) { if (variableInstance is IVariableInstanceEntity variableInstanceEntity) { IVariableInstanceEntityManager variableInstanceEntityManager = VariableInstanceEntityManager; variableInstanceEntityManager.Delete(variableInstanceEntity); if (variableInstanceEntity.ByteArrayRef != null && variableInstanceEntity.ByteArrayRef.Id is object) { ByteArrayEntityManager.DeleteByteArrayById(variableInstanceEntity.ByteArrayRef.Id); } } } } // Delete current user tasks if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).TaskCount > 0)) { ITaskEntityManager taskEntityManager = TaskEntityManager; ICollection <ITaskEntity> tasksForExecution = taskEntityManager.FindTasksByExecutionId(executionEntity.Id); foreach (ITaskEntity taskEntity in tasksForExecution) { taskEntityManager.DeleteTask(taskEntity, deleteReason, false, cancel); } } // Delete jobs if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).TimerJobCount > 0)) { ITimerJobEntityManager timerJobEntityManager = TimerJobEntityManager; ICollection <ITimerJobEntity> timerJobsForExecution = timerJobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (ITimerJobEntity job in timerJobsForExecution) { timerJobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).JobCount > 0)) { IJobEntityManager jobEntityManager = JobEntityManager; ICollection <IJobEntity> jobsForExecution = jobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (IJobEntity job in jobsForExecution) { JobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).SuspendedJobCount > 0)) { ISuspendedJobEntityManager suspendedJobEntityManager = SuspendedJobEntityManager; ICollection <ISuspendedJobEntity> suspendedJobsForExecution = suspendedJobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (ISuspendedJobEntity job in suspendedJobsForExecution) { suspendedJobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).DeadLetterJobCount > 0)) { IDeadLetterJobEntityManager deadLetterJobEntityManager = DeadLetterJobEntityManager; ICollection <IDeadLetterJobEntity> deadLetterJobsForExecution = deadLetterJobEntityManager.FindJobsByExecutionId(executionEntity.Id); foreach (IDeadLetterJobEntity job in deadLetterJobsForExecution) { deadLetterJobEntityManager.Delete(job); if (EventDispatcher.Enabled) { EventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_CANCELED, job)); } } } // Delete event subscriptions if (!enableExecutionRelationshipCounts || (enableExecutionRelationshipCounts && ((ICountingExecutionEntity)executionEntity).EventSubscriptionCount > 0)) { IEventSubscriptionEntityManager eventSubscriptionEntityManager = EventSubscriptionEntityManager; IList <IEventSubscriptionEntity> eventSubscriptions = eventSubscriptionEntityManager.FindEventSubscriptionsByExecution(executionEntity.Id); foreach (IEventSubscriptionEntity eventSubscription in eventSubscriptions) { eventSubscriptionEntityManager.Delete(eventSubscription); } } }