public async Task RegisterJob(string countryId, Uri domain, string path, SiteSpeedSettings settings) { _log.Info($"Registering job for [{domain}][{path}] in country [{countryId}]"); var job = JobBuilder.Create <SiteSpeedJob>() .SetJobData(new JobDataMap() { { SiteSpeedJobDataKeys.Domain, domain }, { SiteSpeedJobDataKeys.Path, path }, { SiteSpeedJobDataKeys.Settings, settings }, { SiteSpeedJobDataKeys.Country, countryId } }) .WithIdentity(path, domain.ToString()) .Build(); var trigger = TriggerBuilder.Create() .WithIdentity(path, domain.ToString()) .WithSimpleSchedule(builder => builder.RepeatForever().WithIntervalInMinutes(10)) .StartNow() .Build(); var dateTimeOffset = await _scheduler.ScheduleJob(job, trigger); _log.Info($"Job registered, starting @ [{dateTimeOffset.DateTime}]"); }
public async Task <IStartupServiceResult> Run() { _logger.Trace("ActivateSitespeedJobs::Run() >>"); var sites = _dataContext.Sites .Include(dao => dao.Pages) .ThenInclude(x => x.Countries) .Include(dao => dao.Countries); foreach (var site in sites) { foreach (var sitePage in site.Pages) { var conf = new SiteSpeedSettings() { BrowserTime = new BrowserTimeSettings() { Browser = BrowserType.Chrome, Connectivity = new StandardConnectivitySettings(ConnectivityProfile.Fast3G), SpeedIndex = true, Video = true, Iterations = 1 }, Mobile = true }; var countryList = site.Countries.Select(x => x.CountryId); if (sitePage.OverridesSiteCountryList) { countryList = sitePage.Countries.Select(x => x.CountryId); } _logger.Info($"Activating scheduled job for page [{site.Domain}/{sitePage.Path}] for countries [{string.Join(",", countryList)}"); foreach (var country in countryList) { await _siteSpeedJobBuilder.RegisterJob(country, new Uri(site.Domain), sitePage.Path, conf); } } } _logger.Trace("ActivateSitespeedJobs::Run() <<"); return(new SuccessfulStartupServiceResult()); }