/// <summary> /// Converts the <see cref="sourceValue" /> parameter to the <see cref="destinationType" /> parameter using <see cref="formatProvider" /// /> and <see cref="ignoreCase" /> /// </summary> /// <param name="sourceValue">the value to convert into an instance of <see cref="ExecutionSchedule" />.</param> /// <returns> /// an instance of <see cref="ExecutionSchedule" />, or <c>null</c> if there is no suitable conversion. /// </returns> public static object ConvertFrom(dynamic sourceValue) { if (null == sourceValue) { return(null); } try { ExecutionSchedule.FromJsonString(typeof(string) == sourceValue.GetType() ? sourceValue : sourceValue.ToJsonString()); } catch { // Unable to use JSON pattern } try { return(new ExecutionSchedule { StartTime = sourceValue.StartTime, TimeZone = sourceValue.TimeZone, TimeoutSecs = sourceValue.TimeoutSecs, }); } catch { } return(null); }
public async Task <CommandResult> Handle(RecalculateExecutionScheduleCommand request, CancellationToken cancellationToken) { var stopwatch = new Stopwatch(); stopwatch.Start(); ExecutionSchedule schedule = await _entitiesRepository.GetFirstOrDefaultAsync <ExecutionSchedule>(st => st.Name == request.Name); if (schedule == null) { throw new InvalidExecutionScheduleException("Execution Schedule with name " + request.Name + " is invalid."); } var executionScheduleLock = await _node.Handle(new RequestDataShard() { Type = schedule.ShardType, ObjectId = schedule.Id, CreateLock = true, LockTimeoutMs = 10000 }); ExecutionSchedule existingValue; if (executionScheduleLock.IsSuccessful && executionScheduleLock.AppliedLocked) { existingValue = (ExecutionSchedule)executionScheduleLock.Data; existingValue.UpdateJournal(new Domain.Entities.JournalEntries.JournalEntry() { CreatedOn = DateTime.UtcNow, Updates = new List <Domain.ValueObjects.Update>() { new Update() { Type = UpdateType.Override, FieldName = "nextrun", Value = SchedulerUtility.NextOccurence(existingValue.Schedule, DateTime.UtcNow) } } }); var result = await _node.Handle(new AddShardWriteOperation() { Operation = ConsensusCore.Domain.Enums.ShardOperationOptions.Update, WaitForSafeWrite = true, Data = existingValue, RemoveLock = true }); } stopwatch.Stop(); return(new CommandResult <ExecutionSchedule>() { ObjectRefId = schedule.Id.ToString(), ElapsedMs = stopwatch.ElapsedMilliseconds, Type = CommandResultTypes.Update, Result = schedule }); }
public WorkerScheduledExecutionForm(string scheduleXml) { InitializeComponent(); UserInterfaceStyler.Configure(this, FormStyle.FixedDialog); errorProvider.SetIconAlignment(hourMin_Label, ErrorIconAlignment.MiddleRight); if (!string.IsNullOrEmpty(scheduleXml)) { try { _bindingList.Clear(); _schedule = LegacySerializer.DeserializeXml <ExecutionSchedule>(scheduleXml); _bindingList = _schedule.BindingList; } catch (XmlException ex) { TraceFactory.Logger.Error("Bad XML in Run Schedule", ex); MessageBox.Show ( "Unable to load existing schedule information.", "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); } } else { _schedule = new ExecutionSchedule(); } dataGridViewCheckBoxColumn1.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridViewTextBoxColumn2.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridViewTextBoxColumn3.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridViewTextBoxColumn4.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; }
public async Task <CommandResult> Handle(UpdateExecutionScheduleCommand request, CancellationToken cancellationToken) { var stopwatch = new Stopwatch(); stopwatch.Start(); ExecutionSchedule schedule = await _entitiesRepository.GetFirstOrDefaultAsync <ExecutionSchedule>(st => st.Name == request.Name); if (schedule == null) { throw new InvalidExecutionScheduleException("Execution Schedule with name " + request.Name + " is invalid."); } if (request.Schedule != null) { foreach (var scheduleString in request.Schedule) { var isValid = SchedulerUtility.IsValidScheduleString(scheduleString); if (!isValid) { throw new InvalidExecutionScheduleException("Schedule " + scheduleString + " is invalid."); } } } var executionScheduleLock = await _node.Handle(new RequestDataShard() { Type = schedule.ShardType, ObjectId = schedule.Id, CreateLock = true }); ExecutionSchedule existingValue; List <Update> updates = new List <Update>(); if (request.IsDisabled != null && schedule.IsDisabled != request.IsDisabled) { updates.Add(new Update() { Type = UpdateType.Override, FieldName = "isdisabled", Value = request.IsDisabled }); } if (request.Schedule != null && schedule.Schedule != request.Schedule) { updates.Add(new Update() { Type = UpdateType.Override, FieldName = "nextrun", Value = SchedulerUtility.NextOccurence(request.Schedule, DateTime.UtcNow) }); updates.Add(new Update() { Type = UpdateType.Override, FieldName = "schedule", Value = request.Schedule }); } if (request.Description != null && schedule.Description != request.Description) { updates.Add(new Update() { Type = UpdateType.Override, FieldName = "description", Value = request.Description }); } if (executionScheduleLock.IsSuccessful && executionScheduleLock.AppliedLocked && updates.Count > 0) { existingValue = (ExecutionSchedule)executionScheduleLock.Data; existingValue.UpdateJournal(new Domain.Entities.JournalEntries.JournalEntry() { CreatedOn = DateTime.UtcNow, Updates = updates }); var result = await _node.Handle(new AddShardWriteOperation() { Operation = ConsensusCore.Domain.Enums.ShardOperationOptions.Update, WaitForSafeWrite = true, Data = existingValue, RemoveLock = true }); } stopwatch.Stop(); return(new CommandResult <ExecutionSchedule>() { ObjectRefId = schedule.Id.ToString(), ElapsedMs = stopwatch.ElapsedMilliseconds, Type = CommandResultTypes.Update, Result = schedule }); }
public async Task <CommandResult> Handle(CreateExecutionScheduleCommand request, CancellationToken cancellationToken) { var stopwatch = new Stopwatch(); stopwatch.Start(); ExecutionSchedule schedule = await _entitiesRepository.GetFirstOrDefaultAsync <ExecutionSchedule>(st => st.Name == request.Name); if (schedule != null) { throw new InvalidExecutionScheduleException("Execution Schedule with name " + request.Name + " is invalid."); } ExecutionTemplate template = await _entitiesRepository.GetFirstOrDefaultAsync <ExecutionTemplate>(st => st.Name == request.ExecutionTemplateName); if (template == null) { throw new InvalidExecutionScheduleException("Execution Template with name " + request.ExecutionTemplateName + " is invalid."); } foreach (var scheduleString in request.Schedule) { var isValid = SchedulerUtility.IsValidScheduleString(scheduleString); if (!isValid) { throw new InvalidExecutionScheduleException("Schedule " + scheduleString + " is invalid."); } } var executionSchedule = new ExecutionSchedule( Guid.NewGuid(), request.Name, request.ExecutionTemplateName, request.Description, request.CreatedBy, request.Schedule, SchedulerUtility.NextOccurence(request.Schedule) ); var executionScheduleResponse = await _node.Handle(new AddShardWriteOperation() { Data = executionSchedule, WaitForSafeWrite = true, Operation = ConsensusCore.Domain.Enums.ShardOperationOptions.Create }); if (request.RunImmediately) { await _mediator.Send(new ExecuteExecutionTemplateCommand() { CreatedBy = request.CreatedBy, ExecutionScheduleId = executionSchedule.Id, Name = executionSchedule.ExecutionTemplateName }); } stopwatch.Stop(); return(new CommandResult <ExecutionSchedule>() { ObjectRefId = executionSchedule.Id.ToString(), ElapsedMs = stopwatch.ElapsedMilliseconds, Type = CommandResultTypes.Create, Result = executionSchedule }); }
private static async Task ProcessSchedule( ExecutionSchedule schedule, ExecutionSchedule scheduleOld, DirectoryInfo rootSource, DirectoryInfo rootStatus, DirectoryInfo rootLoggs, bool masterTrigger) { var failed = false; var logPath = schedule.GetLogFileInfo(rootLoggs); logPath.TryClear(); try { foreach (var cmd in schedule.commands) { var command = cmd?.Trim(); if (command.IsNullOrEmpty()) { continue; } CommandOutput result; string file; string args; if (command.Contains(" ")) { var parts = command.SplitByFirst(' '); file = parts[0]; args = parts[1]; } else { file = command; args = ""; } if (schedule.timeout > 0) { result = await TaskEx.ToTask(CLIHelper.Command, file, args, rootSource.FullName, schedule.timeout); } else { result = await TaskEx.ToTask(CLIHelper.Command, file, args, rootSource.FullName, 0); } if (!result.Error.IsNullOrEmpty() && schedule.throwOnFailure) { failed = true; throw new Exception($"Failed, schedule '{schedule.id}' command: '{cmd}', error: {result.Error}"); } var output = result.JsonSerialize(Newtonsoft.Json.Formatting.Indented); if (logPath.TryCreate()) { logPath.AppendAllText(output); } Console.WriteLine(output); } } finally { if (!failed || schedule.finalizeOnFailure) { Console.WriteLine($"Updating schedule '{schedule.id}' status file..."); schedule.executions = scheduleOld.executions + 1; schedule.UpdateExecutionSchedule(rootStatus); } else { Console.WriteLine($"Schedule '{schedule.id}' status file was not updated."); } } }