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.

35 lines
1010 B

  1. const _ = require('lodash')
  2. /* global WIKI */
  3. module.exports = async (targetKey) => {
  4. WIKI.logger.info(`Syncing with storage target ${targetKey}...`)
  5. try {
  6. const target = _.find(WIKI.models.storage.targets, ['key', targetKey])
  7. if (target) {
  8. await target.fn.sync()
  9. WIKI.logger.info(`Syncing with storage target ${targetKey}: [ COMPLETED ]`)
  10. await WIKI.models.storage.query().patch({
  11. state: {
  12. status: 'operational',
  13. message: '',
  14. lastAttempt: new Date().toISOString()
  15. }
  16. }).where('key', targetKey)
  17. } else {
  18. throw new Error('Invalid storage target. Unable to perform sync.')
  19. }
  20. } catch (err) {
  21. WIKI.logger.error(`Syncing with storage target ${targetKey}: [ FAILED ]`)
  22. WIKI.logger.error(err.message)
  23. await WIKI.models.storage.query().patch({
  24. state: {
  25. status: 'error',
  26. message: err.message,
  27. lastAttempt: new Date().toISOString()
  28. }
  29. }).where('key', targetKey)
  30. }
  31. }