1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980openLwt.SyntaxmoduleSig=App_sigmoduleMake(Kernel:Sig.KERNEL)=structtypet={config:Configuration.t;endpoints:Web.Server.endpointlist;services:(moduleCore.Container.SERVICE)list;schedules:Schedule.tlist;commands:Cmd.tlist;seeds:Seed.tlist;on_start:Core.Ctx.t->unitLwt.t;on_stop:Core.Ctx.t->unitLwt.t;}letempty={config=Configuration.create~development:[]~test:[]~production:[];endpoints=[];services=[];schedules=[];commands=[];seeds=[];on_start=(fun_->Lwt.return());on_stop=(fun_->Lwt.return());}letwith_configconfigapp={appwithconfig}letwith_endpointsendpointsapp={appwithendpoints}letwith_servicesservicesapp={appwithservices}letwith_schedulesschedulesapp={appwithschedules}letwith_commandscommandsapp={appwithcommands}letwith_seedsseedsapp={appwithseeds}leton_starton_startapp={appwithon_start}leton_stopon_stopapp={appwithon_stop}letstart_cmd=Cmd.make~name:"start"~help:"<with_migration>"~description:"Start the Sihl app, use <with_migration> to optionally run the \
migrations before starting the web server"~fn:(funargs->matchargswith|["with_migration"]->letctx=Core.Ctx.empty|>Kernel.Db.add_poolinlet*()=Kernel.Migration.run_allctxinKernel.WebServer.start_serverctx|[]->letctx=Core.Ctx.emptyinKernel.WebServer.start_serverctx|_->raise(Cmd.Invalid_usage"Example usage: start with_migration"))()letrunapp=Lwt_main.run(letctx=Core.Ctx.emptyinKernel.Log.debug(funm->m"APP: Register config");Kernel.Config.register_configapp.config;Kernel.Log.debug(funm->m"APP: Register routes");Kernel.WebServer.register_endpointsapp.endpoints;Kernel.Log.debug(funm->m"APP: Register commands");letcommands=List.consstart_cmdapp.commandsinKernel.Cmd.register_commandscommands;Kernel.Log.debug(funm->m"APP: Register seeds");Kernel.Seed.register_seedsapp.seeds;Kernel.Log.debug(funm->m"APP: Register schedules");let_=app.schedules|>List.map(Kernel.Schedule.schedulectx)inKernel.Log.debug(funm->m"APP: Start services");let*_,ctx=Core.Container.start_servicesapp.servicesinKernel.Log.debug(funm->m"APP: Start app");let*()=app.on_startctxinKernel.Cmd.run())end