private static BackgroundTask NewTask(BackgroundTaskOptions options, IBackgroundTaskSerializer serializer,
                                              Type type, object userData)
        {
            var handlerInfo = new HandlerInfo(type.Namespace, type.Name);
            var task        = new BackgroundTask
            {
                Handler = serializer?.Serialize(handlerInfo),
                Data    = userData == null ? null : JsonSerializer.Serialize(userData)
            };

            options.ProvisionTask(task);
            return(task);
        }
예제 #2
0
        private static void MigrateToLatest(BackgroundTaskOptions taskOptions, DocumentDbOptions dbOptions)
        {
            var runner = new DocumentDbMigrationRunner(dbOptions);

            if (taskOptions.Store.CreateIfNotExists)
            {
                runner.CreateDatabaseIfNotExistsAsync().GetAwaiter().GetResult();
            }

            if (taskOptions.Store.MigrateOnStartup)
            {
                runner.CreateCollectionIfNotExistsAsync().GetAwaiter().GetResult();
            }
        }
예제 #3
0
        private BackgroundTask CreateNewTask()
        {
            var task    = new BackgroundTask();
            var options = new BackgroundTaskOptions();

            // these values are required and must be set by implementation
            task.Handler         = "{}";
            task.MaximumAttempts = options.MaximumAttempts;
            task.MaximumRuntime  = TimeSpan.FromSeconds(options.MaximumRuntimeSeconds);
            task.DeleteOnError   = options.DeleteOnError;
            task.DeleteOnFailure = options.DeleteOnFailure;
            task.DeleteOnSuccess = options.DeleteOnSuccess;
            task.RunAt           = Store.GetTaskTimestamp();

            return(task);
        }
예제 #4
0
 private void OnSettingsChanged(BackgroundTaskOptions changed)
 {
     _logger.Info(() => "Background task options changed, recycling the host.");
     Stop();
     Start();
 }
예제 #5
0
        private static void MigrateToLatest(string connectionString, BackgroundTaskOptions options)
        {
            var runner = new SqliteMigrationRunner(connectionString, new SqliteConnectionOptions(options.Store));

            runner.OnStartAsync <CreateBackgroundTasksSchema>().GetAwaiter().GetResult();
        }