File tree Expand file tree Collapse file tree 5 files changed +16
-18
lines changed Expand file tree Collapse file tree 5 files changed +16
-18
lines changed Original file line number Diff line number Diff line change 2020 :bearer-token " top-secret!" }}
2121 :cron-jobs [{:type :allocate-order
2222 :channel-id " UA"
23- :expression " 4 0 * ? * * *" }]}}
23+ :expression " 0 0/1 * 1/1 * ? *" }]}}
Original file line number Diff line number Diff line change 1111
1212(defn init []
1313 (for [cron-job-config (config/get-all-cron-jobs )]
14- (job/schedule scheduler cron-job-config)))
14+ (job/schedule scheduler cron-job-config)))
Original file line number Diff line number Diff line change 99(defmulti jobtype :type )
1010
1111(defn- identifier [{:keys [channel-id type]}]
12- (keyword channel-id (name type)))
12+ (str channel-id " / " (name type)))
1313
1414(defn- create-job [channel-config cron-job-config]
1515 (qj/build
2222 :as cron-job-config}]
2323 (qt/build
2424 (qt/with-identity (qt/key (identifier cron-job-config)))
25- (qt/start-now )
2625 (qt/with-schedule (qsc/schedule
2726 (qsc/cron-schedule expression)))))
2827
29- (defn create [{:keys [channel-id]
30- :as cron-job-config}]
31- (when-let [channel-config (config/get-channel-config channel-id)]
32- (create-job channel-config cron-job-config)))
33-
3428(defn handle [channel-fn ctx]
35- (channel-fn (qc/from-job-data ctx) nil ))
29+ (let [{:strs [channel-config cron-job-config]} (qc/from-job-data ctx)]
30+ (channel-fn (:channel-id cron-job-config) channel-config)))
3631
37- (defn schedule [scheduler cron-job-config]
38- (when-let [job (create cron-job-config)]
39- (qs/schedule scheduler job (create-trigger cron-job-config))))
32+ (defn schedule [scheduler {:keys [channel-id]
33+ :as cron-job-config}]
34+ (when-let [channel-config (config/get-channel-config channel-id)]
35+ (let [job (create-job channel-config cron-job-config)
36+ trigger (create-trigger cron-job-config)]
37+ (qs/schedule scheduler job trigger))))
4038
4139(comment
42- (key {:channel-id " UA"
43- :type :allocate-order }))
40+ (identifier {:channel-id " UA"
41+ :type :allocate-order }))
Original file line number Diff line number Diff line change 55(s/def ::name #{:tata-cliq :amazon :flipkart })
66
77(defmulti allocate-order (fn [channel-id channel-config]
8- (:name channel-config)))
8+ (:channel- name channel-config)))
Original file line number Diff line number Diff line change 2323 (catch Throwable ex
2424 (event/processing-failed ex id :ranging channel-id channel-name))))
2525
26- (defmethod channel /allocate-order :tata-cliq [x _ ]
27- (prn " ~~>" x ))
26+ (defmethod channel /allocate-order :tata-cliq [channel-id channel-config ]
27+ (prn channel-id " ~~>" channel-config ))
You can’t perform that action at this time.
0 commit comments