示例#1
0
        /// <summary>Get the next job to run. Needs to be thread safe.</summary>
        /// <returns>The job to run or NULL if no more jobs to be run.</returns>
        private MultiProcessJob GetJobToRun()
        {
            var             jobKey = Guid.NewGuid();
            MultiProcessJob job    = null;

            SpinWait.SpinUntil(() => jobsToRun.TryDequeue(out job) || jobQueueFillerTask.IsCompleted);
            if (job == null)
            {
                return(null);
            }
            else if (job.RunnableJob is SimulationDescription)
            {
                job.DataStore       = (job.RunnableJob as SimulationDescription).Storage;
                job.JobSentToClient = (job.RunnableJob as SimulationDescription).ToSimulation();
                (job.JobSentToClient as Simulation).Services = null;
            }
            else
            {
                job.JobSentToClient = job.RunnableJob;
                if (job.JobSentToClient is IModel m)
                {
                    job.JobSentToClient = Apsim.Clone(m) as IRunnable;
                }
                if (job.RunnableJob is IModel model)
                {
                    IModel replacements = model.FindInScope <Replacements>();
                    if (replacements != null)
                    {
                        (job.JobSentToClient as IModel).Children.Add(Apsim.Clone(replacements));
                    }
                    job.DataStore = model.FindInScope <IDataStore>();
                    if (job.DataStore != null)
                    {
                        (job.JobSentToClient as IModel).Children.Add(Apsim.Clone(job.DataStore as IModel));
                    }
                }
            }

            return(job);
        }
示例#2
0
        /// <summary>Get the next job to run. Needs to be thread safe.</summary>
        /// <returns>The job to run or NULL if no more jobs to be run.</returns>
        private MultiProcessJob GetJobToRun()
        {
            var             jobKey = Guid.NewGuid();
            MultiProcessJob job    = null;

            SpinWait.SpinUntil(() => jobsToRun.TryDequeue(out job) || jobQueueFillerTask.IsCompleted);
            if (job == null)
            {
                return(null);
            }
            else if (job.RunnableJob is SimulationDescription)
            {
                job.DataStore       = (job.RunnableJob as SimulationDescription).Storage;
                job.JobSentToClient = (job.RunnableJob as SimulationDescription).ToSimulation();
            }
            else
            {
                job.JobSentToClient = job.RunnableJob;
            }

            return(job);
        }