Exemplo n.º 1
0
        /// <summary>
        /// Factory to create a workflow run , the workflow starts async
        /// </summary>
        /// <param name="workflowToRun"></param>
        /// <param name="args"></param>
        /// <param name="trace"></param>
        /// <param name="invoker"></param>
        /// <returns>The workflow run task ID</returns>
        public string RunWorkflowAsync(WorkflowStartEvent startEvent)
        {
            if (startEvent == null)
            {
                throw new ArgumentNullException(nameof(startEvent));
            }

            if (startEvent.Workflow == null)
            {
                throw new ArgumentException("Missing mandatory argument workflow to on WorkflowStartEvent.");
            }

            using (Profiler.Measure("WorkflowRunner.Instance.StartWorkflowAsync"))
            {
                using (new SecurityBypassContext())
                {
                    if (startEvent.Workflow.WfNewerVersion != null)
                    {
                        throw new ArgumentException("Attempted to run a workflow that is not the newest version.");
                    }
                }

                // create a wf run then pass into the workflow
                var run = new WorkflowRunDeferred(startEvent.Workflow)
                {
                    RunTrace = startEvent.Trace
                };

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                Factory.WorkflowRunTaskManager.RegisterStart(run.TaskId);

                HandleDiagnostics(run, WorkflowRunState_Enumeration.WorkflowRunStarted.ToString( ));

                WorkflowRunContext.Current.QueueAction(() =>
                {
                    stopWatch.Stop();

                    perfCounters.GetPerformanceCounter <AverageTimer32PerformanceCounter>(WorkflowPerformanceCounters.QueueDurationCounterName).AddTiming(stopWatch);

                    using (new WorkflowRunContext(true)
                    {
                        RunTriggersInCurrentThread = true
                    })                                                                         // need to ensure that all deferred saves occur before we register complete.
                    {
                        ProcessWorkflowInContext(run, startEvent);
                    }
                });

                return(run.TaskId);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Private constructor to start the counter.
        /// </summary>
        private PerformanceCounters(string categoryName, string countName, string rateName, string durationName)
        {
            _durationName = durationName;

            _perfCounters = Categories.GetOrAdd(categoryName, name =>
                                                new SingleInstancePerformanceCounterCategory(name));

            _perfCounters.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(rateName).Increment();
            _perfCounters.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(countName).Increment();
            _stopWatch = new Stopwatch();
            _stopWatch.Start();
        }
        public void TestMoq()
        {
            Mock <AverageTimer32PerformanceCounter>          averageTimer32PerformanceCounterMock;
            Mock <NumberOfItems64PerformanceCounter>         numberofItems64PerformanceCounterMock;
            Mock <PercentageRatePerformanceCounter>          percentageRatePerformanceCounterMock;
            Mock <RatePerSecond32PerformanceCounter>         ratePerSecond32PerformanceCounterMock;
            Mock <ISingleInstancePerformanceCounterCategory> singleInstancePerformanceCounterCategoryMock;
            const string counterName = "counterName";

            averageTimer32PerformanceCounterMock = new Mock <AverageTimer32PerformanceCounter>();
            averageTimer32PerformanceCounterMock.Setup(pc => pc.AddTiming(It.IsAny <Stopwatch>()));
            averageTimer32PerformanceCounterMock.Setup(pc => pc.Dispose());

            numberofItems64PerformanceCounterMock = new Mock <NumberOfItems64PerformanceCounter>();
            numberofItems64PerformanceCounterMock.Setup(pc => pc.Increment());
            numberofItems64PerformanceCounterMock.Setup(pc => pc.IncrementBy(It.IsAny <long>()));
            numberofItems64PerformanceCounterMock.Setup(pc => pc.Dispose());

            percentageRatePerformanceCounterMock = new Mock <PercentageRatePerformanceCounter>();
            percentageRatePerformanceCounterMock.Setup(pc => pc.AddHit());
            percentageRatePerformanceCounterMock.Setup(pc => pc.AddMiss());
            percentageRatePerformanceCounterMock.Setup(pc => pc.Dispose());

            ratePerSecond32PerformanceCounterMock = new Mock <RatePerSecond32PerformanceCounter>();
            ratePerSecond32PerformanceCounterMock.Setup(pc => pc.Increment());
            ratePerSecond32PerformanceCounterMock.Setup(pc => pc.Dispose());

            singleInstancePerformanceCounterCategoryMock = new Mock <ISingleInstancePerformanceCounterCategory>();
            singleInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <AverageTimer32PerformanceCounter>(It.IsAny <string>()))
            .Returns(() => averageTimer32PerformanceCounterMock.Object);
            singleInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(It.IsAny <string>()))
            .Returns(() => numberofItems64PerformanceCounterMock.Object);
            singleInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <PercentageRatePerformanceCounter>(It.IsAny <string>()))
            .Returns(() => percentageRatePerformanceCounterMock.Object);
            singleInstancePerformanceCounterCategoryMock.Setup(
                pcc => pcc.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(It.IsAny <string>()))
            .Returns(() => ratePerSecond32PerformanceCounterMock.Object);
            singleInstancePerformanceCounterCategoryMock.Setup(pcc => pcc.Dispose());

            using (ISingleInstancePerformanceCounterCategory singleInstancePerformanceCounterCategory =
                       singleInstancePerformanceCounterCategoryMock.Object)
            {
                singleInstancePerformanceCounterCategory.GetPerformanceCounter <AverageTimer32PerformanceCounter>(
                    counterName).AddTiming(new Stopwatch());
                singleInstancePerformanceCounterCategory.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(
                    counterName).Increment();
                singleInstancePerformanceCounterCategory.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(
                    counterName).IncrementBy(0);
                singleInstancePerformanceCounterCategory.GetPerformanceCounter <PercentageRatePerformanceCounter>(
                    counterName).AddHit();
                singleInstancePerformanceCounterCategory.GetPerformanceCounter <PercentageRatePerformanceCounter>(
                    counterName).AddMiss();
                singleInstancePerformanceCounterCategory.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(
                    counterName).Increment();
            }
        }
        public static void ActionTrigger(this WfTriggerUserUpdatesResource trigger, IEntity entity)
        {
            perfCounters.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(WorkflowPerformanceCounters.TriggerRateCounterName).Increment();

            RunWorkflow(trigger, entity.Id);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Dispose to complete the timer counter.
 /// </summary>
 public void Dispose()
 {
     _stopWatch.Stop();
     _perfCounters.GetPerformanceCounter <AverageTimer32PerformanceCounter>(_durationName).AddTiming(_stopWatch);
 }
Exemplo n.º 6
0
        protected override void Execute(IJobExecutionContext jobContext)
        {
            var stopWatch = new Stopwatch();

            perfCounters.GetPerformanceCounter <RatePerSecond32PerformanceCounter>(WorkflowPerformanceCounters.ScheduleFireRateCounterName).Increment();
            stopWatch.Start();

            var jobRef = ScheduledItemHelper.GetScheduledItemRef(jobContext);

            Diagnostics.EventLog.Application.WriteTrace($"Starting job {jobRef.Id}.");

            try
            {
                using (DeferredChannelMessageContext deferredMsgContext = new DeferredChannelMessageContext())  // needed to keep redis happy
                {
                    // Set the context to the owner of the scheduled item.
                    var scheduledItem = Entity.Get <ScheduledItem>(jobRef);

                    if (scheduledItem == null)
                    {
                        Diagnostics.EventLog.Application.WriteTrace($"Attempted to start a job which references a nonexistant item. Ignoring. JobContext: {jobContext.ToString()}");
                        return;
                    }

                    if (RunAsOwner)
                    {
                        var owner = scheduledItem.SecurityOwner;

                        if (owner == null)
                        {
                            var message = $"Unable to start scheduled job as import configuration has no owner";
                            Diagnostics.EventLog.Application.WriteError($"StartImportJob.Execute: {message}. {scheduledItem.Id}");
                            throw GenerateJobException(message, scheduledItem);
                        }

                        var identityInfo = new IdentityInfo(owner.Id, owner.Name);
                        var contextData  = new RequestContextData(RequestContext.GetContext());
                        contextData.Identity = identityInfo;

                        using (CustomContext.SetContext(contextData))
                        {
                            Execute(jobRef);
                        }
                    }
                    else
                    {
                        Execute(jobRef);
                    }
                }
            }
            catch (JobExecutionException ex)
            {
                EDC.ReadiNow.Diagnostics.EventLog.Application.WriteTrace("Job execution exception. Ex: {0}", ex.ToString());
                throw;  // The job has already handled the problem and taken action.
            }
            catch (PlatformSecurityException ex)
            {
                Diagnostics.EventLog.Application.WriteError($"Platform security exception thrown to scheduler. This should never occur. Ex: {ex}");
            }
            catch (Exception ex)
            {
                Diagnostics.EventLog.Application.WriteError("Exception thrown to scheduler. This should never occur and should be handled by the scheduled item. Ex: {0}", ex.ToString());
            }

            stopWatch.Stop();
            perfCounters.GetPerformanceCounter <AverageTimer32PerformanceCounter>(WorkflowPerformanceCounters.ScheduleJobDurationCounterName).AddTiming(stopWatch);
        }