Exemple #1
0
        public Response <TaskRequest> RequestWork(WorkerRequest request)
        {
            Logger.Info(string.Format("RequestWork Begin {0} {1}", DateTime.Now.Ticks,
                                      Thread.CurrentThread));

            lock (_object)
            {
                var registration = _registry.GetRegistration(request.Token);
                Assumes.NotNull(registration);
                WorkItem workItem =
                    _repository.Query <WorkItem>().FirstOrDefault(wi => wi.Status == (WorkItemStatus.Pending));

                Task task = null;
                if (workItem != null)
                {
                    task = _mappingEngine.Map <Task>(workItem);
                    workItem.AssignTo(registration);
                    _repository.Put(workItem);
                }
                var taskRequest = new TaskRequest {
                    NoWorkAvailable = task == null, Task = task
                };
                Logger.Info("RequestWork End " + DateTime.Now.Ticks + " " + Thread.CurrentThread);

                return(new Response <TaskRequest>(true, "", taskRequest));
            }
        }