Beispiel #1
0
            JobTimed getNextTimedJob()
            {
                JobTimed nextJob  = null;
                TimeSpan awaiting = new TimeSpan(0);

                foreach (var job in timedJobs_)
                {
                    // first execute
                    if (job.NextExecute == job.LastExecute)
                    {
                        job.LastExecute = Manager.Timer.Ticks;
                        return(job);
                    }

                    TimeSpan wait = Manager.Timer.Ticks - job.NextExecute;
                    if (wait > awaiting)
                    {
                        nextJob  = job;
                        awaiting = wait;
                    }
                }

                if (awaiting <= Manager.Timer.Ticks)
                {
                    return(nextJob);
                }
                return(null);
            }
Beispiel #2
0
            public bool unregisterTimedJob(JobTimed job)
            {
                if (job == null)
                {
                    return(false);
                }

                return(timedJobs_.Remove(job));
            }
Beispiel #3
0
            public override void tick(TimeSpan delta)
            {
                if (queuedJobs_.Count > 0 || curQueuedJob_ != null)
                {
                    while (App.Runtime.CurrentInstructionCount <= Default.MaxInstructionCount && (queuedJobs_.Count > 0 || curQueuedJob_ != null))
                    {
                        try
                        {
                            // process queued jobs
                            if (curQueuedJob_ != null)
                            {
                                curQueuedJob_.tick(Manager.Timer.Ticks - curQueuedJobLastExecute_);
                                curQueuedJobLastExecute_ = Manager.Timer.Ticks;
                                queuedJobCountExecutes_++;

                                if (curQueuedJob_.JobFinished)
                                {
                                    curQueuedJob_.finalizeJob();
                                    curQueuedJob_.LastExecute = Manager.Timer.Ticks;
                                    queuedJobCountFinished_++;
                                    curQueuedJob_ = null;
                                }
                            }
                            else if (queuedJobs_.Count > 0)
                            {
                                curQueuedJob_ = queuedJobs_.First.Value;
                                queuedJobs_.RemoveFirst();
                                curQueuedJob_.prepareJob();
                                curQueuedJobLastExecute_ = Manager.Timer.Ticks;
                            }
                        }
                        catch (Exception exp)
                        {
                            if (!curQueuedJob_.handleException())
                            {
                                throw exp;
                            }
                            curQueuedJob_ = null;
                            App.statistics_.registerException(exp);
                        }
                    }
                }
                else
                {
                    // we have a timed job...
                    JobTimed timedJob = getNextTimedJob();
                    if (timedJob != null)
                    {
                        timedJob.tick(Manager.Timer.Ticks - timedJob.LastExecute);
                        timedJob.LastExecute = Manager.Timer.Ticks;
                        timedJob.NextExecute = timedJob.LastExecute + timedJob.Interval;
                        jobCountLastUpdate_++;
                    }
                }
            }
Beispiel #4
0
            public bool registerTimedJob(JobTimed job)
            {
                if (job != null)
                {
                    if (getTimedJob(job.JobId) == null)
                    {
                        timedJobs_.Add(job);
                        return(true);
                    }
                    else
                    {
                        log(Console.LogType.Error, $"Job '{job.JobId}' already registered");
                    }
                }

                return(false);
            }