Ejemplo n.º 1
0
        public virtual string Execute(ICommandContext commandContext)
        {
            if (ReferenceEquals(jobId, null))
            {
                throw new ActivitiIllegalArgumentException("jobId is null");
            }

            IAbstractJobEntity job = null;

            switch (jobType)
            {
            case JobType.ASYNC:
                job = commandContext.JobEntityManager.FindById <IAbstractJobEntity>(new KeyValuePair <string, object>("id", jobId));
                break;

            case JobType.TIMER:
                job = commandContext.TimerJobEntityManager.FindById <IAbstractJobEntity>(new KeyValuePair <string, object>("id", jobId));
                break;

            case JobType.SUSPENDED:
                job = commandContext.SuspendedJobEntityManager.FindById <IAbstractJobEntity>(new KeyValuePair <string, object>("id", jobId));
                break;

            case JobType.DEADLETTER:
                job = commandContext.DeadLetterJobEntityManager.FindById <IAbstractJobEntity>(new KeyValuePair <string, object>("id", jobId));
                break;
            }

            if (job == null)
            {
                throw new ActivitiObjectNotFoundException("No job found with id " + jobId, typeof(IJob));
            }

            return(job.ExceptionStacktrace);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="otherJob"></param>
        /// <returns></returns>
        protected internal virtual ITimerJobEntity CreateTimerJobFromOtherJob(IAbstractJobEntity otherJob)
        {
            ITimerJobEntity timerJob = processEngineConfiguration.TimerJobEntityManager.Create();

            CopyJobInfo(timerJob, otherJob);
            return(timerJob);
        }
Ejemplo n.º 3
0
        public virtual IDeadLetterJobEntity Execute(ICommandContext commandContext)
        {
            if (jobId is null)
            {
                throw new ActivitiIllegalArgumentException("jobId and job is null");
            }

            IAbstractJobEntity job = commandContext.TimerJobEntityManager.FindById <IAbstractJobEntity>(new KeyValuePair <string, object>("id", jobId));

            if (job == null)
            {
                job = commandContext.JobEntityManager.FindById <IAbstractJobEntity>(new KeyValuePair <string, object>("id", jobId));
            }

            if (job == null)
            {
                throw new JobNotFoundException(jobId);
            }

            if (log.IsEnabled(LogLevel.Debug))
            {
                log.LogDebug($"Moving job to deadletter job table {job.Id}");
            }

            IDeadLetterJobEntity deadLetterJob = commandContext.JobManager.MoveJobToDeadLetterJob(job);

            return(deadLetterJob);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public virtual IDeadLetterJobEntity MoveJobToDeadLetterJob(IAbstractJobEntity job)
        {
            IDeadLetterJobEntity deadLetterJob = CreateDeadLetterJobFromOtherJob(job);

            processEngineConfiguration.DeadLetterJobEntityManager.Insert(deadLetterJob);
            if (job is ITimerJobEntity)
            {
                processEngineConfiguration.TimerJobEntityManager.Delete((ITimerJobEntity)job);
            }
            else if (job is IJobEntity)
            {
                processEngineConfiguration.JobEntityManager.Delete((IJobEntity)job);
            }

            return(deadLetterJob);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public virtual ISuspendedJobEntity MoveJobToSuspendedJob(IAbstractJobEntity job)
        {
            ISuspendedJobEntity suspendedJob = CreateSuspendedJobFromOtherJob(job);

            processEngineConfiguration.SuspendedJobEntityManager.Insert(suspendedJob);
            if (job is ITimerJobEntity)
            {
                processEngineConfiguration.TimerJobEntityManager.Delete((ITimerJobEntity)job);
            }
            else if (job is IJobEntity)
            {
                processEngineConfiguration.JobEntityManager.Delete((IJobEntity)job);
            }

            return(suspendedJob);
        }
        protected internal virtual IDeadLetterJobEntity CreateDeadLetterJob(IAbstractJobEntity job)
        {
            IDeadLetterJobEntity newJobEntity = Create();

            newJobEntity.JobHandlerConfiguration = job.JobHandlerConfiguration;
            newJobEntity.JobHandlerType          = job.JobHandlerType;
            newJobEntity.Exclusive           = job.Exclusive;
            newJobEntity.Repeat              = job.Repeat;
            newJobEntity.Retries             = job.Retries;
            newJobEntity.EndDate             = job.EndDate;
            newJobEntity.ExecutionId         = job.ExecutionId;
            newJobEntity.ProcessInstanceId   = job.ProcessInstanceId;
            newJobEntity.ProcessDefinitionId = job.ProcessDefinitionId;

            // Inherit tenant
            newJobEntity.TenantId = job.TenantId;
            newJobEntity.JobType  = job.JobType;
            return(newJobEntity);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        protected internal virtual IJobEntity CreateExecutableJobFromOtherJob(IAbstractJobEntity job)
        {
            IJobEntity executableJob = processEngineConfiguration.JobEntityManager.Create();

            CopyJobInfo(executableJob, job);

            if (AsyncExecutorActive)
            {
                //GregorianCalendar gregorianCalendar = new GregorianCalendar();
                //gregorianCalendar.Time = processEngineConfiguration.Clock.CurrentTime;
                //gregorianCalendar.add(DateTime.MILLISECOND, AsyncExecutor.TimerLockTimeInMillis);

                //将job锁定为一定时间(默认30秒)
                executableJob.LockExpirationTime = DateTime.Now.AddMilliseconds(AsyncExecutor.TimerLockTimeInMillis);
                executableJob.LockOwner          = AsyncExecutor.LockOwner;
            }

            return(executableJob);
        }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="job"></param>
        /// <returns></returns>
        public virtual ITimerJobEntity MoveJobToTimerJob(IAbstractJobEntity job)
        {
            ITimerJobEntity timerJob        = CreateTimerJobFromOtherJob(job);
            bool            insertSuccesful = processEngineConfiguration.TimerJobEntityManager.InsertTimerJobEntity(timerJob);

            if (insertSuccesful)
            {
                if (job is IJobEntity)
                {
                    processEngineConfiguration.JobEntityManager.Delete((IJobEntity)job);
                }
                else if (job is ISuspendedJobEntity)
                {
                    processEngineConfiguration.SuspendedJobEntityManager.Delete((ISuspendedJobEntity)job);
                }

                return(timerJob);
            }
            return(null);
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="copyToJob"></param>
        /// <param name="copyFromJob"></param>
        /// <returns></returns>
        protected internal virtual IAbstractJobEntity CopyJobInfo(IAbstractJobEntity copyToJob, IAbstractJobEntity copyFromJob)
        {
            copyToJob.Duedate                 = copyFromJob.Duedate;
            copyToJob.EndDate                 = copyFromJob.EndDate;
            copyToJob.Exclusive               = copyFromJob.Exclusive;
            copyToJob.ExecutionId             = copyFromJob.ExecutionId;
            copyToJob.Id                      = copyFromJob.Id;
            copyToJob.JobHandlerConfiguration = copyFromJob.JobHandlerConfiguration;
            copyToJob.JobHandlerType          = copyFromJob.JobHandlerType;
            copyToJob.JobType                 = copyFromJob.JobType;
            copyToJob.ExceptionMessage        = copyFromJob.ExceptionMessage;
            copyToJob.ExceptionStacktrace     = copyFromJob.ExceptionStacktrace;
            copyToJob.MaxIterations           = copyFromJob.MaxIterations;
            copyToJob.ProcessDefinitionId     = copyFromJob.ProcessDefinitionId;
            copyToJob.ProcessInstanceId       = copyFromJob.ProcessInstanceId;
            copyToJob.Repeat                  = copyFromJob.Repeat;
            copyToJob.Retries                 = copyFromJob.Retries;
            copyToJob.Revision                = copyFromJob.Revision;
            copyToJob.TenantId                = copyFromJob.TenantId;

            return(copyToJob);
        }
Ejemplo n.º 10
0
        public virtual object Execute(ICommandContext commandContext)
        {
            IJobEntity job = commandContext.JobEntityManager.FindById <IJobEntity>(new KeyValuePair <string, object>("id", jobId));

            if (job == null)
            {
                return(null);
            }

            ProcessEngineConfiguration processEngineConfig = commandContext.ProcessEngineConfiguration;

            IExecutionEntity executionEntity    = fetchExecutionEntity(commandContext, job.ExecutionId);
            FlowElement      currentFlowElement = executionEntity != null ? executionEntity.CurrentFlowElement : null;

            string failedJobRetryTimeCycleValue = null;

            if (currentFlowElement is ServiceTask)
            {
                failedJobRetryTimeCycleValue = ((ServiceTask)currentFlowElement).FailedJobRetryTimeCycleValue;
            }

            IAbstractJobEntity newJobEntity = null;

            if (currentFlowElement == null || ReferenceEquals(failedJobRetryTimeCycleValue, null))
            {
                log.LogDebug("activity or FailedJobRetryTimerCycleValue is null in job " + jobId + ". only decrementing retries.");

                if (job.Retries <= 1)
                {
                    newJobEntity = commandContext.JobManager.MoveJobToDeadLetterJob(job);
                }
                else
                {
                    newJobEntity = commandContext.JobManager.MoveJobToTimerJob(job);
                }

                newJobEntity.Retries = job.Retries - 1;
                if (!job.Duedate.HasValue || JobFields.JOB_TYPE_MESSAGE.Equals(job.JobType))
                {
                    // add wait time for failed async job
                    newJobEntity.Duedate = calculateDueDate(commandContext, processEngineConfig.AsyncFailedJobWaitTime, null);
                }
                else
                {
                    // add default wait time for failed job
                    newJobEntity.Duedate = calculateDueDate(commandContext, processEngineConfig.DefaultFailedJobWaitTime, job.Duedate);
                }
            }
            else
            {
                try
                {
                    DurationHelper durationHelper = new DurationHelper(failedJobRetryTimeCycleValue, processEngineConfig.Clock);
                    int            jobRetries     = job.Retries;
                    if (ReferenceEquals(job.ExceptionMessage, null))
                    {
                        // change default retries to the ones configured
                        jobRetries = durationHelper.Times;
                    }

                    if (jobRetries <= 1)
                    {
                        newJobEntity = commandContext.JobManager.MoveJobToDeadLetterJob(job);
                    }
                    else
                    {
                        newJobEntity = commandContext.JobManager.MoveJobToTimerJob(job);
                    }

                    newJobEntity.Duedate = durationHelper.DateAfter;

                    if (ReferenceEquals(job.ExceptionMessage, null))
                    {
                        // is it the first exception
                        log.LogDebug("Applying JobRetryStrategy '" + failedJobRetryTimeCycleValue + "' the first time for job " + job.Id + " with " + durationHelper.Times + " retries");
                    }
                    else
                    {
                        log.LogDebug("Decrementing retries of JobRetryStrategy '" + failedJobRetryTimeCycleValue + "' for job " + job.Id);
                    }

                    newJobEntity.Retries = jobRetries - 1;
                }
                catch (Exception)
                {
                    throw new ActivitiException("failedJobRetryTimeCylcle has wrong format:" + failedJobRetryTimeCycleValue, exception);
                }
            }

            if (exception != null)
            {
                newJobEntity.ExceptionMessage    = exception.Message;
                newJobEntity.ExceptionStacktrace = ExceptionStacktrace;
            }

            // Dispatch both an update and a retry-decrement event
            IActivitiEventDispatcher eventDispatcher = commandContext.EventDispatcher;

            if (eventDispatcher.Enabled)
            {
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.ENTITY_UPDATED, newJobEntity));
                eventDispatcher.DispatchEvent(ActivitiEventBuilder.CreateEntityEvent(ActivitiEventType.JOB_RETRIES_DECREMENTED, newJobEntity));
            }

            return(null);
        }
Ejemplo n.º 11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="otherJob"></param>
        /// <returns></returns>
        protected internal virtual IDeadLetterJobEntity CreateDeadLetterJobFromOtherJob(IAbstractJobEntity otherJob)
        {
            IDeadLetterJobEntity deadLetterJob = processEngineConfiguration.DeadLetterJobEntityManager.Create();

            CopyJobInfo(deadLetterJob, otherJob);
            return(deadLetterJob);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="otherJob"></param>
        /// <returns></returns>
        protected internal virtual ISuspendedJobEntity CreateSuspendedJobFromOtherJob(IAbstractJobEntity otherJob)
        {
            ISuspendedJobEntity suspendedJob = processEngineConfiguration.SuspendedJobEntityManager.Create();

            CopyJobInfo(suspendedJob, otherJob);
            return(suspendedJob);
        }