Пример #1
0
        /// <summary>
        /// Async wrapper for Commerce Worker Role
        /// </summary>
        /// <returns>
        /// A Task to be waited on
        /// </returns>
        private async Task RunAsync()
        {
            Log.Verbose("Running Commerce Worker role.");

            Log.Verbose("Checking if we can start processing jobs ...");
            while (!ProcessJobs)
            {
                // is it fine ? too fast or slow?
                // we will finetune this after few tries on prod.
                Thread.Sleep(CommerceWorkerConfig.Instance.ProcessingLoopPollingInterval);
            }

            Log.Verbose("Entering processing loop.");

            do
            {
                try
                {
                    Thread.Sleep(CommerceWorkerConfig.Instance.ProcessingLoopPollingInterval);
                    ScheduledJobDetails jobDetails = await Scheduler.GetJobToProcessAsync();

                    if (jobDetails != null)
                    {
                        IJobRunner runner = JobRunnerFactory.Runner(
                            jobDetails, Scheduler, CommerceWorkerConfig.Instance, Log);
                        Log.Information("Running {0} job.", jobDetails.JobType);

                        Tuple <IScheduler, ScheduledJobDetails> timerState = new Tuple <IScheduler, ScheduledJobDetails>(Scheduler, jobDetails);
                        using (Timer tmr = new Timer(ExtendTimeout, timerState, WhenToExtendTimeout, WhenToExtendTimeout))
                        {
                            await runner.RunJobAsync(jobDetails);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Critical("An unknown error occurred during processing.", ex);
                }
            }while (ProcessJobs);

            Log.Information("Processing loop has exited.");

            // We are no longer processing jobs new now...just waiting to be killed when processing ends.
            while (!ExitRole)
            {
#if !IntDebug && !IntRelease
                Log.Information("Wating for role to exit ...");
#endif
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            Log.Information("Role is shutting down ...");
        }
Пример #2
0
        public static void Main(string[] args)
        {
            const string path = @"d:\\tick-tock";

            BlobRepository blobs = BlobRepositoryFactory.Create(with =>
            {
                with.Location = Path.Combine(path, "blobs");
            });

            JobExecutionRepository executions = JobExecutionRepositoryFactory.Create(with =>
            {
                with.Location = Path.Combine(path, "executions");
            });

            JobRepository jobs = JobRepositoryFactory.Create(with =>
            {
                with.Location = Path.Combine(path, "jobs");
            });

            JobTaskRepository tasks = JobTaskRepositoryFactory.Create(with =>
            {
                with.Blobs      = blobs;
                with.Executions = executions;
            });

            JobRunner runner = JobRunnerFactory.Create(with =>
            {
                with.Executions = executions;
                with.Jobs       = jobs;
                with.Tasks      = tasks;
            });

            Bootstrapper bootstrapper = new Bootstrapper(path);
            Uri          uri          = new Uri("http://localhost:1234");

            using (var host = new NancyHost(bootstrapper, uri))
            {
                host.Start();

                while (true)
                {
                    runner.Run();
                    Thread.Sleep(TimeSpan.FromSeconds(10));
                }
            }
        }