コード例 #1
0
        public CompatibilityVersionHandlerTests()
        {
            _schemaMigrationDataStore = Substitute.For <ISchemaDataStore>();
            var collection = new ServiceCollection();

            collection.Add(sp => new CompatibilityVersionHandler(_schemaMigrationDataStore)).Singleton().AsSelf().AsImplementedInterfaces();

            ServiceProvider provider = collection.BuildServiceProvider();

            _mediator          = new Mediator(type => provider.GetService(type));
            _cancellationToken = new CancellationTokenSource().Token;
        }
コード例 #2
0
        public async Task ExecuteAsync(SchemaInformation schemaInformation, string instanceName, CancellationToken cancellationToken)
        {
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));

            _logger.LogInformation($"Polling started at {Clock.UtcNow}");

            while (!cancellationToken.IsCancellationRequested)
            {
                try
                {
                    using IServiceScope scope = _serviceProvider.CreateScope();
                    ISchemaDataStore schemaDataStore = scope.ServiceProvider.GetRequiredService <ISchemaDataStore>();

                    int?previous = schemaInformation.Current;
                    schemaInformation.Current = await schemaDataStore.UpsertInstanceSchemaInformationAsync(instanceName, schemaInformation, cancellationToken).ConfigureAwait(false);

                    // If there was a change in the schema version and this isn't the base schema
                    if (schemaInformation.Current != previous && schemaInformation.Current > 0)
                    {
                        var isFullSchemaSnapshot = previous == 0;

                        await _mediator.NotifySchemaUpgradedAsync((int)schemaInformation.Current, isFullSchemaSnapshot).ConfigureAwait(false);
                    }

                    await schemaDataStore.DeleteExpiredInstanceSchemaAsync(cancellationToken).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    // The job failed.
                    _logger.LogError(ex, "Unhandled exception in the worker.");
                }

                try
                {
                    await Task.Delay(TimeSpan.FromSeconds(_sqlServerDataStoreConfiguration.SchemaOptions.JobPollingFrequencyInSeconds), cancellationToken).ConfigureAwait(false);
                }
                catch (OperationCanceledException) when(cancellationToken.IsCancellationRequested)
                {
                    // Cancel requested.
                    break;
                }
            }
        }
コード例 #3
0
 public CurrentVersionHandler(ISchemaDataStore schemaMigrationDataStore)
 {
     EnsureArg.IsNotNull(schemaMigrationDataStore, nameof(schemaMigrationDataStore));
     _schemaDataStore = schemaMigrationDataStore;
 }
 public CompatibilityVersionHandler(ISchemaDataStore schemaDataStore)
 {
     EnsureArg.IsNotNull(schemaDataStore, nameof(schemaDataStore));
     _schemaDataStore = schemaDataStore;
 }