예제 #1
0
        /// <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();
        }
예제 #2
0
        public async Task <CreateContestResponse> CreateAsync(CreateContestRequest contest)
        {
            var exists = await _contestRepository.FindByTopicAsync(contest.Topic);

            if (exists != null)
            {
                throw new Exception("A contest with the same Topic already exists.");
            }

            var result =
                await _contestRepository.CreateAsync(ContestMapper.MapCreateContestRequestToContestStorage(contest));

            if (contest.Current)
            {
                await _contestRepository.SetCurrentAsync(result);

                // Schedule contest closing job
                var job = new SimpleJob(async scheduledTime =>
                {
                    await UpdateAsync(result, new UpdateContestRequest
                    {
                        Closed = true
                    });
                });

                _singularity.ScheduleJob(new RunOnceSchedule(TimeSpan.FromMinutes(1)), job, false);
            }

            return(new CreateContestResponse {
                Id = result
            });
        }
예제 #3
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);
        }