Skip to content

Commit 11d58d6

Browse files
committed
automatically upgrade json jobs
1 parent 83f8beb commit 11d58d6

4 files changed

Lines changed: 36 additions & 26 deletions

File tree

src/cli/com/yetanalytics/xapipe/cli/options.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@
149149
[nil "--delete-job ID" "Delete the job specified and exit."]
150150
["-f" "--force-resume" "If resuming a job, clear any errors and force it to resume."
151151
:default false]
152-
[nil "--json JSON" "Take a job specification as a JSON string"
152+
[nil "--json JSON" "Take a job specification as a JSON string (automatically upgrades old jobs)"
153153
:parse-fn job-json/json->job]
154-
[nil "--json-file FILE" "Take a job specification from a JSON file"
154+
[nil "--json-file FILE" "Take a job specification from a JSON file (automatically upgrades old jobs)"
155155
:parse-fn (fn [filepath]
156156
(-> filepath
157157
slurp
158158
job-json/json->job))]
159159
[nil "--json-out FILE" "Write JOB to a JSON file"]
160-
[nil "--[no-]upgrade" "Automatically upgrade jobs to the latest version"
160+
[nil "--[no-]upgrade" "Automatically upgrade jobs started from storage to the latest version (jobs started from JSON will always be upgraded)"
161161
:id :upgrade-jobs
162162
:default true]]
163163
(concat storage-options

src/lib/com/yetanalytics/xapipe/job.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
(s/def ::config config/config-spec)
1515
(s/def ::state state/state-spec)
16-
(s/def ::version #{0 current-version})
16+
(s/def ::version #{current-version})
1717
(s/def ::id (s/and string? not-empty))
1818

1919
(defn valid-get-params-vs-state?

src/lib/com/yetanalytics/xapipe/job/config.clj

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
poll-interval :poll-interval
7070
{?since :since
7171
?until :until} :get-params
72+
get-req-config :request-config
7273
:as source-config
7374
:or {get-batch-size 50
7475
get-backoff-opts {:budget 10000
@@ -77,6 +78,7 @@
7778
:source
7879
{post-batch-size :batch-size
7980
post-backoff-opts :backoff-opts
81+
post-req-config :request-config
8082
:as target-config
8183
:or {post-backoff-opts {:budget 10000
8284
:max-attempt 10}}}
@@ -108,27 +110,32 @@
108110
cleanup-buffer-size
109111
(or cleanup-buffer-size
110112
get-batch-size
111-
0)]
112-
{:get-buffer-size get-buffer-size
113-
:statement-buffer-size statement-buffer-size
114-
:batch-buffer-size batch-buffer-size
115-
:batch-timeout batch-timeout
116-
:cleanup-buffer-size cleanup-buffer-size
117-
:source
118-
(-> source-config
119-
(assoc :batch-size get-batch-size
120-
:backoff-opts get-backoff-opts
121-
:poll-interval poll-interval)
122-
(assoc-in [:get-params :limit] get-batch-size)
123-
(cond->
124-
?since (update-in [:get-params :since] t/normalize-stamp)
125-
?until (update-in [:get-params :until] t/normalize-stamp)))
126-
:target
127-
(assoc target-config
128-
:batch-size post-batch-size
129-
:backoff-opts post-backoff-opts)
130-
:filter
131-
(or filter-config {})}))
113+
0)
114+
source-version (get get-req-config :xapi-version "1.0.3")
115+
target-version (get post-req-config :xapi-version "1.0.3")]
116+
(->
117+
{:get-buffer-size get-buffer-size
118+
:statement-buffer-size statement-buffer-size
119+
:batch-buffer-size batch-buffer-size
120+
:batch-timeout batch-timeout
121+
:cleanup-buffer-size cleanup-buffer-size
122+
:source
123+
(-> source-config
124+
(assoc :batch-size get-batch-size
125+
:backoff-opts get-backoff-opts
126+
:poll-interval poll-interval)
127+
(assoc-in [:get-params :limit] get-batch-size)
128+
(cond->
129+
?since (update-in [:get-params :since] t/normalize-stamp)
130+
?until (update-in [:get-params :until] t/normalize-stamp)))
131+
:target
132+
(assoc target-config
133+
:batch-size post-batch-size
134+
:backoff-opts post-backoff-opts)
135+
:filter
136+
(or filter-config {})}
137+
(assoc-in [:source :request-config :xapi-version] source-version)
138+
(assoc-in [:target :request-config :xapi-version] target-version))))
132139

133140
(s/fdef sanitize-req-cfg
134141
:args (s/cat :rcfg ::client/request-config)

src/lib/com/yetanalytics/xapipe/job/json.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@
9595

9696
(defn json->job
9797
"Parse a job from JSON, possibly updating it to the current version."
98-
[^String json-str]
98+
[^String json-str & {:keys [upgrade]
99+
:or {upgrade true}}]
99100
(-> (json/parse-string json-str (partial keyword nil))
100101
keywordize-status
101102
keywordize-job-error-types
102103
(unpack-paths [[:state :filter :pattern]])
104+
(cond->
105+
upgrade job/upgrade-job)
103106
(update :config config/ensure-defaults)))
104107

105108
(s/def ::pretty boolean?)

0 commit comments

Comments
 (0)