Ejemplo n.º 1
0
        public void GetWorkerTaskInstanceTest()
        {
            var factory = new WorkerTaskFactory();

            var task = factory.GetWorkerTaskInstance(typeof(WorkerFactoryTestTask));

            Assert.That(task, Is.Not.Null);
        }
Ejemplo n.º 2
0
        public override void Run()
        {
            var workerTaskFactory = new WorkerTaskFactory();

            while (!IsStopped)
            {
                try
                {
                    var taskContext = new TaskContext(Storage);

                    var message = Queue.GetMessage();
                    if (message != null)
                    {
                        try
                        {
                            var taskRequest = new TaskRequest(message);
                            try
                            {
                                var workerTaskType = workerTaskFactory.GetWorkerTaskType(taskRequest.TaskName);
                                var workerTask = workerTaskFactory.GetWorkerTaskInstance(workerTaskType);

                                var result = workerTask.Execute(taskRequest);

                                result.Execute(taskRequest, taskContext);
                            }
                            catch (Exception ex)
                            {
                                new ErrorResult(ex).Execute(taskRequest, taskContext);
                            }
                        }
                        finally
                        {
                            Queue.Acknowledge(message);
                        }
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }

                }
                catch (Exception ex)
                {
                    Trace.TraceError("Unhandled exception: {0}", ex);
                }
            }
        }