Skip to main content

HTTP Poll

HTTP Poll task is used to invoke HTTP API endpoints until the specified condition matches.

Definitions

   {
"name": "http_poll",
"taskReferenceName": "http_poll_ref",
"type": "HTTP_POLL",
"inputParameters": {
"http_request": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"accept": "application/json",
"contentType": "application/json",
"terminationCondition": "(function(){ return $.output.response.body.randomInt > 10;})();",
"pollingInterval": "60",
"pollingStrategy": "FIXED",
"encode": true,
"headers": {
"Cache-Control": "${workflow.input.cache.control}"
},
"body": {
"key": "value"
}
}
},
"cacheConfig": {
"ttlInSecond": 2000,
"key": "cache-key"
},
"optional": false
}

Input Parameters

AttributeDescription
uriProvide the URI for the service. It can be a partial value when using vipAddress or it can be the server address.
methodChoose the HTTP method. Conductor supports the methods: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, and TRACE.
acceptProvide the accept header as required by the server. The supported types are:
  • application/java-archive
  • application/EDI-X12
  • application/EDIFACT
  • application/javascript
  • application/octet-stream
  • application/ogg
  • application/pdf
  • application/xhtml+xml
  • application/x-shockwave-flash
  • application/json
  • application/ld+json
  • application/xml
  • application/zip
  • application/x-www-form-urlencoded
  • audio/mpeg
  • audio/x-ms-wma
  • audio/vnd.rn-realaudio
  • audio/x-wav
  • image/gif
  • image/jpeg
  • image/png
  • image/tiff
  • image/vnd.microsoft.icon
  • image/x-icon
  • image/vnd.djvu
  • image/svg+xml
By default, it is set to application/json. You can also pass any other headers as variables.
contentTypeProvide the content type for the server. The supported types are:
  • application/java-archive
  • application/EDI-X12
  • application/EDIFACT
  • application/javascript
  • application/octet-stream
  • application/ogg
  • application/pdf
  • application/xhtml+xml
  • application/x-shockwave-flash
  • application/json
  • application/ld+json
  • application/xml
  • application/zip
  • application/x-www-form-urlencoded
  • audio/mpeg
  • audio/x-ms-wma
  • audio/vnd.rn-realaudio
  • audio/x-wav
  • image/gif
  • image/jpeg
  • image/png
  • image/tiff
  • image/vnd.microsoft.icon
  • image/x-icon
  • image/vnd.djvu
  • image/svg+xml
By default, it is set to application/json. You can also pass this parameter as a variable.
terminationConditionSpecifies the condition to be evaluated after every HTTP API invocation. If the condition is evaluated as true, the task will be marked as completed. On the other hand, if the condition is evaluated as false, Conductor will schedule the next poll according to the configurations (pollingInterval & pollingStrategy).
While writing the termination condition,
  • It can be passed as parameters.
  • To use the current http poll as input to the condition, a $ needs to be prefixed. For example, $.output.status. Similarly, previous tasks' output can be referred to using $.task_ref_name.output.
An example termination condition is as follows:(function(){ return $.output.response.body.randomInt > 10;})();
pollingIntervalSpecify the time duration in seconds between each HTTP invocation. By default, the value is set to 60.
pollingStrategyChoose the required polling strategy. It can take any of the following values:
  • FIXED - The duration between each HTTP API invocation will be fixed.
  • LINEAR_BACKOFF - The duration between each HTTP API invocation will be calculated by multiplying the poll count with pollingInterval. Note that the poll count is the incremental value based on each invocation.
  • EXPONENTIAL_BACKOFF - The duration between each HTTP API invocation will be calculated by multiplying the poll count by 2 base exponentials of the polling interval.
By default, the value is set to FIXED.
headersA map of additional HTTP headers to be sent along with the request. The supported types are:
  • Accept-Language
  • Authorization
  • Cache Control
  • Content-MD5
  • From
  • If-Match
  • If-Modified-Since
  • If-None-Match
  • Max-Forwards
  • Pragma
  • If-Range
  • If-Unmodified-Since
  • Proxy-Authorization
  • Range
  • Warning
  • x-api-key
  • Accept-Charset
  • Accept-Encoding
  • Accept-Control-Request-Headers
  • Accept-Control-Request-Method
  • Content-Transfer-Encoding
  • Expect
  • Transfer-Encoding
  • Trailer
bodyRequest body when using POST, PUT, or PATCH. It can be added as text ("body": "text") or parameters such as string, number, boolean, null, or object/array.
encodeDetermines whether the URI needs encoding. When set to true (the default), the Conductor will automatically encode the query parameters before sending the HTTP request.

Set this to false if the URI is already encoded. In this case, the Conductor will assume the query parameters are properly encoded and pass them to the HTTP endpoint as specified in the URI.
cacheConfigEnabling this option allows saving the cache output of the task. On enabling, you can provide the following parameters:
optionalEnabling this option renders the task optional. The workflow continues unaffected by the task's outcome, whether it fails or remains incomplete.

Output Parameters

AttributeDescription
responseA JSON object representing the response, if present.
headersAn object containing the metadata about the response.
statusCodeReturns the HTTP status code indicating the success or failure of the request.
reasonPhraseReturns the reason phrase associated with the HTTP status code.
bodyReturns the body of the response containing the actual data returned by the API.

Examples



  1. Add task type HTTP Poll.
  2. Configure polling endpoint, interval, strategy, and termination condition.

Adding HTTP Poll Task

Sample Workflow

Let’s see a sample workflow:

    {
"name": "your_workflow_name",
"description": "Sample workflow to get started with HTTP POLL task.",
"tasks": [
{
"name": "example",
"taskReferenceName": "example",
"inputParameters": {
"http_request": {
"uri": "https://jsonplaceholder.typicode.com/posts/1",
"method": "GET",
"terminationCondition": "$.output.body.length > 10 ? true : false;",
"pollingInterval": "60",
"pollingStrategy": "FIXED"
}
},
"type": "HTTP_POLL"
}
]
}

So, here, the input parameters for the HTTP Poll task are defined as follows:

      "terminationCondition": "$.output.body.length > 10 ? true : false;",
"pollingInterval": "60",
"pollingStrategy": "FIXED"

Conductor will invoke the HTTP API every 60 seconds until the invoked URI gives the output that is longer than 10 characters.