Execute Watch API
editExecute Watch API
editThe execute watch API allows clients to immediately execute a watch, either one that has been previously added via the Put Watch API or inline as part of the request.
Execute by id
editSubmit the following request to execute a previously added watch:
ExecuteWatchRequest request = ExecuteWatchRequest.byId("my_watch_id"); request.setAlternativeInput("{ \"foo\" : \"bar\" }"); request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); request.setRecordExecution(true); request.setIgnoreCondition(true); request.setTriggerData("{\"triggered_time\":\"now\"}"); request.setDebug(true); ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT);
Execute by id Response
editThe returned Response
contains details of the execution:
Asynchronous execution by id
editThis request can be executed asynchronously:
The asynchronous method does not block and returns immediately. Once it is
completed the ActionListener
is called back using the onResponse
method
if the execution successfully completed or using the onFailure
method if
it failed.
A typical listener for ExecuteWatchResponse
looks like:
Execute inline
editSubmit the following request to execute a watch defined as part of the request:
String watchJson = "{ \n" + " \"trigger\": { \"schedule\": { \"interval\": \"10h\" } },\n" + " \"input\": { \"none\": {} },\n" + " \"actions\": { \"logme\": { \"logging\": { \"text\": \"{{ctx.payload}}\" } } }\n" + "}"; ExecuteWatchRequest request = ExecuteWatchRequest.inline(watchJson); request.setAlternativeInput("{ \"foo\" : \"bar\" }"); request.setActionMode("action1", ExecuteWatchRequest.ActionExecutionMode.SIMULATE); request.setIgnoreCondition(true); request.setTriggerData("{\"triggered_time\":\"now\"}"); request.setDebug(true); ExecuteWatchResponse response = client.watcher().executeWatch(request, RequestOptions.DEFAULT);
Alternative input for the watch to use in json format |
|
Set the mode for action "action1" to SIMULATE |
|
Execute the watch regardless of the watch’s condition |
|
Set the trigger data for the watch in json format |
|
Enable debug mode |
Note that inline watches cannot be recorded.
The response format and asynchronous execution methods are the same as for the Execute Watch by ID API.