server.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. import app.routers.statistics as router_statistics
  20. from app.routers.run import router_af_run
  21. from app.routers.job import router_af_job
  22. from app.routers.task import router_af_task
  23. from configs.globals import GlobalsMiddleware
  24. from utils.sx_log import format_print
  25. import os
  26. format_print()
  27. PREFIX = os.environ.get('APP_PREFIX', default='jpt')
  28. print(f'prefix: {PREFIX}')
  29. Base.metadata.create_all(bind=engine)
  30. app = FastAPI(docs_url=f'/{PREFIX}/docs', redoc_url=f'/{PREFIX}/redoc',
  31. openapi_url=f'/{PREFIX}/openapi.json', title="DAG In Airflow管理系统")
  32. # CORS 跨源资源共享
  33. app.add_middleware(
  34. CORSMiddleware,
  35. allow_origins=["*"],
  36. allow_credentials=True,
  37. allow_methods=["*"],
  38. allow_headers=["*"],
  39. )
  40. app.add_middleware(GlobalsMiddleware)
  41. app.include_router(router_auth.router)
  42. app.include_router(router_programme.router)
  43. app.include_router(router_jjds.router)
  44. app.include_router(router_constants.router)
  45. app.include_router(router_job_info.router)
  46. app.include_router(router_job_log.router)
  47. app.include_router(router_data_management.router)
  48. app.include_router(router_datax.router)
  49. app.include_router(router_files.router)
  50. app.include_router(router_jm_homework.router)
  51. app.include_router(router_dag.router)
  52. app.include_router(router_af_task)
  53. app.include_router(router_af_job)
  54. app.include_router(router_af_run)
  55. app.include_router(router_jm_job_info.router)
  56. app.include_router(router_jm_job_log.router)
  57. app.include_router(router_code_check.router)
  58. app.include_router(router_statistics.router)
  59. if PREFIX == 'af':
  60. AirflowJobSubmitter.auto_submit_data_transfer()
  61. AirflowJobSubmitter.auto_submit_requirements_install()
  62. print('server init finish:)!!!')
  63. # Get 健康检查
  64. @app.get(f"/{PREFIX}/ping", description="健康检查")
  65. def ping():
  66. return "pong"