<commit_before>(ns metabase.task.send-pulses
  "Tasks related to running `Pulses`."
  (:require [clojure.tools.logging :as log]
            [cheshire.core :as cheshire]
            (clojurewerkz.quartzite [jobs :as jobs]
                                    [triggers :as triggers])
            [clojurewerkz.quartzite.schedule.cron :as cron]
            [clj-time.core :as time]
            [hiccup.core :refer [html]]
            [metabase.db :as db]
            [metabase.driver :as driver]
            [metabase.email :as email]
            [metabase.integrations.slack :as slack]
            (metabase.models [card :refer [Card]]
                             [hydrate :refer :all]
                             [pulse :refer [Pulse] :as pulse]
                             [pulse-channel :as pulse-channel]
                             [setting :as setting])
            [metabase.task :as task]
            [metabase.util :as u]
            [metabase.pulse :as p]))


(declare send-pulses)

(def send-pulses-job-key "metabase.task.send-pulses.job")
(def send-pulses-trigger-key "metabase.task.send-pulses.trigger")

(defonce ^:private send-pulses-job (atom nil))
(defonce ^:private send-pulses-trigger (atom nil))

;; triggers the sending of all pulses which are scheduled to run in the current hour
(jobs/defjob SendPulses
  [ctx]
  ;; determine what time it is right now (hour-of-day & day-of-week) in reporting timezone
  (let [now (time/to-time-zone (time/now) (time/time-zone-for-id (or (setting/get :report_timezone) "UTC")))
        curr-hour (time/hour now)
        curr-weekday (:id (get pulse-channel/days-of-week (time/day-of-week now)))]
    (send-pulses curr-hour curr-weekday)))

(defn task-init []
  (log/info "Submitting send-pulses task to scheduler")<commit_msg>fix up the logic around calculating the current hour/day so that we properly apply the reporting timezone.<commit_after>(ns metabase.task.send-pulses
  "Tasks related to running `Pulses`."
  (:require [clojure.tools.logging :as log]
            [cheshire.core :as cheshire]
            (clojurewerkz.quartzite [jobs :as jobs]
                                    [triggers :as triggers])
            [clojurewerkz.quartzite.schedule.cron :as cron]
            [clj-time.core :as time]
            [hiccup.core :refer [html]]
            [metabase.db :as db]
            [metabase.driver :as driver]
            [metabase.email :as email]
            [metabase.integrations.slack :as slack]
            (metabase.models [card :refer [Card]]
                             [hydrate :refer :all]
                             [pulse :refer [Pulse] :as pulse]
                             [pulse-channel :as pulse-channel]
                             [setting :as setting])
            [metabase.task :as task]
            [metabase.util :as u]
            [metabase.pulse :as p]))


(declare send-pulses)

(def send-pulses-job-key "metabase.task.send-pulses.job")
(def send-pulses-trigger-key "metabase.task.send-pulses.trigger")

(defonce ^:private send-pulses-job (atom nil))
(defonce ^:private send-pulses-trigger (atom nil))

;; triggers the sending of all pulses which are scheduled to run in the current hour
(jobs/defjob SendPulses
  [ctx]
  ;; determine what time it is right now (hour-of-day & day-of-week) in reporting timezone
  (let [reporting-timezone (setting/get :report-timezone)
        now                (if (empty? reporting-timezone)
                             (time/now)
                             (time/to-time-zone (time/now) (time/time-zone-for-id reporting-timezone)))
        curr-hour          (time/hour now)
        curr-weekday       (->> (time/day-of-week now)
                                (get pulse-channel/days-of-week)
                                :id)]
    (send-pulses curr-hour curr-weekday)))

(defn task-init []
  (log/info "Submitting send-pulses task to scheduler")
{'fraction_non_alphanumeric': 0.11781314168377824, 'fraction_numerical': 0.0, 'mean_word_length': 1.9344879518072289, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3498043', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1188, 'n_words': 311}