Esempio n. 1
0
        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);
        }