Ejemplo n.º 1
0
 // worker idle && connection isAvaliable
 private static bool IsWorkerAvaliable(DACWorker worker)
 {
     Log.DebugFormat("{0}", worker == null ? "worker is null" : worker.ToString());
     return(worker != null &&
            worker.GetContext() != null &&
            worker.IsIdle() &&
            worker.GetContext().IsAvaliable());
 }
Ejemplo n.º 2
0
            public void Execute(IJobExecutionContext context)
            {
                JobInfo ji = GetJobInfo(context.JobDetail);

                if (ji.Type == TaskType.INSTANT)
                {
                    Console.WriteLine("remove job {1} {0}", DateTime.Now, ji.Dtu.DtuId);
                    TryRemoveJob(ji.Dtu.DtuId);
                }
                log.InfoFormat("Execute Job {0} , type={1}", context.JobDetail.Key, ji.Type);
                try
                {
                    DACWorker worker = ji.Finder.FindWorker(ji.Dtu.DtuId);
                    DACTask   task   = new DACTask(ji.TID, ji.Dtu.DtuId, ji.Sensors, ji.Type, ji.Consumer, ji.ID);
                    if (ji.Type != TaskType.INSTANT)
                    {
                        task.TID = GetTaskGuid(ji.Dtu.DtuCode);
                    }
                    if (!IsWorkerAvaliable(worker))
                    {
                        log.InfoFormat("Worker not avaliable: job=[{0}], worker=[{1}]", ji, GetWorkerInfo(worker));
                        if (ji.Type == TaskType.INSTANT)
                        {
                            int errorcode;
                            if (worker != null && (worker.GetContext() == null || (worker.GetContext().DtuConnection == null) || (worker.GetContext().DtuConnection != null && !worker.GetContext().DtuConnection.IsOnline)))
                            {
                                errorcode = (int)Errors.ERR_NOT_CONNECTED;
                            }
                            else if (worker != null && !worker.IsIdle())
                            {
                                errorcode = (int)Errors.ERR_DTU_BUSY;
                            }
                            else
                            {
                                errorcode = (int)Errors.ERR_UNKNOW;
                            }
                            OnInstantTaskFinished(new FailedDACTaskResult(errorcode, task)
                            {
                                Finished = DateTime.Now
                            });
                        }
                        return;
                    }
                    log.InfoFormat("Worker start working. job={0}, worker=[{1}]", ji, GetWorkerInfo(worker));

                    if (task.Type == TaskType.INSTANT)
                    {
                        task.Consumer += OnInstantTaskFinished;
                    }
                    worker.NewTask(task);
                }
                catch (Exception e)
                {
                    log.Error("DTUDacJob Execute ERR", e);
                }
            }