Skip to content

Instantly share code, notes, and snippets.

@pvh
Created August 22, 2011 19:01
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 pvh/1163214 to your computer and use it in GitHub Desktop.
Save pvh/1163214 to your computer and use it in GitHub Desktop.
(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