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

add sleep process (#3) #22

Merged
merged 1 commit into from
May 18, 2018
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
1 change: 1 addition & 0 deletions {{cookiecutter.project_slug}}/tests/test_wps_caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ def test_wps_caps():
'/ows:Identifier')
assert sorted(names.split()) == [
'inout',
'sleep',
'wordcounter']
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/tests/test_wps_inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pywps import Service
from pywps.tests import assert_response_success

from {{ cookiecutter.project_slug }}.tests.common import client_for
from . common import client_for
from {{ cookiecutter.project_slug }}.processes.wps_inout import InOut


Expand Down
18 changes: 18 additions & 0 deletions {{cookiecutter.project_slug}}/tests/test_wps_sleep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

from pywps import Service
from pywps.tests import assert_response_success

from . common import client_for
from {{ cookiecutter.project_slug }}.processes.wps_sleep import Sleep


@pytest.mark.slow
def test_wps_sleep():
client = client_for(Service(processes=[Sleep()]))
datainputs = "deplay=1"
resp = client.get(
service='WPS', request='Execute', version='1.0.0', identifier='sleep',
datainputs=datainputs)
print resp.data
assert_response_success(resp)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pywps import Service
from pywps.tests import assert_response_success

from {{ cookiecutter.project_slug }}.tests.common import client_for
from . common import client_for
from {{ cookiecutter.project_slug }}.processes.wps_wordcounter import WordCounter


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .wps_wordcounter import WordCounter
from .wps_inout import InOut
from .wps_sleep import Sleep

processes = [
WordCounter(),
InOut(),
Sleep(),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from pywps import Process, LiteralInput, LiteralOutput
from pywps.app.Common import Metadata


class Sleep(Process):
def __init__(self):
inputs = [
LiteralInput('delay', 'Delay between every update',
default='10', 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=[
Metadata('PyWPS Demo', 'https://pywps-demo.readthedocs.io/en/latest/'),
],
inputs=inputs,
outputs=outputs,
store_supported=True,
status_supported=True
)

def _handler(self, request, response):
import time

if 'delay' in request.inputs:
sleep_delay = request.inputs['delay'][0].data
else:
sleep_delay = 10

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'

return response