Jam.py documentation


on_ext_request(task, request, params)

domain: server

language: python

class Task class


Use on_ext_request to send a request to the server for processing.

The task parameter is a reference to the task tree The request is a string that must starts with ‘/ext’ There could be a list of parameters.


The following application will send every 60 seconds a request to the server of Demo application

#!/usr/bin/env python

    # For Python 3.0 and later
    from urllib.request import urlopen
except ImportError:
    # Fall back to Python 2's urllib2
    from urllib2 import urlopen
import json
import time

def send(url, request, params):
    a = urlopen(url + '/' + request, data=str.encode(json.dumps(params)))
    r = json.loads(a.read().decode())
    return r['result']['data']

if __name__ == '__main__':
    url = ''
    while True:
        result = send(url, 'get_sum', [1, 2, 3])

The server will process this request and return the sum of parameters. The on_ext_request must be declared in task server module:

def on_ext_request(task, request, params):
    #print request, params
    reqs = request.split('/')
    if reqs[2] == 'get_sum':
        return params[0] + params[1] + params[2]