Skip to content

Commit

Permalink
Merge pull request #22 from bird-house/issue-3-add-sleep-process
Browse files Browse the repository at this point in the history
add sleep process (#3)
  • Loading branch information
cehbrecht authored May 18, 2018
2 parents bd606f1 + b0b449b commit 8534cd6
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 2 deletions.
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

0 comments on commit 8534cd6

Please sign in to comment.