private void Run() { try { var m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Information, 0, m); var cloudContext = Guid.NewGuid().ToString(); var jobScheduler = new JobScheduler(cloudContext, traceSource, () => AzureConfiguration.Instance.AzureStorageAccount, new Settings()); traceSource.TraceEvent(TraceEventType.Information, 0, Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run", "Starting Paralel.Invoke", cloudContext)); Parallel.Invoke( jobScheduler.JobsManagerProcess, jobScheduler.SchedulerProcess); } catch (Exception ex) { var m = Helper.FormatException(ex, "WorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Error, 0, m); } }
public override void Run() { try { var m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Information, 0, m); string cloudContext; if (RoleEnvironment.IsAvailable) { cloudContext = String.Format("{0}|{1}", RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Id); } else { cloudContext = Guid.NewGuid().ToString(); } var jobScheduler = new JobScheduler(cloudContext, traceSource, () => AzureConfiguration.Instance.AzureStorageAccount, new Settings()); traceSource.TraceEvent(TraceEventType.Information, 0, Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run", "Starting Paralel.Invoke", cloudContext)); Parallel.Invoke( jobScheduler.JobsManagerProcess, jobScheduler.SchedulerProcess); } catch (Exception ex) { var m = Helper.FormatException(ex, "WorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Error, 0, m); } }
public void Scheduler5MinutesTest() { JobScheduler jobScheduler=null; try { string m = Helper.FormatTrace("Staring the Scheduler", "SchedulerWorkerRole", "Run"); var traceSource = new TraceSource("VirtoCommerce.ScheduleService.Trace"); traceSource.TraceEvent(TraceEventType.Information, 0, m); var connectionString = ConfigurationManager.ConnectionStrings["VirtoCommerce_AzureStorage"].ConnectionString; CloudStorageAccount storageAccount; CloudStorageAccount.TryParse(connectionString, out storageAccount); var schedulerDbContext = new TestISchedulerDbContext(); jobScheduler = new JobScheduler( schedulerDbContext, name => new TestISchedulerDbContext.TestJob(), "test-context", traceSource, () => storageAccount, new Settings("test") ); Task.Run( () => Parallel.Invoke( jobScheduler.JobsManagerProcess, jobScheduler.SchedulerProcess)); Thread.Sleep((5 * 60 * 1000) + 15 * 1000); //disable jobs, check that disablinng works - there are no tasks var jobs = schedulerDbContext.GetSystemJobs(); jobs.ForEach(j => j.IsEnabled = false); Thread.Sleep((1 * 60 * 1000)); Assert.Equal(schedulerDbContext.TaskSchedules.Count, 0); Assert.Equal(schedulerDbContext.Count, 12); Assert.Equal(schedulerDbContext.Error, 0); } finally { if (jobScheduler!=null) jobScheduler.Stop(); } }