Skip to content

Commit

Permalink
added a sleep process
Browse files Browse the repository at this point in the history
  • Loading branch information
cehbrecht committed Feb 21, 2024
1 parent d5645ab commit dd88e15
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 7 deletions.
2 changes: 2 additions & 0 deletions albatross/processes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .wps_say_hello import SayHello
from .wps_sleep import Sleep
from .wps_drought import Drought

processes = [
SayHello(),
Drought(),
Sleep(),
]
61 changes: 61 additions & 0 deletions albatross/processes/wps_sleep.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions tests/test_wps_caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]

0 comments on commit dd88e15

Please sign in to comment.