Created
August 22, 2011 19:01
-
-
Save pvh/1163214 to your computer and use it in GitHub Desktop.
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 states.core) | |
(def resource-transitions | |
{:create | |
[{:condition #(= (% :ec2-state "pending")) | |
:transition :booting}, | |
{:condition #(> (* 10 60) (% :created_at050)) | |
:transition :failed}] | |
:booting | |
[{:condition #(= (% :ssh) "online") | |
:transition :online}] | |
:online | |
[{:condition #(= (% :ssh) "offline") | |
:transition :offline}] | |
:offline | |
[{:condition #(= (% :ssh) "online") | |
:transition :online}] | |
}) | |
(def the-resource ^{:transitions resource-transitions} | |
{:state :create | |
:ec2-state "pending" | |
:ssh "offline" | |
}) | |
(defn first-valid-transition [stateful transitions] | |
(let [conditions (transitions :conditions)] | |
(first conditions)) | |
) | |
(defn update-state [stateful] | |
(let [current-transitions (((meta stateful) :transitions) (stateful :state)) | |
transition (first-valid-transition stateful current-transitions)] | |
() ) | |
) | |
;(defn tick [it] ((states it) it)) | |
(def data {:state :start :finished 0}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment