Exemplo n.º 1
0
        public async Task <JobConfigUpdateResult> StartJobAsync(
            JobConfigUpdateCommand jobConfigUpdateCommand)
        {
            var storage = _componentRegistry.GetRegisteredStorage();

            if (storage == null)
            {
                _logger.TrackError(
                    "StartJob",
                    "No storage component was registered");
                return(JobConfigUpdateResult.Failed("No storage is present. Job can't be done"));
            }


            var job = new Job
            {
                FinishedAt = null,
                JobName    = jobConfigUpdateCommand.JobName,
                JobStatus  = JobStatus.Running,
                JobId      = jobConfigUpdateCommand.JobId,
                Owner      = "admin",
                TopicQuery = jobConfigUpdateCommand.TopicQuery,
                StartedAt  = DateTime.Now,
            };

            var analysers = await PushAnalyserJobConfig(
                storage.AnalysedDataInputChannel,
                jobConfigUpdateCommand);


            var analysersInputs = analysers.Select(r => r.InputChannelName).ToArray();

            await PushNetworkDataAcquisitionJobConfig(
                storage.AcquiredDataInputChannel,
                analysersInputs,
                jobConfigUpdateCommand);

            await _jobStorage.InsertNewJobAsync(job);

            return(JobConfigUpdateResult.Successfull(
                       jobConfigUpdateCommand.JobId,
                       JobStatus.Running));
        }
Exemplo n.º 2
0
        public async Task <JobConfigUpdateResult> StopJob(Guid jobId)
        {
            try
            {
                var job = await _jobStorage.GetJobAsync(jobId);

                var notification = new DataAcquisitionConfigUpdateNotification
                {
                    JobId   = jobId,
                    Command = JobCommand.Stop
                };

                var components = await _componentRegistry.GetAllComponentsAsync();

                foreach (var item in components)
                {
                    await NotifyComponent(jobId, item.ComponentId, notification);
                }

                job.JobStatus = JobStatus.Stopped;

                await _jobStorage.UpdateJobAsync(job);

                return(JobConfigUpdateResult.Successfull(jobId, job.JobStatus));
            }
            catch (Exception e)
            {
                var message = $"Could not stop the job {jobId}, due to error {e.Message}";

                _logger.TrackError(
                    "StopJob",
                    message,
                    new
                {
                    jobId,
                    exception = e
                });

                throw new InvalidOperationException(message);
            }
        }