function.task executing bulk tasks

Author: Chris Zheng  (z@caudate.me)
Date: 27 November 2018
Repository: https://github.com/zcaudate/hara
Version: 3.0.2

1    Introduction

hara.function.task provides methods for constructing bulk tasks.

1.1    Installation

Add to project.clj dependencies:

[hara/function.task "3.0.2"]

All functions are in the hara.function.task namespace.

 (use (quote hara.function.task))

2    API



Task ^

constructs a invokable Task object

v 3.0
(defexecutive Task
  [type name main construct arglists item result summary]
  {:type    defrecord
   :tag     "task"
   :display task-display
   :invoke  process/invoke
   :status  task-status})
example not found

deftask ^

defines a top level task

v 3.0
(defmacro deftask
  [name config & body]
  (invoke-intern-task :task name config body))
link
(deftask -list-aliases- {:template :namespace :main clojure.core/ns-aliases :item {:post (comp vec sort keys)} :doc "returns all aliases"})

invoke-intern-task ^

creates a form defining a task

v 3.0
(definvoke invoke-intern-task
  [:method {:multi protocol.function/-invoke-intern
            :val :task}]
  ([name config]
   (invoke-intern-task :task name config nil))
  ([_ name config _]
   (let [template (:template config)
         body `(task ~template ~(str name) ~config)
         arglists (or (:arglists config)
                      (-> (task-defaults template) :arglists))
         name (with-meta name (assoc config :arglists (list 'quote arglists)))]
     `(def ~name ~body))))
link
(invoke-intern-task '-task- '{:template :namespace :main {:fn clojure.core/ns-aliases}})

single-function-print ^

if not `:bulk`, then print function output

v 3.0
(defn single-function-print
  [params]
  (if (and (not (:bulk params))
           (-> params :print :function nil?))
    (assoc-in params [:print :function] true)
    params))
link
(single-function-print {}) => {:print {:function true}}

task ^

creates a task

v 3.0
(defn task
  ([m]
   (map->Task m))
  ([type name arg]
   (let [[params main] (if (map? arg)
                         [arg (-> arg :main :fn)]
                         [{} arg])
         defaults     (task-defaults type)
         params       (nested/merge-nested defaults params)
         count        (or (-> params :main :argcount) 4)
         [main args?] (process/main-function main count)]
     (task (nested/merge-nested defaults
                                params
                                {:main {:fn main
                                        :args? args?}
                                 :name name
                                 :type type})))))
link
(task :namespace "list-interns" ns-interns) (task :namespace "list-interns" {:main {:fn clojure.core/ns-interns}})

task-defaults ^

creates default settings for task groups

v 3.0
(defmulti task-defaults
  identity)
link
(task-defaults :namespace) ;;(task-defaults :project)

task-display ^

displays the task-body

v 3.0
(defn task-display
  [^Task task]
  {:fn (symbol (.name task))})
example not found

task-status ^

displays the task-status

v 3.0
(defn task-status
  [^Task task]
  (.type task))
example not found

task? ^

check if object is a task

v 3.0
(defn task?
  [x]
  (instance? Task x))
link
(-> (task :namespace "list-interns" ns-interns) (task?)) => true