server.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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', openapi_url=f'/{PREFIX}/openapi.json', title="DAG In Airflow管理系统")
  30. # CORS 跨源资源共享
  31. app.add_middleware(
  32. CORSMiddleware,
  33. allow_origins=["*"],
  34. allow_credentials=True,
  35. allow_methods=["*"],
  36. allow_headers=["*"],
  37. )
  38. app.add_middleware(GlobalsMiddleware)
  39. app.include_router(router_auth.router)
  40. app.include_router(router_programme.router)
  41. app.include_router(router_jjds.router)
  42. app.include_router(router_constants.router)
  43. app.include_router(router_job_info.router)
  44. app.include_router(router_job_log.router)
  45. app.include_router(router_data_management.router)
  46. app.include_router(router_datax.router)
  47. app.include_router(router_files.router)
  48. app.include_router(router_jm_homework.router)
  49. app.include_router(router_dag.router)
  50. app.include_router(router_af_task)
  51. app.include_router(router_af_job)
  52. app.include_router(router_af_run)
  53. app.include_router(router_jm_job_info.router)
  54. app.include_router(router_jm_job_log.router)
  55. app.include_router(router_code_check.router)
  56. if PREFIX == 'af':
  57. AirflowJobSubmitter.auto_submit_data_transfer()
  58. AirflowJobSubmitter.auto_submit_requirements_install()
  59. print('server init finish:)!!!')
  60. # Get 健康检查
  61. @app.get(f"/{PREFIX}/ping", description="健康检查")
  62. def ping():
  63. return "pong!!"