public async Task ProcessJobCompletion_JobIdIsNotSet_ThenNoActionTakenAndErrorLogged() { // Arrange ILogger logger = CreateLogger(); IJobRepository jobRepository = CreateJobRepository(); JobManagementService jobManagementService = CreateJobManagementService(jobRepository, logger: logger); JobNotification jobNotification = new JobNotification { RunningStatus = RunningStatus.Completed }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); // Act await jobManagementService.ProcessJobNotification(message); // Assert logger .Received(1) .Error(Arg.Is("Job Notification message has no JobId")); jobRepository .DidNotReceive() .GetJobById(Arg.Any <string>()); }
private void ProcessJobNotification(JobNotification jobNotification) { JobNotificationTypeEnum notificationType = jobNotification.NotificationType; String jobName = jobNotification.JobName; SpooledJob spooledJob = spoolMonitor.FindSpooledJob(jobName); ManagedPrintJob managedJob = null; if (spooledJob != null) { managedJob = new ManagedPrintJob(jobName); } if (notificationType == JobNotificationTypeEnum.JobCreated) { //if (!managedJob.IsPaused()) // managedJob.Pause(); } if (notificationType == JobNotificationTypeEnum.JobChanged) { // Verifica se terminou o spooling para então processar os dados do job if (!managedJob.IsSpooling() && !spooledJob.Processed) { // spooledJob.CopyFiles(@"C:\tempSpool\" + jobName.Split(new char[] { ',' })[0]); String jobInfo = PrintJobContext.GetJobInfo(spooledJob); WriteToLog(jobInfo); spooledJob.Processed = true; } } }
public async Task ProcessJobCompletion_JobIsNotComplete_ThenNoActionTaken() { // Arrange IJobRepository jobRepository = CreateJobRepository(); JobManagementService jobManagementService = CreateJobManagementService(jobRepository); string jobId = "abc123"; JobNotification jobNotification = new JobNotification { JobId = jobId, RunningStatus = RunningStatus.InProgress }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties["jobId"] = jobId; // Act await jobManagementService.ProcessJobNotification(message); // Assert jobRepository .DidNotReceive() .GetJobById(Arg.Is(jobId)); }
private async Task QueueNotifications(IList <Job> createdJobs, IEnumerable <JobDefinition> jobDefinitionsToSupersede) { List <Task> allTasks = new List <Task>(); SemaphoreSlim throttler = new SemaphoreSlim(initialCount: 30); foreach (Job job in createdJobs) { await throttler.WaitAsync(); allTasks.Add( Task.Run(async() => { try { JobDefinition jobDefinition = jobDefinitionsToSupersede.First(m => m.Id == job.JobDefinitionId); await QueueNewJob(job, jobDefinition); JobNotification jobNotification = CreateJobNotificationFromJob(job); await _notificationService.SendNotification(jobNotification); } finally { throttler.Release(); } })); } await TaskHelper.WhenAllAndThrow(allTasks.ToArray()); }
public async Task <ApiValidationResult> ResumeJob(string tenantId, string jobId) { var jobData = await JobStore.Load(tenantId, jobId); if (jobData == null) { return(ApiValidationResult.Failure(ErrorKeys.InvalidJobId)); } if (jobData.Status.State == JobState.InProgress) { return(ApiValidationResult.Ok()); } var changeableStates = new[] { JobState.Draining, JobState.Paused }; if (changeableStates.Any(s => s == jobData.Status.State)) { var updated = await JobStore.UpdateState(tenantId, jobId, jobData.Status.State, JobState.InProgress); if (updated) { await JobNotification.NotifyJobUpdated(jobId); return(ApiValidationResult.Ok()); } } return(ApiValidationResult.Failure(ErrorKeys.InvalidJobState)); }
public async Task CreateInstructGenerateAggregationsAllocationJob_GivenJobCreated_LogsInformation() { //Arrange JobNotification jobNotification = CreateJobNotification(); string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); Job job = new Job { Id = "job-id-1" }; IJobsApiClient jobsApiClient = CreateJobsApiClient(); jobsApiClient .CreateJob(Arg.Any <JobCreateModel>()) .Returns(job); ILogger logger = CreateLogger(); JobService jobService = CreateJobService(jobsApiClient, logger); //Act await jobService.CreateInstructAllocationJob(message); //Assert logger .Received(1) .Information(Arg.Is($"Created new job of type: '{JobConstants.DefinitionNames.CreateInstructAllocationJob}' with id: '{job.Id}'")); }
public async Task ProcessJobCompletion_JobIdNotFound_ThenNoActionTakenAndErrorLogged() { // Arrange string jobId = "abc123"; ILogger logger = CreateLogger(); IJobRepository jobRepository = CreateJobRepository(); jobRepository .GetJobById(Arg.Is(jobId)) .Returns((Job)null); JobManagementService jobManagementService = CreateJobManagementService(jobRepository, logger: logger); JobNotification jobNotification = new JobNotification { RunningStatus = RunningStatus.Completed }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties["jobId"] = jobId; // Act await jobManagementService.ProcessJobNotification(message); // Assert logger .Received(1) .Error(Arg.Is("Could not find job with id {JobId}"), Arg.Is(jobId)); }
public void CreateInstructGenerateAggregationsAllocationJob_GivenCreatingJobReturnsNull_ThrowsException() { //Arrange JobNotification jobNotification = CreateJobNotification(); string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); IJobsApiClient jobsApiClient = CreateJobsApiClient(); jobsApiClient .CreateJob(Arg.Any <JobCreateModel>()) .Returns((Job)null); ILogger logger = CreateLogger(); JobService jobService = CreateJobService(jobsApiClient, logger); //Act Func <Task> test = () => jobService.CreateInstructAllocationJob(message); //Assert test .Should() .ThrowExactly <Exception>() .Which .Message .Should() .Be($"Failed to create new job of type: '{JobConstants.DefinitionNames.CreateInstructAllocationJob}'"); logger .Received(1) .Error(Arg.Is($"Failed to create new job of type: '{JobConstants.DefinitionNames.CreateInstructAllocationJob}'")); }
public async Task SendNotification_WhenAllPropertiesSet_AddsMessageToTopic() { // Arrange IDictionary <string, string> topicMessageProperties = null; IMessengerService messengerService = CreateMessengerService(); await messengerService.SendToTopic(Arg.Any <string>(), Arg.Any <JobNotification>(), Arg.Do <IDictionary <string, string> >(p => topicMessageProperties = p)); ILogger logger = CreateLogger(); INotificationService notificationService = CreateNotificationService(messengerService, logger); JobNotification jobNotification = CreateJobNotification(); // Act await notificationService.SendNotification(jobNotification); // Assert await messengerService .Received(1) .SendToTopic(Arg.Is(ServiceBusConstants.TopicNames.JobNotifications), Arg.Is(jobNotification), Arg.Any <IDictionary <string, string> >()); topicMessageProperties.Should().NotBeNull(); topicMessageProperties["jobId"].Should().Be(jobNotification.JobId, "JobId"); topicMessageProperties["jobType"].Should().Be(jobNotification.JobType, "JobType"); topicMessageProperties["entityId"].Should().Be(jobNotification.Trigger.EntityId, "EntityId"); topicMessageProperties["specificationId"].Should().Be(jobNotification.SpecificationId, "SpecficationId"); topicMessageProperties["parentJobId"].Should().Be(jobNotification.ParentJobId, "ParentJobId"); logger .Received(1) .Information(Arg.Is("Sent notification for job with id '{JobId}' of type '{JobType}' for entity '{EntityType}' with id '{EntityId} and status '{CompletionStatus}"), Arg.Is(jobNotification.JobId), Arg.Is(jobNotification.JobType), Arg.Is(jobNotification.Trigger.EntityType), Arg.Is(jobNotification.Trigger.EntityId), Arg.Is(jobNotification.CompletionStatus)); }
public void NotifyObject(object obj) { if (obj is JobNotification) { // Processa a notificação de job em tempo real (o processamento não pode ser adiado) JobNotification jobNotification = (JobNotification)obj; ProcessJobNotification(jobNotification); return; } if (notifications.Count >= 10) { // Recolhe informações de trace acumuladas em notifications e limpa a lista String notificationItems = ""; foreach (Object item in notifications) { if (item is String) { notificationItems += item + Environment.NewLine; } } notifications.Clear(); // Armazena informações de trace como evento para visualização no Event Viewer if (EventLog.SourceExists("Print Inspector")) { EventLog.WriteEntry("Print Inspector", notificationItems); } } // Armazena outros tipos de notificação para processamento posterior notifications.Add(obj); }
///<summary>Inserts one JobNotification into the database. Provides option to use the existing priKey. Doesn't use the cache.</summary> public static long InsertNoCache(JobNotification jobNotification, bool useExistingPK) { bool isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys); string command = "INSERT INTO jobnotification ("; if (!useExistingPK && isRandomKeys) { jobNotification.JobNotificationNum = ReplicationServers.GetKeyNoCache("jobnotification", "JobNotificationNum"); } if (isRandomKeys || useExistingPK) { command += "JobNotificationNum,"; } command += "JobNum,UserNum,Changes) VALUES("; if (isRandomKeys || useExistingPK) { command += POut.Long(jobNotification.JobNotificationNum) + ","; } command += POut.Long(jobNotification.JobNum) + "," + POut.Long(jobNotification.UserNum) + "," + POut.Int((int)jobNotification.Changes) + ")"; if (useExistingPK || isRandomKeys) { Db.NonQ(command); } else { jobNotification.JobNotificationNum = Db.NonQ(command, true, "JobNotificationNum", "jobNotification"); } return(jobNotification.JobNotificationNum); }
///<summary>Inserts one JobNotification into the database. Provides option to use the existing priKey.</summary> public static long Insert(JobNotification jobNotification, bool useExistingPK) { if (!useExistingPK && PrefC.RandomKeys) { jobNotification.JobNotificationNum = ReplicationServers.GetKey("jobnotification", "JobNotificationNum"); } string command = "INSERT INTO jobnotification ("; if (useExistingPK || PrefC.RandomKeys) { command += "JobNotificationNum,"; } command += "JobNum,UserNum,Changes) VALUES("; if (useExistingPK || PrefC.RandomKeys) { command += POut.Long(jobNotification.JobNotificationNum) + ","; } command += POut.Long(jobNotification.JobNum) + "," + POut.Long(jobNotification.UserNum) + "," + POut.Int((int)jobNotification.Changes) + ")"; if (useExistingPK || PrefC.RandomKeys) { Db.NonQ(command); } else { jobNotification.JobNotificationNum = Db.NonQ(command, true, "JobNotificationNum", "jobNotification"); } return(jobNotification.JobNotificationNum); }
public async Task CreateInstructAllocationJob(Message message) { Guard.ArgumentNotNull(message, nameof(message)); JobNotification jobNotification = message.GetPayloadAsInstanceOf <JobNotification>(); if (jobNotification.CompletionStatus == CompletionStatus.Succeeded && jobNotification.JobType == JobConstants.DefinitionNames.CreateInstructGenerateAggregationsAllocationJob) { JobCreateModel jobCreateModel = new JobCreateModel { JobDefinitionId = JobConstants.DefinitionNames.CreateInstructAllocationJob, InvokerUserDisplayName = jobNotification.InvokerUserDisplayName, InvokerUserId = jobNotification.InvokerUserId, CorrelationId = message.GetCorrelationId(), SpecificationId = jobNotification.SpecificationId, Properties = new Dictionary <string, string> { { "specification-id", jobNotification.SpecificationId } }, Trigger = jobNotification.Trigger }; Job newJob = await _jobsApiClient.CreateJob(jobCreateModel); if (newJob == null) { _logger.Error($"Failed to create new job of type: '{JobConstants.DefinitionNames.CreateInstructAllocationJob}'"); throw new Exception($"Failed to create new job of type: '{JobConstants.DefinitionNames.CreateInstructAllocationJob}'"); } _logger.Information($"Created new job of type: '{JobConstants.DefinitionNames.CreateInstructAllocationJob}' with id: '{newJob.Id}'"); } }
public async Task ProcessJobCompletion_JobHasParentWithMultipleCompletedChildrenWithAllSucceeded_ThenParentCompletedStatusIsSucceeded() { // Arrange string parentJobId = "parent123"; string jobId = "child123"; Job job = new Job { Id = jobId, ParentJobId = parentJobId, CompletionStatus = CompletionStatus.Succeeded, RunningStatus = RunningStatus.Completed }; Job job2 = new Job { Id = "child456", ParentJobId = parentJobId, RunningStatus = RunningStatus.Completed, CompletionStatus = CompletionStatus.Succeeded }; Job job3 = new Job { Id = "child789", ParentJobId = parentJobId, RunningStatus = RunningStatus.Completed, CompletionStatus = CompletionStatus.Succeeded }; Job parentJob = new Job { Id = parentJobId, RunningStatus = RunningStatus.InProgress }; ILogger logger = CreateLogger(); IJobRepository jobRepository = CreateJobRepository(); jobRepository .GetJobById(Arg.Is(jobId)) .Returns(job); jobRepository .GetJobById(Arg.Is(parentJobId)) .Returns(parentJob); jobRepository .GetChildJobsForParent(Arg.Is(parentJobId)) .Returns(new List <Job> { job, job2 }); JobManagementService jobManagementService = CreateJobManagementService(jobRepository, logger: logger); JobNotification jobNotification = new JobNotification { JobId = jobId, RunningStatus = RunningStatus.Completed }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties["jobId"] = jobId; // Act await jobManagementService.ProcessJobNotification(message); // Assert await jobRepository .Received(1) .UpdateJob(Arg.Is <Job>(j => j.Id == parentJobId && j.CompletionStatus == CompletionStatus.Succeeded)); }
public async Task ProcessJobCompletion_JobHasParentTwoChildrenOnlyBothCompleted_ThenParentCompleted() { // Arrange string parentJobId = "parent123"; string jobId = "child123"; Job job = new Job { Id = jobId, ParentJobId = parentJobId, CompletionStatus = CompletionStatus.Succeeded, RunningStatus = RunningStatus.Completed }; Job job2 = new Job { Id = "child456", ParentJobId = parentJobId, CompletionStatus = CompletionStatus.Succeeded, RunningStatus = RunningStatus.Completed }; Job parentJob = new Job { Id = parentJobId, RunningStatus = RunningStatus.InProgress }; ILogger logger = CreateLogger(); IJobRepository jobRepository = CreateJobRepository(); jobRepository .GetJobById(Arg.Is(jobId)) .Returns(job); jobRepository .GetJobById(Arg.Is(parentJobId)) .Returns(parentJob); jobRepository .GetChildJobsForParent(Arg.Is(parentJobId)) .Returns(new List <Job> { job, job2 }); JobManagementService jobManagementService = CreateJobManagementService(jobRepository, logger: logger); JobNotification jobNotification = new JobNotification { JobId = jobId, RunningStatus = RunningStatus.Completed }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties["jobId"] = jobId; // Act await jobManagementService.ProcessJobNotification(message); // Assert await jobRepository .Received(1) .UpdateJob(Arg.Is <Job>(j => j.Id == parentJobId && j.RunningStatus == RunningStatus.Completed && j.Completed.HasValue && j.Outcome == "All child jobs completed")); logger .Received(1) .Information(Arg.Is("Parent Job {ParentJobId} of Completed Job {JobId} has been completed because all child jobs are now complete"), Arg.Is(job.ParentJobId), Arg.Is(jobId)); }
public async Task ProcessJobCompletion_JobHasParentThatIsCompleted_ThenNotificationSent() { // Arrange string parentJobId = "parent123"; string jobId = "child123"; Job job = new Job { Id = jobId, ParentJobId = parentJobId, CompletionStatus = CompletionStatus.Succeeded, RunningStatus = RunningStatus.Completed }; Job parentJob = new Job { Id = parentJobId, RunningStatus = RunningStatus.InProgress }; ILogger logger = CreateLogger(); IJobRepository jobRepository = CreateJobRepository(); jobRepository .GetJobById(Arg.Is(jobId)) .Returns(job); jobRepository .GetJobById(Arg.Is(parentJobId)) .Returns(parentJob); jobRepository .GetChildJobsForParent(Arg.Is(parentJobId)) .Returns(new List <Job> { job }); INotificationService notificationService = CreateNotificationsService(); JobManagementService jobManagementService = CreateJobManagementService(jobRepository, logger: logger, notificationService: notificationService); JobNotification jobNotification = new JobNotification { JobId = jobId, RunningStatus = RunningStatus.Completed }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties["jobId"] = jobId; // Act await jobManagementService.ProcessJobNotification(message); // Assert await notificationService .Received(1) .SendNotification(Arg.Is <JobNotification>(n => n.JobId == parentJobId && n.RunningStatus == RunningStatus.Completed)); logger .Received(1) .Information(Arg.Is("Parent Job {ParentJobId} of Completed Job {JobId} has been completed because all child jobs are now complete"), Arg.Is(job.ParentJobId), Arg.Is(jobId)); }
///<summary>Updates one JobNotification in the database.</summary> public static void Update(JobNotification jobNotification) { string command = "UPDATE jobnotification SET " + "JobNum = " + POut.Long(jobNotification.JobNum) + ", " + "UserNum = " + POut.Long(jobNotification.UserNum) + ", " + "Changes = " + POut.Int((int)jobNotification.Changes) + " " + "WHERE JobNotificationNum = " + POut.Long(jobNotification.JobNotificationNum); Db.NonQ(command); }
public async Task OnNotificationEvent_WhenChildJobWithSpecificationIdIsCreated_ThenSignalRMessagesAdded() { // Arrange NotificationService service = CreateService(); JobNotification jobNotification = new JobNotification() { CompletionStatus = null, JobId = JobId, JobType = "test", SpecificationId = SpecificationId, ParentJobId = "parentJobId1", }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); IAsyncCollector <SignalRMessage> generatedMessages = CreateSignalRMessageCollector(); // Act await service.OnNotificationEvent(message, generatedMessages); // Assert await generatedMessages .Received(2) .AddAsync(Arg.Any <SignalRMessage>()); await generatedMessages .Received(1) .AddAsync( Arg.Is <SignalRMessage>( c => c.Target == JobConstants.NotificationsTargetFunction && c.Arguments.Length == 1 && c.Arguments.First() != null && c.GroupName == JobConstants.NotificationChannels.All)); await generatedMessages .Received(1) .AddAsync( Arg.Is <SignalRMessage>( c => c.Target == JobConstants.NotificationsTargetFunction && c.Arguments.Length == 1 && c.Arguments.First() != null && c.GroupName == $"{JobConstants.NotificationChannels.SpecificationPrefix}{SpecificationId.Replace("-", "")}")); await generatedMessages .Received(0) .AddAsync( Arg.Is <SignalRMessage>( c => c.Target == JobConstants.NotificationsTargetFunction && c.Arguments.Length == 1 && c.Arguments.First() != null && c.GroupName == JobConstants.NotificationChannels.ParentJobs)); }
public async Task <ApiValidationResult> StopJob(string tenantId, string jobId) { var jobData = await JobStore.Load(tenantId, jobId); if (jobData == null) { return(ApiValidationResult.Failure(ErrorKeys.InvalidJobId)); } if (jobData.Status.State == JobState.Stopped) { return(ApiValidationResult.Ok()); } if (jobData.Configuration.IsIndefinite) { return(ApiValidationResult.Failure(ErrorKeys.InvalidJobAction)); } if (jobData.Configuration.PreprocessorJobIds.SafeAny()) { foreach (var preprocessorJobId in jobData.Configuration.PreprocessorJobIds) { var preprocessorJobStatus = await JobStore.LoadStatus(tenantId, preprocessorJobId); if (preprocessorJobStatus.State < JobState.Completed) { return(ApiValidationResult.Failure(ErrorKeys.JobActionHasPreprocessorDependency, new[] { preprocessorJobId })); } } } var changeableStates = new[] { JobState.InProgress, JobState.Draining, JobState.Paused }; if (changeableStates.Any(s => s == jobData.Status.State)) { var updated = await JobStore.UpdateState(tenantId, jobId, jobData.Status.State, JobState.Stopped); if (updated) { await JobNotification.NotifyJobUpdated(jobId); var jobStepSource = GetJobQueue(jobData); if (jobStepSource != null) { await jobStepSource.Purge(); } return(ApiValidationResult.Ok()); } } return(ApiValidationResult.Failure(ErrorKeys.InvalidJobState)); }
public ActionResult JobNotification(JobNotification jobNotification) { var connectionID = ProcessHub.GetConnectionIdByJobId(jobNotification.JobID); if (connectionID != null) { var hubContext = GlobalHost.ConnectionManager.GetHubContext <ProcessHub>(); hubContext.Clients.Clients(new[] { connectionID }).jobCompleted( jobNotification.JobID, jobNotification.JobStatus, JsonConvert.SerializeObject(jobNotification.User)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
///<summary>Returns true if Update(JobNotification,JobNotification) would make changes to the database. ///Does not make any changes to the database and can be called before remoting role is checked.</summary> public static bool UpdateComparison(JobNotification jobNotification, JobNotification oldJobNotification) { if (jobNotification.JobNum != oldJobNotification.JobNum) { return(true); } if (jobNotification.UserNum != oldJobNotification.UserNum) { return(true); } if (jobNotification.Changes != oldJobNotification.Changes) { return(true); } return(false); }
///<summary>Converts a DataTable to a list of objects.</summary> public static List <JobNotification> TableToList(DataTable table) { List <JobNotification> retVal = new List <JobNotification>(); JobNotification jobNotification; foreach (DataRow row in table.Rows) { jobNotification = new JobNotification(); jobNotification.JobNotificationNum = PIn.Long(row["JobNotificationNum"].ToString()); jobNotification.JobNum = PIn.Long(row["JobNum"].ToString()); jobNotification.UserNum = PIn.Long(row["UserNum"].ToString()); jobNotification.Changes = (OpenDentBusiness.JobNotificationChanges)PIn.Int(row["Changes"].ToString()); retVal.Add(jobNotification); } return(retVal); }
public void NotifyObject(Object obj) { if (obj is JobNotification) { JobNotification jobNotification = (JobNotification)obj; ProcessJobNotification(jobNotification); return; } if (obj is String) { String traceInfo = (String)obj; traceInfoBox.Invoke(new PerformTextOutputDelegate(LogTraceInfo), traceInfo); return; } }
/// <summary>Handle notifications</summary> /// <param name="notification">the job event notification to print</param> /// <param name="type">an arbotrary object passed when this listener is registered, may be null</param> public override void HandleNotification(Notification notification, object handback) { JobNotification notif = notification as JobNotification; if (notif != null) { JobEventType type = notif.getEventType(); // skip job updated notifications if (type != JobEventType.JOB_UPDATED) { JobInformation jobInfo = notif.getJobInformation(); int n = jobInfo.getTaskCount(); Console.WriteLine("[MyJobNotificationListener] job '" + jobInfo.getJobName() + "' received " + type + " notification" + (n > 0 ? " for " + n + " tasks" : "") + ", handback = " + (handback != null ? "" + handback : "null")); } } }
public async Task OnNotificationEvent(Message message, IAsyncCollector <SignalRMessage> signalRMessages) { Guard.ArgumentNotNull(message, nameof(message)); Guard.ArgumentNotNull(signalRMessages, nameof(signalRMessages)); JobNotification jobNotification = message.GetPayloadAsInstanceOf <JobNotification>(); if (jobNotification == null) { throw new InvalidOperationException("Job notificiation was null"); } // Send to all notifications channel await signalRMessages.AddAsync( new SignalRMessage { Target = JobConstants.NotificationsTargetFunction, GroupName = JobConstants.NotificationChannels.All, Arguments = new[] { jobNotification } }); if (!string.IsNullOrWhiteSpace(jobNotification.SpecificationId)) { // Send to individual specifications group await signalRMessages.AddAsync( new SignalRMessage { Target = JobConstants.NotificationsTargetFunction, GroupName = $"{JobConstants.NotificationChannels.SpecificationPrefix}{jobNotification.SpecificationId.Replace("-", "")}", Arguments = new[] { jobNotification } }); } if (string.IsNullOrWhiteSpace(jobNotification.ParentJobId)) { // Send to parent jobs only group await signalRMessages.AddAsync( new SignalRMessage { Target = JobConstants.NotificationsTargetFunction, GroupName = JobConstants.NotificationChannels.ParentJobs, Arguments = new[] { jobNotification } }); } }
public async Task StartJobIfNotStarted(string tenantId, string jobId) { var jobData = await JobStore.Load(tenantId, jobId); if (jobData == null) { throw new InvalidOperationException($"JobId {jobId} does not exist."); } if (jobData.Status.State != JobState.Initializing) { return; } await JobStore.UpdateState(tenantId, jobId, JobState.Initializing, JobState.InProgress); await JobNotification.NotifyJobUpdated(jobId); }
private async Task TimeoutJob(Job runningJob) { runningJob.Completed = DateTimeOffset.UtcNow; runningJob.CompletionStatus = CompletionStatus.TimedOut; runningJob.RunningStatus = RunningStatus.Completed; HttpStatusCode statusCode = await _jobsRepositoryPolicy.ExecuteAsync(() => _jobRepository.UpdateJob(runningJob)); if (statusCode.IsSuccess()) { JobNotification jobNotification = CreateJobNotificationFromJob(runningJob); await _notificationService.SendNotification(jobNotification); } else { _logger.Error($"Failed to update timeout job, Id: '{runningJob.Id}' with status code {(int)statusCode}"); } }
public void BuildRequestModel_GivenJobNotificationWithDefinitionNotConfiguredForScaling_ContainsNoRepositoryTypes() { //Arrange JobNotification jobNotification = new JobNotification { JobType = "any-job-def-id" }; CosmosDbScalingRequestModelBuilder builder = new CosmosDbScalingRequestModelBuilder(); //Act CosmosDbScalingRequestModel requestModel = builder.BuildRequestModel(jobNotification); //Assert requestModel .RepositoryTypes .Should() .BeNull(); }
public async Task ProcessJobCompletion_JobHasNoParent_ThenNoActionTakenAndMessageLogged() { // Arrange string jobId = "abc123"; Job job = new Job { Id = jobId, ParentJobId = null }; ILogger logger = CreateLogger(); IJobRepository jobRepository = CreateJobRepository(); jobRepository .GetJobById(Arg.Is(jobId)) .Returns(job); JobManagementService jobManagementService = CreateJobManagementService(jobRepository, logger: logger); JobNotification jobNotification = new JobNotification { JobId = jobId, RunningStatus = RunningStatus.Completed }; string json = JsonConvert.SerializeObject(jobNotification); Message message = new Message(Encoding.UTF8.GetBytes(json)); message.UserProperties["jobId"] = jobId; // Act await jobManagementService.ProcessJobNotification(message); // Assert logger .Received(1) .Information(Arg.Is("Completed Job {JobId} has no parent"), Arg.Is(jobId)); jobRepository .DidNotReceive() .GetChildJobsForParent(Arg.Any <string>()); }
public CosmosDbScalingRequestModel BuildRequestModel(JobNotification jobNotification) { CosmosDbScalingRequestModel cosmosDbScalingRequestModel = new CosmosDbScalingRequestModel { JobDefinitionId = jobNotification.JobType }; switch (jobNotification.JobType) { case JobConstants.DefinitionNames.CreateInstructAllocationJob: cosmosDbScalingRequestModel.RepositoryTypes = new[] { CosmosCollectionType.CalculationProviderResults, CosmosCollectionType.ProviderSourceDatasets }; break; case JobConstants.DefinitionNames.CreateInstructGenerateAggregationsAllocationJob: cosmosDbScalingRequestModel.RepositoryTypes = new[] { CosmosCollectionType.ProviderSourceDatasets }; break; case JobConstants.DefinitionNames.MapDatasetJob: cosmosDbScalingRequestModel.RepositoryTypes = new[] { CosmosCollectionType.ProviderSourceDatasets }; break; case JobConstants.DefinitionNames.PublishProviderResultsJob: cosmosDbScalingRequestModel.RepositoryTypes = new[] { CosmosCollectionType.CalculationProviderResults, CosmosCollectionType.PublishedProviderResults }; break; } return(cosmosDbScalingRequestModel); }
/// <summary> /// Sends a new mining job to the miner. /// </summary> public void SendJob(JobNotification job) { throw new NotSupportedException(); }
/// <summary> /// Sends a mining-job to miner. /// </summary> public void SendJob(JobNotification jobNotification) { var notification = new JsonRequest { Id = null, Method = "mining.notify", Params = jobNotification }; //Params = new JobNotification() //{ // Id = "2b50", // PreviousBlockHash = "8f0472e229d7f803642efac67a3daeabbe9bda7ac7872ea19e3978cf3e65261d", // CoinbaseInitial = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2703c33a07062f503253482f047028a25208", // CoinbaseFinal = "0d2f7374726174756d506f6f6c2f0000000001fe7aaa2a010000001976a9145b771921a9b47ee8104da7e4710b5f633d95fa7388ac00000000", // MerkleBranches = new List<object> // { // "795ec58b7ebf9522ad15b76207c8f40e569cfd478c2e2c30bfa06c8a6d24609d", // "e76544a1b9d7550280c49bf965d5882c65f8cd4b9711202cc9bd311f76b438ac", // "01acd5a2a3142d735e4847a5b512aef35f22f67eb2d7be1f4dcdfca3c4031a43", // "4c561433d42406ca777fb1aa730a6b96317ca68c2341b5f0f52afc2ae1b6235d" // }, // BlockVersion = "00000002", // NetworkDifficulty = "1b1d88f6", // nTime = "52a22871", // CleanJobs = false //} var json = JsonConvert.SerializeObject(notification) + "\n"; var data = Encoding.UTF8.GetBytes(json); this.Connection.Send(data); Log.Verbose("RPC-client send:\n{0}", data.ToEncodedString()); }