Ejemplo n.º 1
0
        public static BackgroundTask CreateBackgroundTask(long triggerId, long entityId, int triggerDepth)
        {
            var runParams = new RunTriggersParams
            {
                TriggerDepth = triggerDepth,
                TriggerId    = triggerId,
                EntityId     = entityId
            };

            return(BackgroundTask.Create(HandlerKey, runParams));
        }
Ejemplo n.º 2
0
        public static BackgroundTask CreateBackgroundTask(WorkflowRun run, IWorkflowQueuedEvent resumeEvent)
        {
            if (resumeEvent == null)
            {
                throw new ArgumentNullException(nameof(resumeEvent));
            }

            var runParams = new ResumeWorkflowParams {
                WorkflowRunId = run.Id
            };

            return(BackgroundTask.Create(HandlerKey, runParams));
        }
Ejemplo n.º 3
0
        public void Runs( )
        {
            var edcTenantId = TenantHelper.GetTenantId("EDC", true);

            //static string result = "";
            _result = "";

            using (CountdownEvent evt = new CountdownEvent(1))
            {
                Action <DummyParam> act = (p) =>
                {
                    _result += p.S;
                    // ReSharper disable once AccessToDisposedClosure
                    evt.Signal( );
                };


                var handler = new DummyHandler {
                    Action = act
                };
                var qFactory = new RedisTenantQueueFactory("BackgroundTaskManagerTests " + Guid.NewGuid( ));
                var manager  = new BackgroundTaskManager(qFactory, handlers: handler.ToEnumerable( ))
                {
                    IsActive = true
                };

                try
                {
                    manager.EnqueueTask(edcTenantId, BackgroundTask.Create("DummyHandler", new DummyParam {
                        S = "a"
                    }));
                    Assert.That(_result, Is.Empty);

                    manager.Start( );

                    evt.Wait(DefaultTimeout);
                    evt.Reset( );

                    Assert.That(_result, Is.EqualTo("a"));

                    manager.EnqueueTask(edcTenantId, BackgroundTask.Create("DummyHandler", new DummyParam {
                        S = "b"
                    }));

                    evt.Wait(DefaultTimeout);
                    evt.Reset( );

                    Assert.That(_result, Is.EqualTo("ab"));

                    manager.Stop(5000);

                    manager.EnqueueTask(edcTenantId, BackgroundTask.Create("DummyHandler", new DummyParam {
                        S = "c"
                    }));

                    Assert.That(_result, Is.EqualTo("ab"));                              // c not processed
                }
                finally
                {
                    manager.Stop( );
                    var items = manager.EmptyQueue(edcTenantId);
                    Assert.That(items.Count( ), Is.EqualTo(1));
                }
            }
        }
Ejemplo n.º 4
0
        public void SerializeParams()
        {
            var p = new RunTriggersParams();

            BackgroundTask.Create <RunTriggersParams>("test", p);
        }
Ejemplo n.º 5
0
        public void Serialize <T>() where T : IWorkflowQueuedEvent, new()
        {
            var param = new T();

            BackgroundTask.Create <T>("test", param);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Convert a T to a background task
 /// </summary>
 public BackgroundTask ToBackgroundTask(T taskData)
 {
     return(BackgroundTask.Create(TaskHandlerKey, taskData));
 }