public DayArchiverProcessManager( IColdStorage coldStorage, IArchivableDaysRepository archivableDaysRepository, ICommandStore commandStore, TimeSpan threshold, IEventStore eventStore, Func <Guid> idGenerator ) { _commandStore = commandStore; _idGenerator = idGenerator; When <DayScheduled>(async(e, m) => { await archivableDaysRepository.Add(new ArchivableDay(e.DayId, e.Date)); }); When <CalendarDayStarted>(async(e, m) => { var archivableDays = await archivableDaysRepository.FindAll(e.Date.Add(threshold)); foreach (var day in archivableDays) { await SendCommand(day.Id, m.CorrelationId, m.CausationId); } }); When <DayScheduleArchived>(async(e, m) => { var streamName = StreamName.For <Day>(e.DayId); var events = await eventStore.LoadEvents(streamName); coldStorage.SaveAll(events); var lastVersion = await eventStore.GetLastVersion(streamName); if (lastVersion.HasValue) { await eventStore.TruncateStream(streamName, lastVersion.Value); } }); }
private StartupShutdownBase CreateDistributedServer(LocalServerConfiguration localServerConfiguration, DistributedContentSettings distributedSettings) { var cacheConfig = _arguments.Configuration; var factory = CreateDistributedContentStoreFactory(); // NOTE: This relies on the assumption that when creating a distributed server, // there is only one call to create a cache so we simply create the cache here and ignore path // below in factory delegates since the logic for creating path based caches is included in the // call to CreateTopLevelStore var topLevelAndPrimaryStore = factory.CreateTopLevelStore(); IColdStorage coldStorage = topLevelAndPrimaryStore.primaryDistributedStore.ColdStorage; if (distributedSettings.EnableMetadataStore || distributedSettings.EnableDistributedCache) { _logger.Always("Creating distributed server with content and metadata store"); Func <AbsolutePath, ICache> cacheFactory = path => { if (distributedSettings.EnableDistributedCache) { var distributedCache = new DistributedOneLevelCache(topLevelAndPrimaryStore.topLevelStore, factory.Services.ContentLocationStoreServices.Instance, Guid.NewGuid(), passContentToMemoization: true); ICache cacheToReturn = distributedCache; #if MICROSOFT_INTERNAL if (distributedSettings.EnablePublishingCache) { cacheToReturn = new PublishingCache <DistributedOneLevelCache>( local: distributedCache, remote: new BuildCachePublishingStore(contentSource: distributedCache, _fileSystem, distributedSettings.PublishingConcurrencyLimit), Guid.NewGuid()); } #endif return(cacheToReturn); } else { return(new OneLevelCache( contentStoreFunc: () => topLevelAndPrimaryStore.topLevelStore, memoizationStoreFunc: () => CreateServerSideLocalMemoizationStore(path, factory), Guid.NewGuid(), passContentToMemoization: true)); } }; // NOTE(jubayard): When generating the service configuration, we create a single named cache root in // the distributed case. This means that the factories will be called exactly once, so we will have // a single MultiplexedContentStore and MemoizationStore. The latter will be located in the last cache // root listed as per production configuration, which currently (8/27/2019) points to the SSD drives. return(new LocalCacheServer( _fileSystem, _logger, _arguments.Configuration.LocalCasSettings.ServiceSettings.ScenarioName, cacheFactory, localServerConfiguration, capabilities: distributedSettings.EnablePublishingCache?Capabilities.All: Capabilities.AllNonPublishing, factory.GetAdditionalEndpoints(), coldStorage)); } else { _logger.Always("Creating distributed server with content store only"); return(new LocalContentServer( _fileSystem, _logger, cacheConfig.LocalCasSettings.ServiceSettings.ScenarioName, path => topLevelAndPrimaryStore.topLevelStore, localServerConfiguration, factory.GetAdditionalEndpoints(), coldStorage)); } }