server.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from fastapi import FastAPI
  2. from fastapi.middleware.cors import CORSMiddleware
  3. from app.core.airflow.job import AirflowJobSubmitter
  4. from app.models.database import engine, Base
  5. import app.routers.job_jdbc_datasource as router_jjds
  6. import app.routers.constants as router_constants
  7. import app.routers.job_info as router_job_info
  8. import app.routers.job_log as router_job_log
  9. import app.routers.datax_json as router_datax
  10. import app.routers.data_management as router_data_management
  11. import app.routers.files as router_files
  12. import app.routers.jm_homework as router_jm_homework
  13. import app.routers.dag as router_dag
  14. import app.routers.code_check as router_code_check
  15. import app.routers.jm_job_info as router_jm_job_info
  16. import app.routers.jm_job_log as router_jm_job_log
  17. import app.routers.auth as router_auth
  18. import app.routers.programme as router_programme
  19. from app.routers.run import router_af_run
  20. from app.routers.job import router_af_job
  21. from app.routers.task import router_af_task
  22. from configs.globals import GlobalsMiddleware
  23. from utils.sx_log import format_print
  24. import os
  25. format_print()
  26. PREFIX = os.environ.get('APP_PREFIX', default='jpt')
  27. print(f'prefix: {PREFIX}')
  28. Base.metadata.create_all(bind=engine)
  29. app = FastAPI(docs_url=f'/{PREFIX}/docs', redoc_url=f'/{PREFIX}/redoc',
  30. openapi_url=f'/{PREFIX}/openapi.json', title="DAG In Airflow管理系统")
  31. # CORS 跨源资源共享
  32. app.add_middleware(
  33. CORSMiddleware,
  34. allow_origins=["*"],
  35. allow_credentials=True,
  36. allow_methods=["*"],
  37. allow_headers=["*"],
  38. )
  39. app.add_middleware(GlobalsMiddleware)
  40. app.include_router(router_auth.router)
  41. app.include_router(router_programme.router)
  42. app.include_router(router_jjds.router)
  43. app.include_router(router_constants.router)
  44. app.include_router(router_job_info.router)
  45. app.include_router(router_job_log.router)
  46. app.include_router(router_data_management.router)
  47. app.include_router(router_datax.router)
  48. app.include_router(router_files.router)
  49. app.include_router(router_jm_homework.router)
  50. app.include_router(router_dag.router)
  51. app.include_router(router_af_task)
  52. app.include_router(router_af_job)
  53. app.include_router(router_af_run)
  54. app.include_router(router_jm_job_info.router)
  55. app.include_router(router_jm_job_log.router)
  56. app.include_router(router_code_check.router)
  57. if PREFIX == 'af':
  58. AirflowJobSubmitter.auto_submit_data_transfer()
  59. AirflowJobSubmitter.auto_submit_requirements_install()
  60. print('server init finish:)!!!')
  61. # Get 健康检查
  62. @app.get(f"/{PREFIX}/ping", description="健康检查")
  63. def ping():
  64. return "pong"