Documentation | NodeHandler | Commands | every
every: Periodically Run Code Block
This command run the code inside a block at a regular interval as long as the block returns true. The first argument is a name used primarily in debugging messages. The second argument is the time interval in seconds, and the third is an optional, initial value given to the block when it is called for the first time. On subsequent calls, the return value of the previous call is passed instead. This allows for context being maintained across invocations. If the block returns 'nil' no further invocations will be scheduled. So please ensure to return a non-nil value to keep this command alive.
Syntax
every(name, interval = 60, initialValue = nil) {|context|}
- name: A name used in debugging messages.
- interval: Time between checks in seconds.
- initialValue: Optional value passed to first invocation.
- context: Context across invocation. Will be initialValue first, return of previous for all following.
Usage
# Report every 10 seconds the number of nodes still down # every('checkDownNodes', 10) { count = allNodes.inject(0) { |i, node| i += 1 if !node.isUp } info "#{count} node(s) still down." if count > 0 true if count > 0 # Stop if all up }