Skip to content

Instantly share code, notes, and snippets.

@hugoduncan
Created April 9, 2014 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugoduncan/10300831 to your computer and use it in GitHub Desktop.
Save hugoduncan/10300831 to your computer and use it in GitHub Desktop.
pallet use-async api example
(ns pallet.api-examples.plan
"Examples of pallet's plan api"
(:refer-clojure :exclude [sync])
(:require
[pallet.actions :refer [exec-script*]]
[pallet.core.executor.ssh :refer [ssh-executor]]
[pallet.plan :refer [execute-plan execute-plans plan-fn]]
[pallet.session :as session :refer [set-user]]
[pallet.user :refer [default-user]]
[pallet.utils.async :refer [sync]]))
(defn ls-on-localhost
"Execute a 'ls' on localhost."
[]
(let [localhost {:id "localhost" :primary-ip "127.0.0.1"
;; Adjust these appropriately
:os-family :darwin :packager :brew}
session (-> (session/create {:executor (ssh-executor)})
(set-user (default-user)))
f (plan-fn [session]
(exec-script* session "ls"))]
;; Use synchronous execution of a single plan function.
(execute-plan session localhost f)
;; Use async execution, which allows running plan functions on
;; multiple targets in parallel.
(sync (execute-plans session [{:target localhost :plan-fn f}]))))
@tbatchelli
Copy link

(ns pallet.api-examples.plan
  "Examples of pallet's plan api"
  (:refer-clojure :exclude [sync])
  (:require
   [pallet.actions :refer [exec-script*]]
   [pallet.core.executor.ssh :refer [ssh-executor]]
   [pallet.plan :refer [execute-plan execute-plans plan-fn]]
   [pallet.session :as session :refer [set-user]]
   [pallet.user :refer [default-user]]
   [pallet.utils.async :refer [sync]]))

(defn ls-on-localhost
  "Execute a 'ls' on localhost."
  []
  (let [localhost {:id "localhost" :primary-ip "127.0.0.1"
                   ;; Adjust these appropriately
                   :os-family :darwin :packager :brew}
        session (-> (session/create {:executor (ssh-executor)})
                    (set-user (default-user)))
        f (plan-fn [session]
            (exec-script* session "ls"))]
    ;; sync version
    (execute-plan session localhost f)
    ;; async version 
    (sync (execute-plans session [{:target localhost :plan-fn f}]))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment