sync.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Command, flags } from '@oclif/command'
  2. import { performSync } from '../../services/sync/synchronizer'
  3. import logger from '../../services/logger'
  4. /**
  5. * CLI command:
  6. * Synchronizes data: fixes the difference between node obligations and local
  7. * storage.
  8. *
  9. * @remarks
  10. * Should be run only during the development.
  11. * Shell command: "dev:upload"
  12. */
  13. export default class DevSync extends Command {
  14. static description =
  15. 'Synchronizes the data - it fixes the differences between local data folder and worker ID obligations from the runtime.'
  16. static flags = {
  17. help: flags.help({ char: 'h' }),
  18. workerId: flags.integer({
  19. char: 'w',
  20. required: true,
  21. description: 'Storage node operator worker ID.',
  22. }),
  23. syncWorkersNumber: flags.integer({
  24. char: 'p',
  25. required: false,
  26. description: 'Sync workers number (max async operations in progress).',
  27. }),
  28. queryNodeHost: flags.string({
  29. char: 'q',
  30. required: false,
  31. description: 'Query node host and port (e.g.: some.com:8081)',
  32. }),
  33. dataSourceOperatorHost: flags.string({
  34. char: 'o',
  35. required: false,
  36. description: 'Storage node host and port (e.g.: some.com:8081) to get data from.',
  37. }),
  38. uploads: flags.string({
  39. char: 'd',
  40. required: true,
  41. description: 'Data uploading directory (absolute path).',
  42. }),
  43. }
  44. async run(): Promise<void> {
  45. const { flags } = this.parse(DevSync)
  46. logger.info('Syncing...')
  47. const queryNodeHost = flags.queryNodeHost ?? 'localhost:8081'
  48. const queryNodeUrl = `http://${queryNodeHost}/graphql`
  49. const syncWorkersNumber = flags.syncWorkersNumber ?? 20
  50. const dataSourceOperatorHost = flags.dataSourceOperatorHost ?? 'localhost:3333'
  51. const operatorUrl = `http://${dataSourceOperatorHost}/`
  52. try {
  53. await performSync(flags.workerId, syncWorkersNumber, queryNodeUrl, flags.uploads, operatorUrl)
  54. } catch (err) {
  55. logger.error(err)
  56. logger.error(JSON.stringify(err, null, 2))
  57. }
  58. }
  59. }