diff --git a/src/metabase/core.clj b/src/metabase/core.clj index 089a549f8f6af8542da7ef432070daa330081c53..d3cc2c1262a13cd5fbb3f999401a3b4df9bd5c6f 100644 --- a/src/metabase/core.clj +++ b/src/metabase/core.clj @@ -104,8 +104,8 @@ (events/initialize-events!) (init-status/set-progress! 0.7) - ;; Now start the task runner - (task/start-scheduler!) + ;; Now initialize the task runner + (task/init-scheduler!) (init-status/set-progress! 0.8) (when new-install? @@ -123,6 +123,8 @@ ;; otherwise update if appropriate (sample-data/update-sample-database-if-needed!))) + ;; start scheduler at end of init! + (task/start-scheduler!) (init-status/set-complete!) (log/info (trs "Metabase Initialization COMPLETE"))) diff --git a/src/metabase/task.clj b/src/metabase/task.clj index 625091faa89177f6059eb601ef1862e07066a114..f8af6d20837b56060819384d38eca10b94ed5581 100644 --- a/src/metabase/task.clj +++ b/src/metabase/task.clj @@ -146,8 +146,9 @@ (when (= (mdb/db-type) :postgres) (System/setProperty "org.quartz.jobStore.driverDelegateClass" "org.quartz.impl.jdbcjobstore.PostgreSQLDelegate"))) -(defn start-scheduler! - "Start our Quartzite scheduler which allows jobs to be submitted and triggers to begin executing." +(defn init-scheduler! + "Initialize our Quartzite scheduler which allows jobs to be submitted and triggers to scheduled. Puts scheduler in + standby mode. Call [[start-scheduler!]] to begin running scheduled tasks." [] (classloader/the-classloader) (when-not @quartz-scheduler @@ -155,9 +156,19 @@ (let [new-scheduler (qs/initialize)] (when (compare-and-set! quartz-scheduler nil new-scheduler) (find-and-load-task-namespaces!) - (qs/start new-scheduler) + (qs/standby new-scheduler) + (log/info (trs "Task scheduler initialized into standby mode.")) (init-tasks!))))) +(defn start-scheduler! + "Start an initialized scheduler. Tasks do not run before calling this function. It is an error to call this function + when [[quartz-scheduler]] has not been set. The function [[init-scheduler!]] will initialize this correctly." + [] + (if-let [scheduler @quartz-scheduler] + (do (qs/start scheduler) + (log/info (trs "Task scheduler started"))) + (throw (trs "Scheduler not initialized but `start-scheduler!` called. Please call `init-scheduler!` before attempting to start.")))) + (defn stop-scheduler! "Stop our Quartzite scheduler and shutdown any running executions." []