add_datax_task_with_minio.py 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import time
  2. import requests
  3. from auo_tests.tasks.config import host
  4. from auo_tests.tasks.minio_handler import FileHandler, URL as MinioURL
  5. filename = 'hive2hive.json'
  6. minio_bucket = 'mytest'
  7. minio_path = f'datax/' + filename
  8. minio_handler = FileHandler(bucket_name=minio_bucket)
  9. with open(filename, 'rb') as f:
  10. minio_handler.put_byte_file(file_name=minio_path, file_content=f.read())
  11. file_path = f'{minio_bucket}/{minio_path}'
  12. cmd_parameter = '-j "-Xms2G -Xmx2G" -p "-Dct=hangzhou" '
  13. name = f'datax_task_{int(time.time())}'
  14. data = {
  15. "name": name,
  16. "file_urls": [file_path],
  17. "script": "",
  18. "cmd": "cd datax/bin && curl $FILE_TO_DOWNLOAD >> config.json && echo \"\'\"$HOME/conda/envs/py27/bin/python datax.py $CMD_PARM config.json\"\'\" |xargs bash -c",
  19. "cmd_parameters": cmd_parameter,
  20. "envs": {"FILE_TO_DOWNLOAD": f'http://{MinioURL}/{file_path}'},
  21. "run_image": "SXKJ:32775/pod_datax:0.9",
  22. "task_type": "datax",
  23. "user_id": 33
  24. }
  25. print(data)
  26. ret = requests.post(url=f'http://{host}/jpt/jpt_task', json=data)
  27. print(ret.json())