Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Adds support for including custom executor jobs in /jobs #756

Merged
merged 12 commits into from
Mar 21, 2018

Conversation

dposada
Copy link
Contributor

@dposada dposada commented Mar 9, 2018

Changes proposed in this PR

  • adding the ability to list jobs on /jobs
  • /jobs will not filter out custom executor jobs

Why are we making these changes?

We want to give users and tools the option of including custom executor jobs when listing (while maintaining backwards compatibility).

@dposada dposada removed the wip label Mar 9, 2018
@dposada dposada requested a review from shamsimam March 9, 2018 04:55
Copy link
Contributor

@DaoWen DaoWen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to update the /list endpoint later?

@@ -2041,7 +2040,8 @@
::start-ms (parse-long-default start-ms nil)
::limit (parse-int-default limit Integer/MAX_VALUE)
::end-ms (parse-long-default end-ms (System/currentTimeMillis))
::name-filter-fn (name-filter-str->name-filter-fn name)}]
::name-filter-fn (name-filter-str->name-filter-fn name)
::include-custom-executor? (Boolean/parseBoolean include-custom-executor)}]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: It's probably better to use Boolean/valueOf here so as to avoid the implicit auto-boxing. (valueOf returns a Boolean object, whereas parseBoolean returns a boolean primitive).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(take-while #(and (< (:e %) entid-end)
(= (:a %) job-user-entid)
(= (:v %) user)))
(map #(:e %))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

η-reduction! (map #(:e %))(map :e)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(filter #(< (.getTime (:job/submit-time %)) (.getTime end)))
(filter #(= state-keyword (:job/state %))))]
(cond->> jobs
(not include-custom-executor?) (filter #(not (:job/custom-executor %))))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was carried over from the old code, but can we change the (filter #(not (:job/custom-executor %)) to (remove :job/custom-executor)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dposada
Copy link
Contributor Author

dposada commented Mar 9, 2018

@DaoWen

Are you planning to update the /list endpoint later?

I don't understand the question -- this PR does update the /list endpoint

@@ -2015,8 +2015,7 @@
:malformed? (fn [ctx]
;; since-hours-ago is included for backwards compatibility but is deprecated
;; please use start-ms and end-ms instead
(let [{:keys [state user since-hours-ago start-ms end-ms limit name]
:as params}
(let [{:keys [state user since-hours-ago start-ms end-ms limit name include-custom-executor]}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: lexicographic order

@DaoWen
Copy link
Contributor

DaoWen commented Mar 9, 2018

I didn't see any swagger updates, so I assumed you hadn't touched the actual endpoint. I didn't realize that it doesn't have any swagger annotations (#307). 😢

I guess that's another thing to fix whenever we get around to fixing our outdated swagger docs.

@dposada dposada changed the title Adds support for including custom executor jobs in /list Adds support for including custom executor jobs in /jobs Mar 12, 2018
Copy link
Contributor

@shamsimam shamsimam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completed my pass, added some comments.

(set/difference states util/instance-states)
(if (set/superset? states util/instance-states)
(-> states (set/difference util/instance-states) (conj "completed"))
states)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be easier to read:

(def terminal states #{"completed" "failed" "success"})
...
(if (some states terminal-states)
  (-> states (set/difference terminal-states) (conj "completed"))
  states)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the current (and desired) behavior:

(api/normalize-list-states #{"success" "failed" "completed"})
=> #{"completed"}
(api/normalize-list-states #{"success" "failed"})
=> #{"completed"}
(api/normalize-list-states #{"success"})
=> #{"success"}
(api/normalize-list-states #{"failed"})
=> #{"failed"}
(api/normalize-list-states #{"completed"})
=> #{"completed"}

I don't think your suggestion will have the same results when states is #{"success"}, for example.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay

(-> states (set/difference util/instance-states) (conj "completed"))
states)))

(defn parse-time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong in util?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(or (tf/parse s)
(tc/from-long (Long/parseLong s))))

(defn- parse-int-default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong in util?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(let [pattern (name-filter-str->name-filter-pattern name)]
#(re-matches pattern %))))

(defn job-list-request-malformed?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are start and end required parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(is (= 201 (:status response-1)))
(is (= 2 (count jobs)))
(is (= (:uuid response-2) (-> jobs first (get "uuid"))))
(is (= (:uuid response-1) (-> jobs second (get "uuid"))))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we assert on the :job/custom-executor flags of the two jobs also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

(filter #(< (.getTime (:job/submit-time %)) (.getTime end)))
(filter #(= state-keyword (:job/state %))))]
(cond->> jobs
(not include-custom-executor?) (remove :job/custom-executor))))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If include custom-exector jobs, do you need to check the commit-latch to avoid returning uncommitted jobs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, this is done now

@dposada
Copy link
Contributor Author

dposada commented Mar 21, 2018

@shamsimam @sradack Any additional feedback on this?

@dposada
Copy link
Contributor Author

dposada commented Mar 21, 2018

Can we merge?

dposada added a commit to dposada/Cook that referenced this pull request Nov 1, 2018
* Adds support for including custom executor jobs in /list

* Fixes broken unit tests

* Addresses feedback from code review

* Adds support for listing jobs with /jobs

* Feedback from code review

* Removes uncommitted jobs from results

* Fixes the filtering for non-custom-executor jobs

* Marks test_kill_task_terminate_with_sigterm as xfail

* Adds missing import
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants