You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

  1. var nThen = require("nthen");
  2. var Store = require("../lib/storage/file");
  3. var config = require("../lib/load-config");
  4. var store;
  5. var Log;
  6. nThen(function (w) {
  7. // load the store which will be used for iterating over channels
  8. // and performing operations like archival and deletion
  9. Store.create(config, w(function (err, _) {
  10. if (err) { throw err; }
  11. store = _;
  12. }));
  13. // load the logging module so that you have a record of which
  14. // files were archived or deleted at what time
  15. var Logger = require("../lib/log");
  16. Logger.create(config, w(function (_) {
  17. Log = _;
  18. }));
  19. }).nThen(function (w) {
  20. // count the number of files which have been restored in this run
  21. var restored = 0;
  22. var handler = function (err, item, cb) {
  23. if (err) {
  24. Log.error('RESTORE_ARCHIVED_CHANNEL_ITERATION', err);
  25. return void cb();
  26. }
  27. store.restoreArchivedChannel(item.channel, w(function (err) {
  28. if (err) {
  29. Log.error('RESTORE_ARCHIVED_CHANNEL_RESTORATION_ERROR', {
  30. error: err,
  31. channel: item.channel,
  32. });
  33. return void cb();
  34. }
  35. Log.info('RESTORE_ARCHIVED_CHANNEL_RESTORATION', item.channel);
  36. restored++;
  37. cb();
  38. }));
  39. };
  40. // if you hit an error, log it
  41. // otherwise, when there are no more channels to process
  42. // log some stats about how many were removed
  43. var done = function (err) {
  44. if (err) {
  45. return Log.error('RESTORE_ARCHIVED_FINAL_ERROR', err);
  46. }
  47. Log.info('RESTORE_ARCHIVED_CHANNELS_RESTORED', restored);
  48. };
  49. store.listArchivedChannels(handler, w(done));
  50. }).nThen(function () {
  51. // the store will keep this script running if you don't shut it down
  52. store.shutdown();
  53. Log.shutdown();
  54. });