Friday, July 12, 2013

Algorithms.io Now Support Async Calls

We have just released new functionality that allows someone to make an asynchronous call with any of our algorithms via our API.  Prior to this every algorithm’s API call is a synchronous call which means if the algorithms takes 5 minutes to run, the API call will hold the connection for 5 minutes.  This is not ideal in some situation.  This now asynchronous call functionality allows you to run the same algorithm but instead of waiting around for it to finish, the system will return a job id to you and you can use that to query for the status of the job.
Let me show you how this works.  It is not too different from before.
Making an asynchronous call.  The only thing we are changing in the call is the parameter “method” is now set to “async”
curl -X POST \
-d 'method=async' \
-d 'outputType=json' \
-d 'train=3339' \
-d 'test=3340' \
-d 'dependentVariable=closed' \
-H "authToken: <AUTH_TOKEN>" \
https://api.algorithms.io/jobs/swagger/46
 
RETURNS:
[
    {
        "status""SUBMITTED_TO_QUEUE",
        "job_id""4fcb7389fa4c1e3d3caabe506bd360c9"
    }
]
This call will return immediately.  Using the “job_id” you will make a query to checkout the status of this job.
curl -X GET \
-H "authToken: <AUTH_TOKEN>" \
https://api.algorithms.io/jobs/id/4fcb7389fa4c1e3d3caabe506bd360c9
RETURN:
{
    "status""COMPLETED",
    "additional_info": {
        "final": {
            "output": {
                "datasource_id_seq"3663
            }
        }
    },
    "datasource": {
        "id""3663"
    },
    "created": {
        "date""2013-07-09 22:20:29",
        "timezone_type"3,
        "timezone""America/Los_Angeles"
    },
    "last_modified": {
        "date""2013-07-09 22:20:29",
        "timezone_type"3,
        "timezone""America/Los_Angeles"
    }
}
The status will be in various states depending on the algorithm.  There is one final state “ERROR” or “COMPLETED”.  Once you see this, it is the final output.  The results from the algorithm is placed into a datasource for you.  The datasource id can be found in two places in the query job return.  Both will have the same ID.
Thats about it.  Making asynchronous calls easy!