コード例 #1
0
ファイル: JobProxy.cs プロジェクト: AllenLius/dtf
        public void GetJobWait(string client)
        {
            Job job = GetOrCreateJob(client);

            using (AutoMonitor m = new AutoMonitor(job.ExecuteLock, MonitorTimeout))
            {
                if (m.Entered)
                {
                    DateTime start = DateTime.Now;
                    if (Wait(job, JobStatus.Scheduled, LongLoopTimeout))
                    {
                        //Log.Default.Trace(" Client:{0} job:{1}", client, job.Message);
                        try
                        {
                            HttpCurrentContext.Close(HttpStatusCode.OK, job.Message);
                            job.Status = JobStatus.Running;
                            Log.Default.Trace("Client:{0} Running", client);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        HttpCurrentContext.CloseAsTimeout();
                    }
                }
                else
                {
                    HttpCurrentContext.Close(HttpStatusCode.Forbidden, Error_HavePendingRequestAlready);
                }
            }
        }
コード例 #2
0
ファイル: JobProxy.cs プロジェクト: AllenLius/dtf
        public void ExecuteJob(string client)
        {
            Job job = GetOrCreateJob(client);

            using (AutoMonitor m = new AutoMonitor(job.InvokeLock, MonitorTimeout))
            {
                if (m.Entered)
                {
                    if (job.Status == JobStatus.Idle)
                    {
                        try
                        {
                            job.Message = HttpCurrentContext.Body;
                            job.Status  = JobStatus.Scheduled;
                            //Log.Default.Trace(" Client:{0} Job:{1}", client, job.Message);
                            if (Wait(job, JobStatus.Finished, ExecuteTimeout))
                            {
                                string msg = job.Message;
                                msg = msg.Length > 1000 ? msg.Substring(0, 1000) : msg;
                                //Log.Default.Trace(" Client:{0} Result:{1}", client, msg);
                                HttpCurrentContext.Close(HttpStatusCode.OK, job.Message);
                            }
                            else
                            {
                                HttpCurrentContext.CloseAsTimeout();
                            }
                        }
                        catch (Exception)
                        {
                        }
                        finally
                        {
                            job.Status = JobStatus.Idle;
                            Log.Default.Trace("Client:{0} Idle", client);
                        }
                    }
                    else
                    {
                        HttpCurrentContext.Close(HttpStatusCode.Forbidden, "Job status not Idle!");
                    }
                }
                else
                {
                    HttpCurrentContext.Close(HttpStatusCode.Forbidden, Error_HavePendingRequestAlready);
                }
            }
        }