core.py 847 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. from demeter.core import *
  3. import json
  4. class Core(object):
  5. # 实时同步
  6. def rsync(self, table, id):
  7. command = Demeter.path + 'sync.py -t ' + str(table) + ' -i ' + str(id)
  8. Shell.popen("python3 " + command, bg=True)
  9. #self.sync(table, {'id':id})
  10. # 远程同步
  11. def sync(self, table, search={}):
  12. farm = Demeter.service('common').list('farm', search={'eros_status':1})
  13. state = True
  14. data = Demeter.service('common').list(table, state=state, search=search)
  15. if not data:
  16. state = False
  17. data = Demeter.service('common').list(table, state=state, search=search)
  18. param = {}
  19. param['data'] = json.dumps(data)
  20. param['table'] = table
  21. if farm and data:
  22. for v in farm:
  23. url = 'http://' + v['eros_server'] + ':8081/interface/sync'
  24. Demeter.curl(url, param, 'post')