Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        public void SendResult(string client)
        {
            Job job = GetOrCreateJob(client);

            using (AutoMonitor m = new AutoMonitor(job.ExecuteLock, MonitorTimeout))
            {
                if (m.Entered)
                {
                    if (job.Status == JobStatus.Running)
                    {
                        try
                        {
                            job.Message = HttpCurrentContext.Body;
                            HttpCurrentContext.Close();
                            job.Status = JobStatus.Finished;
                            Log.Default.Trace("Client:{0} Finished", client);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        HttpCurrentContext.Close(HttpStatusCode.Forbidden, string.Format("Current job status is: {0}", job.Status.ToString()));
                    }
                }
                else
                {
                    HttpCurrentContext.Close(HttpStatusCode.Forbidden, Error_HavePendingRequestAlready);
                }
            }
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }