Skip to content

Instantly share code, notes, and snippets.

@eraserhd
Created October 26, 2020 15:14
Show Gist options
  • Save eraserhd/a60250281e9d47743e9021ccd1337bca to your computer and use it in GitHub Desktop.
Save eraserhd/a60250281e9d47743e9021ccd1337bca to your computer and use it in GitHub Desktop.
;; I? Input satisfied?
;; O? Output satisfied?
;; RR? Requires release?
;; HR? Has release?
;;
(def status-table
;; # I? O? RR? HR? | Status
;; --- -- -- -- -- | ------
'[[ 0 N N N N :| "UNAVAILABLE"]
[ 1 Y N N N :| "AVAILABLE"]
[ 2 N Y N N :| "FINISHED"] ; (1)
[ 3 Y Y N N :| "FINISHED"]
[ 4 N N Y N :| "UNAVAILABLE"]
[ 5 Y N Y N :| "HELD"]
[ 6 N Y Y N :| "HELD"] ; (2)
[ 7 Y Y Y N :| "HELD"]
[ 8 N N N Y :| "UNAVAILABLE"] ; }
[ 9 Y N N Y :| "AVAILABLE"] ; } Could happen if redeploy w/o RR?
[10 N Y N Y :| "FINISHED"] ; (1) }
[11 Y Y N Y :| "FINISHED"] ; }
[12 N N Y Y :| "UNAVAILABLE"]
[13 Y N Y Y :| "AVAILABLE"]
[14 N Y Y Y :| "FINISHED"] ; (1)
[15 Y Y Y Y :| "FINISHED"]])
;; Notes:
;; (1) We can finish a task before it is available. This should help in
;; making post-goals tasks less cluttered if we already have the data for
;; a goal.
;; (2) We mark a task as held if it has output satisfied but not input
;; satisfied because releasing will cause it to finish, and we don't want
;; to go , so the user is aware that releasing will do something.
(def ^:private status-table-lookup
(into {}
(map (fn [[_ I? O? RR? HR? _ status]]
[[(= I? 'Y) (= O? 'Y) (= RR? 'Y) (= HR? 'Y)] status]))
status-table))
(defrule taskexec-status
{:salience -20001}
[EAV (= e ?taskexec) (= a :taskexec/def) (= v ?taskdef)]
[EAV (= e ?taskexec) (= a :taskexec/uuid) (= v ?uuid)]
[:not [EAV (= e ?taskdef) (= a :taskdef/subtasks)]]
[?I <- (acc/count) :from [EAV (= e ?taskexec) (= a :taskexec/input-satisfied?) (= v true)]]
[?O <- (acc/count) :from [EAV (= e ?taskexec) (= a :taskexec/output-satisfied?) (= v true)]]
[?RR <- (acc/count) :from [EAV (= e ?taskdef) (= a :taskdef/requires-release) (= v true)]]
[?HR <- (acc/count) :from [EAV (= a :task-release/exec-uuid) (= v ?uuid)]]
=>
(let [I? (not (zero? ?I))
O? (not (zero? ?O))
RR? (not (zero? ?RR))
HR? (not (zero? ?HR))
status (get @#'status-table-lookup [I? O? RR? HR?])]
(synthesize! ?taskexec :taskexec/status status)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment