source: trunk/docker/test_long_process.py @ 959

Last change on this file since 959 was 959, checked in by djay, 22 months ago

Add Dockerfile created on #177 providing docker-compose environmeent solving issue reported on #175.

File size: 2.9 KB
Line 
1import argparse
2import requests
3import time
4
5from threading import Thread
6from xml.etree import ElementTree
7
8parser = argparse.ArgumentParser()
9parser.add_argument("threads", help="number of threads", type=int)
10args = parser.parse_args()
11
12
13class LongProcess(Thread):
14    def __init__(self, name):
15        Thread.__init__(self)
16        self.name = name
17        self.progress = None
18        self.location_url = self.launch_long_process()
19        print("INIT %s %s" % (self.name, self.location_url))
20
21    def launch_long_process(self):
22        endpoint_url = "http://localhost/cgi-bin/zoo_loader.cgi"
23        params = dict(
24            request="Execute",
25            service="WPS",
26            version="1.0.0",
27            Identifier="longProcess",
28            DataInputs="a=toto",
29            ResponseDocument="Result",
30            storeExecuteResponse="true",
31            status="true",
32        )
33        r = requests.get(endpoint_url, params=params)
34        root = ElementTree.fromstring(r.content)
35
36        location_url = root.attrib["statusLocation"]
37        return location_url
38
39    def get_progress(self):
40        progress = None
41        r = requests.get(self.location_url)
42        root = ElementTree.fromstring(r.content)
43        ns = dict(wps="http://www.opengis.net/wps/1.0.0")
44        status = root.find("wps:Status", ns)
45        if status:
46            ctime = status.attrib["creationTime"]
47            started = root.find("wps:Status/wps:ProcessStarted", ns)
48            #started = root.find("wps:ProcessStarted", ns)
49            succeeded = root.find("wps:Status/wps:ProcessSucceeded", ns)
50            #succeeded = root.find("wps:ProcessSucceeded", ns)
51            if started is not None and started.attrib["percentCompleted"]:
52                percent = started.attrib["percentCompleted"]
53                progress = int(percent)
54            elif succeeded is not None:
55                progress = 100
56            else:
57                # error?
58                print(r.content.decode())
59                progress = None
60        else:
61            print(r.content.decode())
62            progress = -1
63
64        self.progress = progress
65        return self.progress
66
67    def run(self):
68        print("Thread %s: starting" % self.name)
69        while True:
70            progress = self.get_progress()
71            if progress == 100:
72                print("Thread %s: succeeded" % self.name)
73                break
74            elif progress == -1:
75                print("Thread %s: failed" % self.name)
76                break
77            elif progress is None:
78                print("Thread %s: error" % self.name)
79                break
80            else:
81                print("Thread %s :progress %s" % (self.name, progress))
82            time.sleep(1.0)
83        print("Thread %s: finishing" % self.name)
84
85
86threads = list()
87for i in range(0, args.threads):
88    t = LongProcess(i)
89    t.start()
90    threads.append(t)
91
92for t in threads:
93    t.join()
94
Note: See TracBrowser for help on using the repository browser.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png