Skip to content

Interval

Piotr Gankiewicz edited this page Jul 6, 2016 · 4 revisions

Interval defines the period after which the Watcher will execute its check (invoke ExecuteAsync() method to be specific). Each Watcher may have its own interval. For example, you might want to check a website availability every 500 ms, while the database should respond only every 10 seconds and so on.

This is where the interval configuration comes in handy - you are able to define a custom interval for each of the Watchers independently via available method overloads (including generic AddWatcher() and all of the available extension methods like AddWebWatcher() etc.) that takes an optional parameter named interval being of type TimeSpan. You can also leave it as it is (5 seconds interval by default) or use the WithInterval() function to set a common interval for all of the Watcher.

Interval is strictly related to the concept of an iteration, which is a single cycle that executes all of checks and returns a collection of results which is available to consume via the OnIterationCompleted() hook.

So what happens when you have defined a set of different intervals? In order to complete a single iteration it is required to invoke ExecuteAsync() at least once for each one Watcher. It means that iteration will take as much time as the longest interval value.

Please consider the following example:

  • Web Watcher - 200 ms interval.
  • Port Watcher - 500 ms interval.
  • MSSQL Watcher - 5 s interval.

The iteration cycle will take 5 seconds to complete, due to the MSSQL Watcher having the longest interval. As a result of an iteration, you may expect 25 checks (25 * 200 ms) for the Web Watcher, 10 checks (10 * 500 ms) for the Port Watcher and a single check for the MSSQL Watcher.

Example of configuring the interval via the generic AddWatcher() method:

var wardenConfiguration = WardenConfiguration
    .Create()
    .AddWatcher(watcher, interval: TimeSpan.FromMilliseconds(500)
    //Configure other watchers, hooks etc.

Example of configuring the interval via one of the available extension methods:

var wardenConfiguration = WardenConfiguration
    .Create()
    .AddWebWatcher("http://httpstat.us/200", interval: TimeSpan.FromMilliseconds(500))
    //Configure other watchers, hooks etc.
Clone this wiki locally