Created
April 9, 2014 18:34
-
-
Save hugoduncan/10300831 to your computer and use it in GitHub Desktop.
pallet use-async api example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
commented
Apr 9, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment