/// <summary> /// Create background jobs to populate users and sandboxes /// This class separates the initialization engine from HangFire /// </summary> public void Configure() { if (!_initializationModel.Enabled) { return; } if (_apiConfigurationProvider.DatabaseEngine == DatabaseEngine.SqlServer) { // initial creation of roles, users, and sandboxes at server startup for sql server only var id1 = BackgroundJob.Enqueue(() => _engine.CreateIdentityRoles()); BackgroundJob.ContinueJobWith(id1, () => _engine.CreateIdentityUsers()); } // add vendors and sandboxes var id2 = BackgroundJob.Enqueue(() => _engine.CreateVendors()); var id3 = BackgroundJob.ContinueJobWith(id2, () => _engine.CreateSandboxes()); BackgroundJob.ContinueJobWith(id3, () => _engine.UpdateClientWithLEAIdsFromPopulatedSandbox()); // refresh existing sandboxes periodically if (_initializationModel.Users.Any(u => u.Sandboxes.Any(s => s.Refresh))) { // Change the recurrence to suit your needs using Cron functions or a unix CRON expressions (i.e. "* */6 * * *" = every 6 hours) RecurringJob.AddOrUpdate("RebuildSandboxes", () => _engine.RebuildSandboxes(), Cron.Daily(), TimeZoneInfo.Local); } }