public string RunTask(int id) { try { ScheduledTask s = new ScheduledTask().Get(id); s.Run(); return ""; } catch (Exception e) { return e.Message; } }
public void Run_Exception_Success() { DateTimeOffset now = new DateTimeOffset(2013, 6, 1, 12, 0, 0, 0, TimeSpan.Zero); DateTimeOffset now2 = new DateTimeOffset(2013, 6, 1, 12, 0, 1, 0, TimeSpan.Zero); ScheduledTask <FailableScheduledAction> task = new ScheduledTask <FailableScheduledAction>(Schedule.CreateOneTime(now), new FailableScheduledAction(FailableScheduledAction.DummyAction.ThrowException), true, now, now2); SimpleSchedulerAction action = new SimpleSchedulerAction(); task.Run(action); Assert.IsFalse(action.IsSuccess); Assert.IsFalse(action.IsCanceled); Assert.IsNotNull(action.Exception, nameof(action.Exception)); Assert.IsNull(action.State, nameof(action.State)); }
public Task StartAsync(CancellationToken cancellationToken) { _scheduler = ScheduledTask.Run(async() => { _logger.LogInformation("Initiating update..."); try { foreach (var source in await _sources.All().ToListAsync()) { _logger.LogInformation($"Updating {source.Name}..."); var addedArticleCount = 0; var articles = await FeedLoader.ArticlesFrom(source); var urls = source.Articles .OrderByDescending(article => article.PublishDate) .Take(articles.Count * 2) .Select(article => article.Url) .ToHashSet(); foreach (var article in articles) { if (!urls.Contains(article.Url)) { source.Articles.Add(article); addedArticleCount++; } } await _sources.Update(source); _logger.LogInformation($"{source.Name} finished. {addedArticleCount} added."); } _logger.LogInformation("Update finished."); } catch (Exception ex) { _logger.LogError(ex, "Update failed."); } }, TimeSpan.FromMinutes(5), _cancellationTokenSource.Token); return(Task.CompletedTask); }