Skip to content
Snippets Groups Projects
Commit e13d9aa8 authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #1078 from metabase/task_reloading_fix

Task/Events reloading fix
parents ab657241 46f2289d
Branches
Tags
No related merge requests found
(ns metabase.events
"Provides a very simply event bus using `core.async` to allow publishing and subscribing to intersting
topics happening throughout the Metabase system in a decoupled way."
topics happening throughout the Metabase system in a decoupled way.
## Regarding Events Initialization:
The most appropriate way to initialize event listeners in any `metabase.events.*` namespace is to implement the
`events-init` function which accepts zero arguments. This function is dynamically resolved and called exactly
once when the application goes through normal startup procedures. Inside this function you can do any work
needed and add your events subscribers to the bus as usual via `start-event-listener`."
(:require clojure.java.classpath
[clojure.core.async :as async]
[clojure.tools.logging :as log]
......@@ -22,7 +29,9 @@
set
(map (fn [events-ns]
(log/info "\tloading events namespace: " events-ns)
(require events-ns)))
(require events-ns)
;; look for `events-init` function in the namespace and call it if it exists
((ns-resolve events-ns 'events-init))))
dorun))
(defn initialize-events!
......
......@@ -122,7 +122,7 @@
;;; ## ---------------------------------------- LIFECYLE ----------------------------------------
;; this is what actually kicks off our listener for events
(when (config/is-prod?)
(log/info "Starting activity-feed events listener")
(events/start-event-listener activity-feed-topics activity-feed-channel process-activity-event))
(defn events-init []
(when-not (config/is-test?)
(log/info "Starting activity-feed events listener")
(events/start-event-listener activity-feed-topics activity-feed-channel process-activity-event)))
......@@ -54,7 +54,7 @@
;;; ## ---------------------------------------- LIFECYLE ----------------------------------------
;; this is what actually kicks off our listener for events
(when (config/is-prod?)
(log/info "Starting revision events listener")
(events/start-event-listener revisions-topics revisions-channel process-revision-event))
(defn events-init []
(when-not (config/is-test?)
(log/info "Starting revision events listener")
(events/start-event-listener revisions-topics revisions-channel process-revision-event)))
......@@ -39,7 +39,7 @@
;;; ## ---------------------------------------- LIFECYLE ----------------------------------------
;; this is what actually kicks off our listener for events
(when (config/is-prod?)
(log/info "Starting database sync events listener")
(events/start-event-listener sync-database-topics sync-database-channel process-sync-database-event))
(defn events-init []
(when-not (config/is-test?)
(log/info "Starting database sync events listener")
(events/start-event-listener sync-database-topics sync-database-channel process-sync-database-event)))
......@@ -47,7 +47,7 @@
;;; ## ---------------------------------------- LIFECYLE ----------------------------------------
;; this is what actually kicks off our listener for events
(when (config/is-prod?)
(log/info "Starting view-log events listener")
(events/start-event-listener view-counts-topics view-counts-channel process-view-count-event))
(defn events-init []
(when-not (config/is-test?)
(log/info "Starting view-log events listener")
(events/start-event-listener view-counts-topics view-counts-channel process-view-count-event)))
(ns metabase.task
"Background task scheduling via Quartzite. Individual tasks are defined in `metabase.task.*`"
"Background task scheduling via Quartzite. Individual tasks are defined in `metabase.task.*`.
## Regarding Task Initialization:
The most appropriate way to initialize tasks in any `metabase.task.*` namespace is to implement the
`task-init` function which accepts zero arguments. This function is dynamically resolved and called
exactly once when the application goes through normal startup procedures. Inside this function you
can do any work needed and add your task to the scheduler as usual via `schedule-task!`."
(:require clojure.java.classpath
[clojure.tools.logging :as log]
[clojure.tools.namespace.find :as ns-find]
......@@ -18,7 +25,9 @@
set
(map (fn [events-ns]
(log/info "\tloading tasks namespace: " events-ns)
(require events-ns)))
(require events-ns)
;; look for `task-init` function in the namespace and call it if it exists
((ns-resolve events-ns 'task-init))))
dorun))
(defn start-scheduler!
......
......@@ -27,8 +27,7 @@
(catch Exception e
(log/error "Error syncing database: " (:id database) e))))))
;; this is what actually adds our task to the scheduler
(when (config/is-prod?)
(defn task-init []
(log/info "Submitting sync-database task to scheduler")
;; build our job
(reset! sync-databases-job (jobs/build
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment