/// <summary> /// Loads logging, sets up fatal behaviour, subscribes rabbit etc. /// </summary> /// <param name="globals">Settings for the microservice (location of rabbit, queue names etc)</param> /// <param name="rabbitMqAdapter"></param> /// <param name="threaded"></param> protected MicroserviceHost( [NotNull] GlobalOptions globals, IRabbitMqAdapter rabbitMqAdapter = null, bool threaded = false) { if (globals == null || globals.FileSystemOptions == null || globals.RabbitOptions == null || globals.LoggingOptions == null) { throw new ArgumentException("All or part of the global options are null"); } HostProcessName = SmiCliInit.HostProcessName; Logger = LogManager.GetLogger(GetType().Name); Logger.Info("Host logger created"); HostProcessID = Process.GetCurrentProcess().Id; Logger.Info($"Starting {HostProcessName} (Host={Environment.MachineName} PID={HostProcessID} User={Environment.UserName})"); // log centrally Globals = globals; Logger.Debug("Loaded global options:\n" + globals); // should also be centralized for non-host uses // Ensure this is false in case the default changes DicomTypeTranslater.SerializeBinaryData = false; _fatalLoggingProducerOptions = new ProducerOptions { ExchangeName = Globals.RabbitOptions.FatalLoggingExchange }; //TODO This won't pass for testing with mocked filesystems //if(!Directory.Exists(options.FileSystemRoot)) // throw new ArgumentException("Could not locate the FileSystemRoot \"" + options.FileSystemRoot + "\""); OnFatal += (sender, args) => Fatal(args.Message, args.Exception); RabbitMqAdapter = rabbitMqAdapter; if (RabbitMqAdapter == null) { ConnectionFactory connectionFactory = globals.RabbitOptions.CreateConnectionFactory(); RabbitMqAdapter = new RabbitMqAdapter(connectionFactory, HostProcessName + HostProcessID, OnFatal, threaded); _controlMessageConsumer = new ControlMessageConsumer(connectionFactory, HostProcessName, HostProcessID, globals.RabbitOptions.RabbitMqControlExchangeName, this.Stop); } ObjectFactory = new MicroserviceObjectFactory(); ObjectFactory.FatalHandler = (s, e) => Fatal(e.Message, e.Exception); }
public TriggerUpdatesHost(GlobalOptions options, ITriggerUpdatesSource source, IRabbitMqAdapter rabbitMqAdapter = null) : base(options, rabbitMqAdapter) { this._source = source; _producer = RabbitMqAdapter.SetupProducer(options.TriggerUpdatesOptions, isBatch: false); }
/// <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); }
public UpdateValuesHost([NotNull] GlobalOptions globals, IRabbitMqAdapter rabbitMqAdapter = null, bool threaded = false) : base(globals, rabbitMqAdapter, threaded) { FansiImplementations.Load(); }