forked from audreyfeldroy/cookiecutter-pypackage
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from bird-house/issue-3-add-sleep-process
add sleep process (#3)
- Loading branch information
Showing
6 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ def test_wps_caps(): | |
'/ows:Identifier') | ||
assert sorted(names.split()) == [ | ||
'inout', | ||
'sleep', | ||
'wordcounter'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
] |
51 changes: 51 additions & 0 deletions
51
{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/processes/wps_sleep.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |