Skip to content
Snippets Groups Projects
Commit 331b3706 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran
Browse files

cron this puppy up

parent c6fa3566
Branches
Tags
No related merge requests found
(ns metabase.task.send-anonymous-stats
"Contains a Metabase task which periodically sends anonymous usage information to the Metabase team."
(:require [clojure.tools.logging :as log]
(clojurewerkz.quartzite [jobs :as jobs]
[triggers :as triggers])
[clojurewerkz.quartzite.schedule.cron :as cron]
(metabase [config :as config]
[public-settings :as public-settings]
[task :as task]
[util.stats :as stats])))
(def ^:private ^:const job-key "metabase.task.anonymous-stats.job")
(def ^:private ^:const trigger-key "metabase.task.anonymous-stats.trigger")
(defonce ^:private job (atom nil))
(defonce ^:private trigger (atom nil))
;; if we can collect usage data, do so and send it home
(jobs/defjob SendAnonymousUsageStats
[ctx]
(when (public-settings/anon-tracking-enabled)
(log/debug "Sending anonymous usage stats.")
(try
;; TODO: add in additional request params if anonymous tracking is enabled
(stats/phone-home-stats!)
(catch Throwable e
(log/error "Error sending anonymous usage stats: " e)))))
(defn task-init
"Job initialization"
[]
;; build our job
(reset! job (jobs/build
(jobs/of-type SendAnonymousUsageStats)
(jobs/with-identity (jobs/key job-key))))
;; build our trigger
(reset! trigger (triggers/build
(triggers/with-identity (triggers/key trigger-key))
(triggers/start-now)
(triggers/with-schedule
;; run twice a day
(cron/cron-schedule "0 15 7 * * ? *"))))
;; submit ourselves to the scheduler
(task/schedule-task! @job @trigger))
......@@ -301,25 +301,23 @@
(defn get-anonymous-usage-stats
"generate a map of the usage stats for this instance"
[]
(when [setting/get :anon-tracking-enabled]
;do stuff
(merge (get-settings)
(merge (get-settings)
{:uuid anonymous-id :timestamp (new java.util.Date)}
{:stats {
:user (get-user-metrics)
:question (get-question-metrics)
:dashboard (get-dashboard-metrics)
:database (get-database-metrics)
:table (get-table-metrics)
:field (get-field-metrics)
:pulse (get-pulse-metrics)
:segment (get-segment-metrics)
:metric (get-metric-metrics)
:group (get-group-metrics)
:label (get-label-metrics)
:execution (get-execution-metrics)}})))
(defn- send-stats
:user (get-user-metrics)
:question (get-question-metrics)
:dashboard (get-dashboard-metrics)
:database (get-database-metrics)
:table (get-table-metrics)
:field (get-field-metrics)
:pulse (get-pulse-metrics)
:segment (get-segment-metrics)
:metric (get-metric-metrics)
:group (get-group-metrics)
:label (get-label-metrics)
:execution (get-execution-metrics)}}))
(defn- send-stats!
"send stats to Metabase tracking server"
[stats]
(try
......@@ -327,8 +325,8 @@
(catch Throwable e
(log/error "Sending usage stats FAILED: " (.getMessage e)))))
(defn phone-home-stats
"doc-string"
(defn phone-home-stats!
"Collect usage stats and phone them home"
[]
(when (anon-tracking-enabled?)
(send-stats (get-anonymous-usage-stats))))
\ No newline at end of file
(send-stats! (get-anonymous-usage-stats))))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment