public void ShouldNotScheduleJobIfJobIsRunning() { // Arrange RunningJobs runningJobs = new RunningJobs(); var scheduleManagerMock = new Mock <IScheduleJobManager>(); var siteSocialAccount = new SiteSocialAccount { SiteId = 10000, FacebookPageId = "123" }; Action <TriggerBuilder> configuerTriggerAction = t => { }; // Act runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); // Assert scheduleManagerMock.Verify(mock => mock.ScheduleAsync <TestJob, SiteSocialAccount>(It.IsAny <Action <JobBuilder> >(), configuerTriggerAction, siteSocialAccount), Times.Once); }
protected async override Task ExecuteJob(IJobExecutionContext context) { // schedule job for every site List <int> facebookSiteIds = await _siteSocialAccountService.GetFacebookSiteIdsAsync(); if (facebookSiteIds != null && facebookSiteIds.Any()) { foreach (var siteId in facebookSiteIds) { RunningJobs.Schedule <PullTaggedVisitorPostsJob>(_scheduleJobManager, siteId, CronTrigger(AppSettings.FacebookPullTaggedVisitorPostsJobCronExpression)); //RunningJobs.Schedule<PullVisitorPostsFromFeedJob>(_scheduleJobManager, siteId, CronTrigger(AppSettings.FacebookPullVisitorPostsFromFeedJobCronExpression)); //RunningJobs.Schedule<PullMessagesJob>(_scheduleJobManager, siteId, CronTrigger(AppSettings.FacebookPullMessagesJobCronExpression)); RunningJobs.Schedule <GetRawDataJob>(_scheduleJobManager, siteId, CronTrigger(AppSettings.FacebookGetRawDataJobCronExpression)); } } // schedule job for every site //List<int> twitterSiteIds = await _siteSocialAccountService.GetTwitterSiteIdsAsync(); //if (twitterSiteIds != null && twitterSiteIds.Any()) //{ // foreach (var siteId in twitterSiteIds) // { // RunningJobs.Schedule<TwitterPullTweetsJob>(_scheduleJobManager, siteId, CronTrigger(AppSettings.TwitterPullTweetsJobCronExpression)); // RunningJobs.Schedule<TwitterPullDirectMessagesJob>(_scheduleJobManager, siteId, CronTrigger(AppSettings.TwitterPullDirectMessagesJobCronExpression)); // } //} // schedule job for every twitter integration account List <SiteSocialAccount> twitterAccounts = await _siteSocialAccountService.GetTwitterSiteAccountsAsync(); if (twitterAccounts != null && twitterAccounts.Any()) { foreach (var twitterAccount in twitterAccounts) { RunningJobs.Schedule <TwitterUserStreamJob>(_scheduleJobManager, twitterAccount, StartNowTrigger()); } } RunningJobs.StopTimeoutJobs(context.Scheduler); }
public void ShouldUpdateLastScheduleTime() { // Arrange RunningJobs runningJobs = new RunningJobs(); var scheduleManagerMock = new Mock <IScheduleJobManager>(); var siteSocialAccount = new SiteSocialAccount { SiteId = 10000, FacebookPageId = "123" }; Action <TriggerBuilder> configuerTriggerAction = t => { }; // Act runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); DateTime firstScheduleTime = runningJobs.Get <TestJob>(siteSocialAccount.SiteId, siteSocialAccount.FacebookPageId).LastScheduleTime; Thread.Sleep(100); runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); DateTime secondScheduleTime = runningJobs.Get <TestJob>(siteSocialAccount.SiteId, siteSocialAccount.FacebookPageId).LastScheduleTime; // Assert Assert.NotEqual(firstScheduleTime, secondScheduleTime); Assert.True(secondScheduleTime > firstScheduleTime); }
public void ShouldRemoveRunningJob() { // Arrange RunningJobs runningJobs = new RunningJobs(); var scheduleManagerMock = new Mock <IScheduleJobManager>(); var siteSocialAccount = new SiteSocialAccount { SiteId = 10000, FacebookPageId = "123" }; Action <TriggerBuilder> configuerTriggerAction = t => { }; // Act runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); runningJobs.Remove <TestJob>(siteSocialAccount.SiteId, siteSocialAccount.FacebookPageId); var runningJob = runningJobs.Get <TestJob>(siteSocialAccount.SiteId, siteSocialAccount.FacebookPageId); // Assert Assert.Null(runningJob); }
public void ShouldGetRunningJob() { // Arrange RunningJobs runningJobs = new RunningJobs(); var scheduleManagerMock = new Mock <IScheduleJobManager>(); var siteSocialAccount = new SiteSocialAccount { SiteId = 10000, FacebookPageId = "123" }; Action <TriggerBuilder> configuerTriggerAction = t => { }; // Act runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); var runningJob = runningJobs.Get <TestJob>(siteSocialAccount.SiteId, siteSocialAccount.FacebookPageId); // Assert Assert.NotNull(runningJob); Assert.Equal(10000, runningJob.SiteId); Assert.Equal("123", runningJob.OriginalAccountId); Assert.Equal("TestJob - SiteId(10000) - OriginalId(123)", runningJob.JobKey); Assert.Equal("TestJob", runningJob.JobGroup); }
public void ShouldStopTimeoutRunningJobs() { // Arrange RunningJobs runningJobs = new RunningJobs(); var scheduleManagerMock = new Mock <IScheduleJobManager>(); var siteSocialAccount = new SiteSocialAccount { SiteId = 10000, FacebookPageId = "123" }; Action <TriggerBuilder> configuerTriggerAction = t => { }; var schedulerMock = new Mock <IScheduler>(); schedulerMock.Setup(t => t.GetJobDetail(It.IsAny <JobKey>())).Returns(new Mock <IJobDetail>().Object); // Act runningJobs.Schedule <TestJob>(scheduleManagerMock.Object, siteSocialAccount, configuerTriggerAction); var runningJob = runningJobs.Get <TestJob>(siteSocialAccount.SiteId, siteSocialAccount.FacebookPageId); runningJob.LastScheduleTime = DateTime.UtcNow.AddSeconds(-301); runningJobs.StopTimeoutJobs(schedulerMock.Object); // Assert schedulerMock.Verify(t => t.DeleteJob(It.Is <JobKey>(r => r.Name == "TestJob - SiteId(10000) - OriginalId(123)"))); Assert.False(runningJobs.IsRunning <TestJob>(10000, "123")); }