Changes between Initial Version and Version 1 of Old/NodeHandler/Commands/every


Ignore:
Timestamp:
Apr 14, 2006, 6:32:31 AM (19 years ago)
Author:
max
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Old/NodeHandler/Commands/every

    v1 v1  
     1[wiki:Documentation]
     2| [wiki:Documentation/NodeHandler NodeHandler]
     3| [wiki:Documentation/NodeHandler/Commands Commands]
     4| every
     5
     6
     7= every: Periodically Run Code Block =
     8
     9This 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.
     10
     11
     12== Syntax ==
     13'''every(''name, interval = 60, initialValue = nil'') {|''context''|}'''
     14
     15
     16  * '''name''': A name used in debugging messages.
     17  * '''interval''': Time between checks in seconds.
     18  * '''initialValue''': Optional value passed to first invocation.
     19  * '''context''': Context across invocation. Will be initialValue first, return of previous for all following.
     20
     21== Usage ==
     22
     23{{{
     24# Report every 10 seconds the number of nodes still down
     25#
     26every('checkDownNodes', 10) {
     27  count = allNodes.inject(0) { |i, node|
     28    i += 1 if !node.isUp
     29  }
     30  info "#{count} node(s) still down." if count > 0
     31  true if count > 0  # Stop if all up
     32}
     33}}}
     34
     35== See Also ==
     36
     37[wiki:Documentation/NodeHandler/Commands/defProperty defProperty]