public void GetNotifier_ConstructsLoggingNotifier() { IJobCompleteNotifier notifier = JobCompleteNotifierFactory.GetNotifier(notifierTypeStr: "LoggingNotifier"); Assert.True(notifier is LoggingNotifier); }
public void GetNotifier_ThrowsException_OnInvalidNotifierTypeStr() { Assert.Throws <ArgumentException>(() => JobCompleteNotifierFactory.GetNotifier(notifierTypeStr: "foo")); }
/// <summary> /// Default constructor for CohortPackagerHost /// </summary> /// <param name="globals"></param> /// <param name="jobStore"></param> /// <param name="fileSystem"></param> /// <param name="reporter"> /// Pass to override the default IJobReporter that will be created from /// Globals.CohortPackagerOptions.ReportFormat. That value should not be set if a reporter is passed. /// </param> /// <param name="notifier"></param> /// <param name="rabbitMqAdapter"></param> /// <param name="dateTimeProvider"></param> public CohortPackagerHost( [NotNull] GlobalOptions globals, [CanBeNull] ExtractJobStore jobStore = null, [CanBeNull] IFileSystem fileSystem = null, [CanBeNull] IJobReporter reporter = null, [CanBeNull] IJobCompleteNotifier notifier = null, [CanBeNull] IRabbitMqAdapter rabbitMqAdapter = null, [CanBeNull] DateTimeProvider dateTimeProvider = null ) : base(globals, rabbitMqAdapter) { if (jobStore == null) { MongoDbOptions mongoDbOptions = Globals.MongoDatabases.ExtractionStoreOptions; jobStore = new MongoExtractJobStore( MongoClientHelpers.GetMongoClient(mongoDbOptions, HostProcessName), mongoDbOptions.DatabaseName, dateTimeProvider ); } else if (dateTimeProvider != null) { throw new ArgumentException("jobStore and dateTimeProvider are mutually exclusive arguments"); } // If not passed a reporter or notifier, try and construct one from the given options string reportFormatStr = Globals.CohortPackagerOptions.ReportFormat; if (reporter == null) { reporter = JobReporterFactory.GetReporter( Globals.CohortPackagerOptions.ReporterType, jobStore, fileSystem ?? new FileSystem(), Globals.FileSystemOptions.ExtractRoot, reportFormatStr, Globals.CohortPackagerOptions.ReportNewLine ); } else { if (!string.IsNullOrWhiteSpace(reportFormatStr)) { throw new ArgumentException($"Passed an IJobReporter, but this conflicts with the ReportFormat of '{reportFormatStr}' in the given options"); } if (fileSystem != null) { throw new ArgumentException("Passed a fileSystem, but this will be unused as also passed an existing IJobReporter"); } } notifier ??= JobCompleteNotifierFactory.GetNotifier( Globals.CohortPackagerOptions.NotifierType ); _jobWatcher = new ExtractJobWatcher( globals.CohortPackagerOptions, jobStore, ExceptionCallback, notifier, reporter ); AddControlHandler(new CohortPackagerControlMessageHandler(_jobWatcher)); // Setup our consumers _requestInfoMessageConsumer = new ExtractionRequestInfoMessageConsumer(jobStore); _fileCollectionMessageConsumer = new ExtractFileCollectionMessageConsumer(jobStore); _anonFailedMessageConsumer = new AnonFailedMessageConsumer(jobStore); _anonVerificationMessageConsumer = new AnonVerificationMessageConsumer(jobStore); }