Example #1
0
        public override void execute(BatchJobConfiguration configuration, ExecutionEntity execution, CommandContext commandContext, string tenantId)
        {
            ByteArrayEntity configurationEntity = commandContext.DbEntityManager.selectById(typeof(ByteArrayEntity), configuration.ConfigurationByteArrayId);

            DeleteProcessInstanceBatchConfiguration batchConfiguration = readConfiguration(configurationEntity.Bytes);

            bool initialLegacyRestrictions = commandContext.RestrictUserOperationLogToAuthenticatedUsers;

            commandContext.disableUserOperationLog();
            commandContext.RestrictUserOperationLogToAuthenticatedUsers = true;
            try
            {
                RuntimeService runtimeService = commandContext.ProcessEngineConfiguration.RuntimeService;
                if (batchConfiguration.FailIfNotExists)
                {
                    runtimeService.deleteProcessInstances(batchConfiguration.Ids, batchConfiguration.deleteReason, batchConfiguration.SkipCustomListeners, true, batchConfiguration.SkipSubprocesses);
                }
                else
                {
                    runtimeService.deleteProcessInstancesIfExists(batchConfiguration.Ids, batchConfiguration.deleteReason, batchConfiguration.SkipCustomListeners, true, batchConfiguration.SkipSubprocesses);
                }
            }
            finally
            {
                commandContext.enableUserOperationLog();
                commandContext.RestrictUserOperationLogToAuthenticatedUsers = initialLegacyRestrictions;
            }

            commandContext.ByteArrayManager.delete(configurationEntity);
        }