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.users as router_users
  18. import app.routers.project as router_project
  19. import app.routers.programme as router_programme
  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', 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_users.router)
  41. app.include_router(router_project.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. if PREFIX == 'af':
  59. AirflowJobSubmitter.auto_submit_data_transfer()
  60. AirflowJobSubmitter.auto_submit_requirements_install()
  61. print('server init finish:)!!!')
  62. # Get 健康检查
  63. @app.get(f"/{PREFIX}/ping", description="健康检查")
  64. def ping():
  65. return "pong!!"