コード例 #1
0
 public Job ReadJob(string name)
 {
     lock (this._sync)
     {
         if (System.IO.File.Exists(this._path + System.IO.Path.DirectorySeparatorChar + System.Web.HttpUtility.UrlEncode(name)))
         {
             System.IO.Stream stream    = System.IO.File.OpenRead(this._path + System.IO.Path.DirectorySeparatorChar + System.Web.HttpUtility.UrlEncode(name));
             JobReader        jobReader = new JobReader(stream);
             Job job = jobReader.Read();
             stream.Close();
             return(job);
         }
         else
         {
             throw new System.Exception("Cannot read job.  Job does not exist: " + name);
         }
     }
 }
コード例 #2
0
        private void Run()
        {
            if (System.IO.Directory.Exists(this._path))
            {
                foreach (string file in System.IO.Directory.GetFiles(this._path))
                {
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(file);
                    if (!fileInfo.Name.EndsWith(".tmp"))
                    {
                        System.IO.Stream stream    = System.IO.File.OpenRead(file);
                        JobReader        jobReader = new JobReader(stream);
                        Job job = jobReader.Read();
                        this._jobs.Add(job.Name, job);
                        stream.Close();
                    }
                }
            }


            Bamboo.DataStructures.Table jobTimes       = this._database.ReadTable("Statibase.JobSummary");
            Dictionary <string, long>   jobTimesLookup = new Dictionary <string, long>();

            foreach (Bamboo.DataStructures.Tuple row in jobTimes.Rows)
            {
                jobTimesLookup.Add((string)row[0], (long)row[1]);
            }


            while (true)
            {
                List <Job> jobs = new List <Job>();
                lock (this._sync)
                {
                    foreach (Job job in this._jobs.Values)
                    {
                        jobs.Add(job);
                    }
                }

                System.DateTime now2 = System.DateTime.Now;
                long            now  = now2.Ticks;

                foreach (Job job in jobs)
                {
                    //TODO do this in memory.
                    long lastRun = 0;
                    if (jobTimesLookup.ContainsKey(job.Name))
                    {
                        lastRun = jobTimesLookup[job.Name];
                    }


                    switch (job.Type)
                    {
                    case JobType.Interval:
                    {
                        long next = lastRun + job.Interval.Ticks;
                        if (next < now)
                        {
                            this._threadPool.Enqueue(new Bamboo.Threading.ThreadTask(this._method, this, job));
                            jobTimesLookup[job.Name] = now;
                        }
                        break;
                    }

                    case JobType.Daily:
                    {
                        System.DateTime lastRunDate = new System.DateTime(lastRun);
                        if (!lastRunDate.Date.Equals(now2.Date) && job.Time.TimeOfDay < now2.TimeOfDay)
                        {
                            this._threadPool.Enqueue(new Bamboo.Threading.ThreadTask(this._method, this, job));
                            jobTimesLookup[job.Name] = now;
                        }
                        break;
                    }

                    case JobType.Weekly:
                    {
                        if (job.Days.Contains(GetDay(System.DateTime.Now.DayOfWeek)))
                        {
                            System.DateTime lastRunDate = new System.DateTime(lastRun);
                            if (!lastRunDate.Date.Equals(now2.Date) && job.Time.TimeOfDay < now2.TimeOfDay)
                            {
                                this._threadPool.Enqueue(new Bamboo.Threading.ThreadTask(this._method, this, job));
                                jobTimesLookup[job.Name] = now;
                            }
                        }
                        break;
                    }
                    }
                }

                System.Threading.Thread.Sleep(500);
            }
        }