public void JobsSettingsSetSuccessfully() { RunScenario("JobsSettingsSetSuccessfully", appManager => { const string triggeredJobName = "triggeredJob"; const string continuousJobName = "continuousJob"; const string settingKey = "mysetting"; const string settingValue = "myvalue"; TestTracer.Trace("Creating a triggered job and creating a continuous job"); appManager.JobsManager.CreateTriggeredJobAsync(triggeredJobName, "run.cmd", JobScript).Wait(); appManager.JobsManager.CreateContinuousJobAsync(continuousJobName, "run.cmd", JobScript).Wait(); TestTracer.Trace("Test update of continuous job settings"); JobSettings continuousJobSettings = appManager.JobsManager.GetContinuousJobSettingsAsync(continuousJobName).Result; Assert.Equal(null, continuousJobSettings.GetSetting <string>(settingKey)); continuousJobSettings.SetSetting(settingKey, settingValue); appManager.JobsManager.SetContinuousJobSettingsAsync(continuousJobName, continuousJobSettings).Wait(); continuousJobSettings = appManager.JobsManager.GetContinuousJobSettingsAsync(continuousJobName).Result; Assert.Equal(settingValue, continuousJobSettings.GetSetting <string>(settingKey)); TestTracer.Trace("Test update of triggered job settings"); JobSettings triggeredJobSettings = appManager.JobsManager.GetTriggeredJobSettingsAsync(triggeredJobName).Result; Assert.Equal(null, triggeredJobSettings.GetSetting <string>(settingKey)); triggeredJobSettings.SetSetting(settingKey, settingValue); appManager.JobsManager.SetTriggeredJobSettingsAsync(triggeredJobName, triggeredJobSettings).Wait(); triggeredJobSettings = appManager.JobsManager.GetTriggeredJobSettingsAsync(triggeredJobName).Result; Assert.Equal(settingValue, triggeredJobSettings.GetSetting <string>(settingKey)); }); }
private bool TryGetLockIfSingleton() { bool isSingleton = _jobSettings.GetSetting("is_singleton", defaultValue: false); if (!isSingleton) { return(true); } if (_singletonLock.Lock()) { return(true); } _continuousJobLogger.ReportStatus(ContinuousJobStatus.InactiveInstance); return(false); }
public void ContinuousJobStartsAfterGoingDown() { RunScenario("ContinuousJobStartsAfterGoingDown", appManager => { TestTracer.Trace("Copying the script to the continuous job directory"); appManager.JobsManager.CreateContinuousJobAsync("basicJob1", "run.cmd", JobScript).Wait(); var expectedContinuousJob = new ContinuousJob() { Name = "basicJob1", JobType = "continuous", Status = "PendingRestart", RunCommand = "run.cmd" }; WaitUntilAssertVerified( "verify continuous job", TimeSpan.FromSeconds(60), () => { ContinuousJob deployedJob = appManager.JobsManager.GetContinuousJobAsync("basicJob1").Result; AssertContinuousJob(expectedContinuousJob, deployedJob); }); TestTracer.Trace("Waiting for verification file to have 2 lines (which means it ran twice)"); var expectedVerificationFileContents = new List <string>(); expectedVerificationFileContents.Add(ExpectedVerificationFileContent); expectedVerificationFileContents.Add(ExpectedVerificationFileContent); WaitUntilAssertVerified( "verification file", TimeSpan.FromSeconds(30), () => VerifyVerificationFile(appManager, expectedVerificationFileContents.ToArray())); TestTracer.Trace("Verify continuous job settings and set it to isSingleton: true"); JobSettings continuousJobSettings = appManager.JobsManager.GetContinuousJobSettingsAsync(expectedContinuousJob.Name).Result; Assert.False(continuousJobSettings.IsSingleton); continuousJobSettings.SetSetting("is_singleton", true); appManager.JobsManager.SetContinuousJobSettingsAsync(expectedContinuousJob.Name, continuousJobSettings).Wait(); expectedVerificationFileContents.Add(ExpectedVerificationFileContent); expectedVerificationFileContents.Add(ExpectedVerificationFileContent); WaitUntilAssertVerified( "verification file", TimeSpan.FromSeconds(30), () => VerifyVerificationFile(appManager, expectedVerificationFileContents.ToArray())); TestTracer.Trace("Verify continuous job settings and set it to isSingleton: false"); continuousJobSettings = appManager.JobsManager.GetContinuousJobSettingsAsync(expectedContinuousJob.Name).Result; Assert.True(continuousJobSettings.GetSetting <bool>("is_singleton")); continuousJobSettings.SetSetting("is_singleton", false); appManager.JobsManager.SetContinuousJobSettingsAsync(expectedContinuousJob.Name, continuousJobSettings).Wait(); expectedVerificationFileContents.Add(ExpectedVerificationFileContent); expectedVerificationFileContents.Add(ExpectedVerificationFileContent); WaitUntilAssertVerified( "verification file", TimeSpan.FromSeconds(30), () => VerifyVerificationFile(appManager, expectedVerificationFileContents.ToArray())); }); }