/// <summary> /// Configure the background scheduler that updates the calendar in the background /// </summary> private static void SetUpBackgroundJob() { if (backgroundUpdateScheduler == null) { ISingularityFactory factory = new SingularityFactory(); backgroundUpdateScheduler = factory.GetSingularity(); } if (backgroundUpdateJob == null) { backgroundUpdateJob = new SimpleJob(scheduledTime => UpdateGoogleCalendar()); } if (scheduledUpdateJob != null) { backgroundUpdateScheduler.StopScheduledJob(scheduledUpdateJob); scheduledUpdateJob = null; backgroundUpdateScheduler.Stop(); } if (_runInMinutes > 0) { var schedule = new EveryXTimeSchedule(TimeSpan.FromMinutes(_runInMinutes)); scheduledUpdateJob = backgroundUpdateScheduler.ScheduleJob(schedule, backgroundUpdateJob, true); } backgroundUpdateScheduler.Start(); }
private void ScheduleClaymoreJob() { this.logger.LogDebug("Scheduling Claymore Job!"); ISingularity singularity = Singularity.Instance; ISchedule schedule = new CronSchedule(settings.ClaymoreSchdeule); var job = new SimpleJob(scheduledTime => { this.logger.LogInformation("Executing claymore job!"); this.claymoreClient.requestStats() .Subscribe( (d) => { try { var utcDateTime = DateTime.UtcNow; var tuples = d.ToMetrics(utcDateTime, this.settings.MetricsTopicPrefix); foreach (var tuple in tuples) { this.metricsQueue.Add(tuple); } this.metricsQueue.Add(this.InjectWallet(utcDateTime)); this.logger.LogInformation("Claymore data queued!"); } catch (Exception e) { this.logger.LogError("Failed to process claymore data: {0}", e); } }, (e) => { this.logger.LogError("Failed retrieving claymore data: {0}", e); if (this.settings.ClaymoreShouldReboot) { this.ExecuteRebootCommand(); } }, () => { this.logger.LogInformation("Claymore job completed!"); } ); }); var scheduledJob = singularity.ScheduleJob(schedule, job, true); var nextExecution = schedule.NextScheduledTime(scheduledJob); singularity.Start(); this.logger.LogDebug("Claymore Job scheduled with schedule: {0}!", schedule.ToString()); this.logger.LogDebug("Claymore Job's next scheduled execution: {0}!", nextExecution); }