datax.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from app import crud, models
  2. from app.utils.send_util import *
  3. from app.utils.utils import get_cmd_parameter
  4. from sqlalchemy.orm import Session
  5. def datax_create_job(job_info: models.JobInfo, db: Session):
  6. af_task = datax_create_task(job_info)
  7. af_job = {
  8. "tasks": [af_task],
  9. "name": job_info.job_desc,
  10. "dependence": [],
  11. "cron": job_info.job_cron,
  12. "desc": job_info.job_desc,
  13. "route_strategy": job_info.executor_route_strategy,
  14. "block_strategy": job_info.executor_block_strategy,
  15. "executor_timeout": job_info.executor_timeout,
  16. "executor_fail_retry_count": job_info.executor_fail_retry_count,
  17. "trigger_status": job_info.trigger_status,
  18. "job_mode":1,
  19. "job_type": 0,
  20. "user_id": 0,
  21. }
  22. res = send_post('/jpt/af_job', af_job)
  23. af_job = res['data']
  24. crud.create_relation(db, job_info.id,'datax', af_job['id'])
  25. send_submit(af_job['id'])
  26. def datax_create_task(job_info: models.JobInfo):
  27. cmd_parameter = get_cmd_parameter(job_info.jvm_param, job_info.inc_start_time, job_info.replace_param, job_info.partition_info)
  28. af_task = {
  29. "name": job_info.job_desc,
  30. "file_urls": [],
  31. "script": job_info.job_json,
  32. "cmd": "",
  33. "cmd_parameters": cmd_parameter,
  34. "envs": {},
  35. "run_image": "",
  36. "task_type": "datax",
  37. "user_id": 0,
  38. }
  39. res = send_post('/jpt/af_task', af_task)
  40. af_task = res['data']
  41. return af_task
  42. def datax_update_job(job_info: models.JobInfo, db: Session):
  43. relation = crud.get_af_id(db, job_info.id, 'datax')
  44. af_job_id = relation.af_id
  45. res = send_get("/jpt/af_job/getOnce",af_job_id)
  46. old_af_job = res['data']
  47. old_af_task = old_af_job['tasks'][0]
  48. af_task = datax_put_task(job_info,old_af_task)
  49. af_job = {
  50. "tasks": [af_task],
  51. "name": job_info.job_desc,
  52. "dependence": [],
  53. "cron": job_info.job_cron,
  54. "desc": job_info.job_desc,
  55. "route_strategy": job_info.executor_route_strategy,
  56. "block_strategy": job_info.executor_block_strategy,
  57. "executor_timeout": job_info.executor_timeout,
  58. "executor_fail_retry_count": job_info.executor_fail_retry_count,
  59. "trigger_status": job_info.trigger_status,
  60. }
  61. res = send_put('/jpt/af_job', old_af_job['id'], af_job)
  62. af_job = res['data']
  63. send_submit(af_job['id'])
  64. def datax_put_task(job_info: models.JobInfo,old_af_task):
  65. cmd_parameter = get_cmd_parameter(job_info.jvm_param, job_info.inc_start_time, job_info.replace_param, job_info.partition_info)
  66. af_task = {
  67. "name": job_info.job_desc,
  68. "file_urls": [],
  69. "script": job_info.job_json,
  70. "cmd": "",
  71. "cmd_parameters": cmd_parameter,
  72. "envs": {},
  73. "run_image": "",
  74. }
  75. res = send_put('/jpt/af_task', old_af_task['id'],af_task)
  76. af_task = res['data']
  77. return af_task