-
Notifications
You must be signed in to change notification settings - Fork 0
Add cancel endpoint, R progress monitor, and upgrade PyWPS #68
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
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
412ca17
Use PyWPS 4.6.0, .references for OPeNDAP inputs
QSparks 01fb841
Handle OPeNDAP vs. local data in select_args util
QSparks 1fe48fb
Revert select_args_from_input_list
QSparks ebf3b0f
extract .data if it exists in select_args_from_input_list
QSparks af6a5cb
Revert .data extract, add logging
QSparks fcb7a19
Use as_reference for ComplexInput
QSparks 2ac6641
Black
QSparks 0d2c00d
Revet as_reference usage
QSparks 6dd6276
Test OPeNDAP input fix
QSparks f2e5efa
Revert test OPeNDAP input fix
QSparks a7abef7
Log wps_CI inputs
QSparks 022eb8d
Test set gcm and obs files to href
QSparks 75b86aa
Test override collect_args for gcm and obs files
QSparks 5153ba4
Remove as_reference to allow container starts
QSparks 9d98fd9
Use updated wps_tools
QSparks 76f9aa7
Install git in Dockerfile
QSparks 9a82fc0
Use python3.9 required by wps_tools
QSparks 68e789f
Use nchelpers v5.5.11
QSparks 526ab0c
Add fine-grained progress steps
QSparks d1358bf
Use wps-tools v2.1.2 on pypi
QSparks 07d19ff
Add cancellation process
QSparks ae822a3
Add check for failed status
QSparks 3ec8557
SIGTERM target process in wps_cancel
QSparks 58eeed0
Revert sigterm calls in wps_cancel
QSparks 961acb2
Move WPS cancellation to a separate endpoint
QSparks b2d796f
Add logging to wsgi.py
QSparks ba06924
Prevent updates after cancellation
QSparks 13445d4
Update in-memory status on cancel
QSparks c48d21a
Add graceful termination on cancel
QSparks 91c72c6
Check running before cancel
QSparks aaa5409
Add sqlite3 to Dockerfile, adjust wps.cfg.template
QSparks e8bc5be
Launch next process on cancel
QSparks 03d05e7
Revert launch next process on cancel
QSparks 38aaa30
replace os.kill with safe cancel using psutil and signal
QSparks d858320
Remove timeout check and allow DB-based self-cancel
QSparks 1964167
Test cooperative cancel with os.kill in R callback
QSparks 7db6642
Revert to OS-level process termination
QSparks 14ba2df
Set DB status when process is failed
QSparks 1828690
Track response objects to enable cleanup
QSparks 2f24a06
Use response.uuid for tracking
QSparks ee8d760
Include response cleanup on failure
QSparks e7a08bc
Include cleanup on in-response failure
QSparks eede1ec
Add cancel_process.md
QSparks 0aa396b
First cut fixing CI
QSparks 31c7a4b
Install r-base in python-ci
QSparks fd3123a
CI Fix
QSparks f9c26aa
Use tagged wps-tools v2.1.3
QSparks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
| import json | ||
| import os | ||
| import signal | ||
| from pywps.dblog import store_status, get_session, ProcessInstance | ||
| from pywps.response.status import WPS_STATUS | ||
| from chickadee.response_tracker import get_response | ||
|
|
||
|
|
||
| def handle_cancel(environ, start_response): | ||
| def error(msg, code): | ||
| return _simple_json_response(start_response, {"error": msg}, code) | ||
|
|
||
| if environ["REQUEST_METHOD"].upper() != "POST": | ||
| return error("Method not allowed, use POST", "405 Method Not Allowed") | ||
|
|
||
| content_length = int(environ.get("CONTENT_LENGTH") or 0) | ||
| try: | ||
| body = environ["wsgi.input"].read(content_length) | ||
| data = json.loads(body.decode("utf-8")) | ||
| except (json.JSONDecodeError, UnicodeDecodeError): | ||
| return error("Invalid JSON", "400 Bad Request") | ||
|
|
||
| process_uuid = data.get("uuid") | ||
| if not process_uuid: | ||
| return error("Missing 'uuid' in request body", "400 Bad Request") | ||
|
|
||
| session = get_session() | ||
| try: | ||
| process = session.query(ProcessInstance).filter_by(uuid=process_uuid).first() | ||
| if not process or not process.pid: | ||
| return error("Process UUID not found or no PID recorded.", "404 Not Found") | ||
|
|
||
| pid = process.pid | ||
| try: | ||
| response = get_response(process_uuid) | ||
|
|
||
| if process.status in {WPS_STATUS.STARTED, WPS_STATUS.PAUSED}: | ||
| os.kill(pid, signal.SIGINT) # Graceful termination | ||
| if response: | ||
| response.clean() | ||
| store_status( | ||
| process_uuid, WPS_STATUS.FAILED, "Process cancelled by user", 100 | ||
| ) | ||
| return _simple_json_response( | ||
| start_response, | ||
| {"message": f"Process {process_uuid} (PID {pid}) cancelled."}, | ||
| "200 OK", | ||
| ) | ||
|
|
||
| except ProcessLookupError: | ||
| return error(f"Process {pid} not found.", "404 Not Found") | ||
| except PermissionError: | ||
| return error(f"Permission denied to stop process {pid}.", "403 Forbidden") | ||
|
|
||
| except Exception as e: | ||
| return error(f"Failed to update status: {str(e)}", "500 Internal Server Error") | ||
| finally: | ||
| session.close() | ||
|
|
||
|
|
||
| def _simple_json_response(start_response, data, status="200 OK"): | ||
| body = json.dumps(data).encode("utf-8") | ||
| headers = [ | ||
| ("Content-Type", "application/json; charset=utf-8"), | ||
| ("Content-Length", str(len(body))), | ||
| ] | ||
| start_response(status, headers) | ||
| return [body] | ||
This file contains hidden or 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 hidden or 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 hidden or 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,13 @@ | ||
| response_registry = {} | ||
|
|
||
|
|
||
| def track_response(uuid, response): | ||
| response_registry[uuid] = response | ||
|
|
||
|
|
||
| def get_response(uuid): | ||
| return response_registry.get(uuid) | ||
|
|
||
|
|
||
| def untrack_response(uuid): | ||
| response_registry.pop(uuid, None) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, good error handling 👍