<commit_before>(ns onyx.job
  (:require [schema.core :as s]
            [onyx.schema :as os]))

(def base-schemas
  {:task-map os/TaskMap
   :lifecycles [os/Lifecycle]
   :triggers [os/Trigger]
   :windows [os/Window]
   :flow-conditions [os/FlowCondition]})

(defn vector-map-merge [schema base-schema]
  [(os/combine-restricted-ns (merge (first schema) (or (:schema (first base-schema))
                                                       (first base-schema))))])

(defn compose-schemas [{:keys [task schema]} base-schema]
  (let [{:keys [task-map lifecycles
                triggers windows
                flow-conditions]} schema]
    (-> schema
        (update :task-map os/UniqueTaskMap)
        (update :lifecycles vector-map-merge      (:lifecycles base-schema))
        (update :triggers vector-map-merge        (:triggers base-schema))
        (update :windows vector-map-merge         (:windows base-schema))
        (update :flow-conditions vector-map-merge (:flow-conditions base-schema))
        (select-keys (keys task)))))

(s/defn ^:always-validate add-task :- os/Job
  "Adds a task's task-definition to a job"
  ([job task-definition & behaviors]
   (add-task job (reduce (fn [acc f] (f acc)) task-definition behaviors)))
  ([{:keys [catalog lifecycles triggers windows flow-conditions] :as job}
    {:keys [task schema] :as task-definition}]
   (let [composed-schema (compose-schemas task-definition base-schemas)]
     (s/validate composed-schema task)
     (cond-> job
       catalog (update :catalog conj (:task-map task))
       lifecycles (update :lifecycles into (:lifecycles task))
       triggers (update :triggers into (:triggers task))
       windows (update :windows into (:windows task))
       flow-conditions (update :flow-conditions into (:flow-conditions task))))))<commit_msg>Fixed blunder on add-task merging in elements<commit_after>(ns onyx.job
  (:require [schema.core :as s]
            [onyx.schema :as os]))

(def base-schemas
  {:task-map os/TaskMap
   :lifecycles [os/Lifecycle]
   :triggers [os/Trigger]
   :windows [os/Window]
   :flow-conditions [os/FlowCondition]})

(defn vschema-merge [schema base-schema]
  [(os/combine-restricted-ns (merge (first schema) (or (:schema (first base-schema))
                                                       (first base-schema))))])

(defn compose-schemas [{:keys [task schema]} base-schema]
  (let [{:keys [task-map lifecycles
                triggers windows
                flow-conditions]} schema]
    (-> schema
        (update :task-map os/UniqueTaskMap)
        (update :lifecycles vschema-merge (:lifecycles base-schema))
        (update :triggers vschema-merge (:triggers base-schema))
        (update :windows vschema-merge (:windows base-schema))
        (update :flow-conditions vschema-merge (:flow-conditions base-schema))
        (select-keys (keys task)))))

(s/defn ^:always-validate add-task :- os/Job
  "Adds a task's task-definition to a job"
  ([job task-definition & behaviors]
   (add-task job (reduce (fn [acc f] (f acc)) task-definition behaviors)))
  ([job task-bundle]
   (let [{:keys [task schema]} task-bundle
         {:keys [task-map lifecycles triggers windows flow-conditions]} task
         composed-schema (compose-schemas task-bundle base-schemas)]
     (s/validate composed-schema task)
     (cond-> job
       task-map (update :catalog conj task-map)
       lifecycles (update :lifecycles into lifecycles)
       triggers (update :triggers into triggers)
       windows (update :windows into windows)
       flow-conditions (update :flow-conditions into flow-conditions)))))
{'fraction_non_alphanumeric': 0.13200221852468108, 'fraction_numerical': 0.0, 'mean_word_length': 2.8250265111346766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '460139', 'n_tokens_mistral': 1113, 'n_tokens_neox': 1062, 'n_words': 306}