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.

45 lines
1.2 KiB

  1. require('../core/worker')
  2. const _ = require('lodash')
  3. const { createApolloFetch } = require('apollo-fetch')
  4. /* global WIKI */
  5. WIKI.redis = require('../core/redis').init()
  6. WIKI.models = require('../core/db').init()
  7. module.exports = async (job) => {
  8. WIKI.logger.info(`Fetching latest updates from Graph endpoint...`)
  9. try {
  10. await WIKI.configSvc.loadFromDb()
  11. const apollo = createApolloFetch({
  12. uri: WIKI.config.graphEndpoint
  13. })
  14. const resp = await apollo({
  15. query: `query ($channel: ReleaseChannel!, $version: String!) {
  16. releases {
  17. checkForUpdates(channel: $channel, version: $version) {
  18. channel
  19. version
  20. releaseDate
  21. minimumVersionRequired
  22. minimumNodeRequired
  23. }
  24. }
  25. }`,
  26. variables: {
  27. channel: 'BETA', // TODO
  28. version: WIKI.version
  29. }
  30. })
  31. const info = _.get(resp, 'data.releases.checkForUpdates', {})
  32. await WIKI.redis.publish('updates', JSON.stringify(info))
  33. WIKI.logger.info(`Fetching latest updates from Graph endpoint: [ COMPLETED ]`)
  34. } catch (err) {
  35. WIKI.logger.error(`Fetching latest updates from Graph endpoint: [ FAILED ]`)
  36. WIKI.logger.error(err.message)
  37. }
  38. }