diff --git a/albatross/processes/__init__.py b/albatross/processes/__init__.py index 5b21298..adb1c59 100644 --- a/albatross/processes/__init__.py +++ b/albatross/processes/__init__.py @@ -1,7 +1,9 @@ from .wps_say_hello import SayHello +from .wps_sleep import Sleep from .wps_drought import Drought processes = [ SayHello(), Drought(), + Sleep(), ] diff --git a/albatross/processes/wps_sleep.py b/albatross/processes/wps_sleep.py new file mode 100644 index 0000000..297ae9d --- /dev/null +++ b/albatross/processes/wps_sleep.py @@ -0,0 +1,61 @@ +from pywps import Process, LiteralInput, LiteralOutput +from pywps.app.Common import Metadata +from pywps.ext_autodoc import MetadataUrl + + +class Sleep(Process): + """A long running process, just sleeping.""" + + def __init__(self): + inputs = [ + LiteralInput( + "delay", "Delay between every update", default="2", data_type="float" + ) + ] + outputs = [LiteralOutput("sleep_output", "Sleep Output", data_type="string")] + + super(Sleep, self).__init__( + self._handler, + identifier="sleep", + version="1.0", + title="Sleep Process", + abstract="Testing a long running process, in the sleep. " + "This process will sleep for a given delay or 10 seconds if not a valid value.", + profile="", + metadata=[ + MetadataUrl( + "User Guide", + "https://emu.readthedocs.io/en/latest/processes.html", + anonymous=True, + ), # noqa + Metadata("PyWPS Demo", "https://pywps-demo.readthedocs.io/en/latest/"), + ], + inputs=inputs, + outputs=outputs, + store_supported=True, + status_supported=True, + ) + + @staticmethod + def _handler(request, response): + import time + + if "delay" in request.inputs: + sleep_delay = request.inputs["delay"][0].data + else: + sleep_delay = 2 + + response.update_status("PyWPS Process started. Waiting...", 0) + time.sleep(sleep_delay) + response.update_status("PyWPS Process started. Waiting...", 20) + time.sleep(sleep_delay) + response.update_status("PyWPS Process started. Waiting...", 40) + time.sleep(sleep_delay) + response.update_status("PyWPS Process started. Waiting...", 60) + time.sleep(sleep_delay) + response.update_status("PyWPS Process started. Waiting...", 80) + time.sleep(sleep_delay) + response.outputs["sleep_output"].data = "done sleeping" + + response.update_status("PyWPS Process completed.", 100) + return response diff --git a/tests/test_wps_caps.py b/tests/test_wps_caps.py index 59a8f55..de6c563 100644 --- a/tests/test_wps_caps.py +++ b/tests/test_wps_caps.py @@ -6,12 +6,12 @@ def test_wps_caps(): client = client_for(Service(processes=processes)) - resp = client.get(service='wps', request='getcapabilities', version='1.0.0') - names = resp.xpath_text('/wps:Capabilities' - '/wps:ProcessOfferings' - '/wps:Process' - '/ows:Identifier') + resp = client.get(service="wps", request="getcapabilities", version="1.0.0") + names = resp.xpath_text( + "/wps:Capabilities" "/wps:ProcessOfferings" "/wps:Process" "/ows:Identifier" + ) assert sorted(names.split()) == [ - 'drought', - 'hello', + "drought", + "hello", + "sleep", ]