public void ErrorDuringSchedule() { _writeMock.errorForPrefix = "Add Schedules"; var newJobs = JsonConvert.DeserializeObject <NewJobs>( File.ReadAllText( Path.Combine("..", "..", "..", "sample-newjobs", "fixtures-queues.json")), jsonSettings ); _writeJobs.Invoking(x => x.AddJobs(newJobs, null)) .Should() .Throw <Exception>() .WithMessage("Sample error"); ShouldMatchSnapshot(_writeMock.UpdateSchedules, "fixtures-queues-updatesch.json"); ShouldMatchSnapshot(_writeMock.DeletePartsPals, "fixtures-queues-delparts.json"); ShouldMatchSnapshot(_writeMock.Fixtures, "fixtures-queues-fixtures.json", AdjustProgramPath); ShouldMatchSnapshot(_writeMock.AddParts, "fixtures-queues-parts.json"); ShouldMatchSnapshot(_writeMock.AddSchedules, "fixtures-queues-schedules.json"); var start = newJobs.Jobs.First().RouteStartingTimeUTC; _jobDB.LoadJobsNotCopiedToSystem(start, start.AddMinutes(1)).Jobs .Should().BeEquivalentTo( newJobs.Jobs, options => options .Excluding(j => j.Comment) .Excluding(j => j.HoldEntireJob)); //try again still with error _writeMock.AddSchedules = null; _writeJobs.Invoking(x => x.RecopyJobsToMazak(start)) .Should() .Throw <Exception>() .WithMessage("Sample error"); ShouldMatchSnapshot(_writeMock.AddSchedules, "fixtures-queues-schedules.json"); _jobDB.LoadJobsNotCopiedToSystem(start, start.AddMinutes(1)).Jobs .Should().BeEquivalentTo( newJobs.Jobs, options => options .Excluding(j => j.Comment) .Excluding(j => j.HoldEntireJob)); //finally succeed without error _writeMock.errorForPrefix = null; _writeJobs.RecopyJobsToMazak(start); ShouldMatchSnapshot(_writeMock.AddSchedules, "fixtures-queues-schedules.json"); _jobDB.LoadJobsNotCopiedToSystem(start, start.AddMinutes(1)).Jobs.Should().BeEmpty(); }
public void RecopyJobsToSystem() { try { if (!OpenDatabaseKitDB.MazakTransactionLock.WaitOne(TimeSpan.FromMinutes(2), true)) { throw new Exception("Unable to obtain mazak database lock"); } try { _writeJobs.RecopyJobsToMazak(); } finally { OpenDatabaseKitDB.MazakTransactionLock.ReleaseMutex(); } } catch (Exception ex) { Log.Error(ex, "Error recopying job schedules to mazak"); } }