Release5767.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using MediaBrowser.Common.ScheduledTasks;
  5. using MediaBrowser.Controller.Configuration;
  6. using MediaBrowser.Server.Implementations.LiveTv;
  7. using MediaBrowser.Server.Implementations.Persistence;
  8. using MediaBrowser.Server.Implementations.ScheduledTasks;
  9. namespace MediaBrowser.Server.Startup.Common.Migrations
  10. {
  11. public class Release5767 : IVersionMigration
  12. {
  13. private readonly IServerConfigurationManager _config;
  14. private readonly ITaskManager _taskManager;
  15. public Release5767(IServerConfigurationManager config, ITaskManager taskManager)
  16. {
  17. _config = config;
  18. _taskManager = taskManager;
  19. }
  20. public async void Run()
  21. {
  22. var name = "5767.1";
  23. if (_config.Configuration.Migrations.Contains(name, StringComparer.OrdinalIgnoreCase))
  24. {
  25. return;
  26. }
  27. Task.Run(async () =>
  28. {
  29. await Task.Delay(3000).ConfigureAwait(false);
  30. _taskManager.QueueScheduledTask<CleanDatabaseScheduledTask>();
  31. });
  32. // Wait a few minutes before marking this as done. Make sure the server doesn't get restarted.
  33. await Task.Delay(300000).ConfigureAwait(false);
  34. var list = _config.Configuration.Migrations.ToList();
  35. list.Add(name);
  36. _config.Configuration.Migrations = list.ToArray();
  37. _config.SaveConfiguration();
  38. }
  39. }
  40. }