send_util.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from unittest import result
  2. import requests
  3. from configs.settings import config
  4. HOST = config.get('AIRFLOW', 'HOST')
  5. PORT = config.get('AIRFLOW', 'PORT')
  6. def send_post(uri,data):
  7. res = requests.post(url=f'http://{HOST}:{PORT}{uri}', json=data)
  8. result = res.json()
  9. if 'code' in result.keys() and result['code'] == 200:
  10. return res.json()
  11. else:
  12. raise Exception('请求airflow失败')
  13. def send_submit(af_job_id):
  14. res = requests.post(url=f'http://{HOST}:{PORT}/jpt/af_job/submit?id='+str(af_job_id))
  15. result = res.json()
  16. print(result)
  17. if 'code' in result.keys() and result['code'] == 200:
  18. return res.json()
  19. else:
  20. raise Exception('请求airflow失败')
  21. def send_put(uri,path_data,data):
  22. res = requests.put(url=f'http://{HOST}:{PORT}{uri}/{path_data}', json=data)
  23. result = res.json()
  24. if 'code' in result.keys() and result['code'] == 200:
  25. return res.json()
  26. else:
  27. raise Exception('请求airflow失败')
  28. def send_get(uri,path_data):
  29. res = requests.get(url=f'http://{HOST}:{PORT}{uri}/{path_data}')
  30. result = res.json()
  31. if 'code' in result.keys() and result['code'] == 200:
  32. return res.json()
  33. else:
  34. raise Exception('请求airflow失败')