refresh_lib.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = {
  10. schedule: {
  11. // interval: '30s', // 30 seconds, for dev
  12. interval: '5m', // 5 min, for opr
  13. type: 'worker',
  14. },
  15. async task (ctx) {
  16. if (!ctx.app.awaitRefresh || ctx.app.awaitRefresh.length === 0) return;
  17. const lib = await ctx.service.quotaLib.getDataById(ctx.app.awaitRefresh.shift());
  18. if (!lib) return;
  19. const nsp = ctx.app.io.of('/lib');
  20. try {
  21. // test error
  22. // throw '1';
  23. await ctx.service.quotaLib.refreshLib(lib);
  24. nsp.emit('refreshed', {
  25. id: lib.id,
  26. filename: lib.filename,
  27. success: true,
  28. count: ctx.app.awaitRefresh.length,
  29. });
  30. } catch(err) {
  31. console.log(err);
  32. nsp.emit('refreshed', {
  33. id: lib.id,
  34. filename: lib.filename,
  35. success: false,
  36. count: ctx.app.awaitRefresh.length,
  37. });
  38. }
  39. }
  40. };