Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a sleep process #8

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
]
Loading