-
Notifications
You must be signed in to change notification settings - Fork 299
Add the possibility to send a notification on job completion via web hook #10888
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
Open
ptormene
wants to merge
15
commits into
master
Choose a base branch
from
geocallback
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
83ce852
Add the possibility to call calc_run indicating a callback to run on …
ptormene c83fbec
Merge remote-tracking branch 'origin/master' into geocallback
ptormene 47a1278
Finalize calculation notification via webhook (success or failure) fo…
ptormene bee0e70
Improve docstrings
ptormene 3ac1e45
Merge remote-tracking branch 'origin/master' into geocallback
ptormene 9bc8067
Add to calc_run and calc_run_ini the possibility to specify the 'job_…
ptormene 961de14
Add a test checking the callback when a job is successfully completed
ptormene 259e807
Make notify_job_complete return all the available information (from t…
ptormene fdf3ffd
Extract function wait_for_callback
ptormene ca4f1a2
Merge remote-tracking branch 'origin/master' into geocallback
ptormene 3b69954
Merge remote-tracking branch 'origin/master' into geocallback
ptormene 06799a0
Refactor the test that checks the callback on job complete, so we can…
ptormene 532377b
Raise timeout waiting for on_job_complete_event
ptormene d20dc99
Check that, after waiting for it, the on_job_complete_event was trigg…
ptormene 7d198ba
Improve docstrings
ptormene 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 |
---|---|---|
|
@@ -64,6 +64,7 @@ | |
from openquake.engine import __version__ as oqversion | ||
from openquake.engine.export import core | ||
from openquake.engine import engine, aelo, impact | ||
from openquake.engine.engine import notify_job_complete | ||
from openquake.engine.aelo import ( | ||
get_params_from, PRELIMINARY_MODELS, PRELIMINARY_MODEL_WARNING_MSG) | ||
from openquake.engine.export.core import DataStoreExportError | ||
|
@@ -687,6 +688,15 @@ def calc_log_size(request, calc_id): | |
return JsonResponse(response_data) | ||
|
||
|
||
@csrf_exempt | ||
@require_http_methods(['POST']) | ||
def log_callback(request): | ||
print(request.POST) | ||
print(request.GET) | ||
print(request.body.decode('utf8')) | ||
return HttpResponse(content='Done') | ||
|
||
|
||
@csrf_exempt | ||
@cross_domain_ajax | ||
@require_http_methods(['POST']) | ||
|
@@ -702,6 +712,8 @@ def calc_run(request): | |
The request also needs to contain the files needed to perform the | ||
calculation. They can be uploaded as separate files, or zipped | ||
together. | ||
If the request has the attribute `notify_to`, and it starts with | ||
'http[s]://', the engine will send a notification to the given url | ||
""" | ||
job_ini = request.POST.get('job_ini') | ||
hazard_job_id = request.POST.get('hazard_job_id') | ||
|
@@ -710,8 +722,12 @@ def calc_run(request): | |
else: | ||
ini = job_ini if job_ini else ".ini" | ||
user = utils.get_user(request) | ||
notify_to = request.POST.get('notify_to') | ||
# notify_to = 'http://127.0.0.1:8800/v1/log_callback?pippo=pluto' | ||
|
||
try: | ||
job_id = submit_job(request.FILES, ini, user, hazard_job_id) | ||
job_id = submit_job( | ||
request.FILES, ini, user, hazard_job_id, notify_to) | ||
except Exception as exc: # job failed, for instance missing .xml file | ||
# get the exception message | ||
exc_msg = traceback.format_exc() + str(exc) | ||
|
@@ -734,11 +750,16 @@ def calc_run_ini(request): | |
:param request: | ||
a `django.http.HttpRequest` object. | ||
The request must contain the full path to a job.ini file | ||
If the request has the attribute `notify_to`, and it starts with | ||
'http[s]://', the engine will send a notification to the given url | ||
|
||
""" | ||
ini = request.POST.get('job_ini') | ||
ini = request.POST['job_ini'] | ||
hazard_job_id = request.POST.get('hazard_job_id') | ||
user = utils.get_user(request) | ||
notify_to = request.POST.get('notify_to') | ||
# notify_to = 'http://127.0.0.1:8800/v1/log_callback?pippo=pluto' | ||
try: | ||
job_id = submit_job([], ini, user, hc_id=None) | ||
job_id = submit_job([], ini, user, hazard_job_id, notify_to=notify_to) | ||
except Exception as exc: # job failed, for instance missing .ini file | ||
# get the exception message | ||
exc_msg = traceback.format_exc() + str(exc) | ||
|
@@ -1225,7 +1246,7 @@ def aelo_run(request): | |
return JsonResponse(response_data, status=200) | ||
|
||
|
||
def submit_job(request_files, ini, username, hc_id): | ||
def submit_job(request_files, ini, username, hc_id, notify_to=None): | ||
""" | ||
Create a job object from the given files and run it in a new process. | ||
|
||
|
@@ -1272,7 +1293,10 @@ def submit_job(request_files, ini, username, hc_id): | |
CALC_NAME='calc%d' % job.calc_id) | ||
subprocess.run(submit_cmd, input=yaml.encode('ascii')) | ||
else: | ||
proc = mp.Process(target=engine.run_jobs, args=([job],)) | ||
kwargs = {} | ||
if notify_to is not None: | ||
kwargs['notify_to'] = notify_to | ||
proc = mp.Process(target=engine.run_jobs, args=([job],), kwargs=kwargs) | ||
proc.start() | ||
if config.webapi.calc_timeout: | ||
mp.Process( | ||
|
@@ -1695,7 +1719,8 @@ def web_engine_get_outputs(request, calc_id, **kwargs): | |
mce=mce, mce_spectra=mce_spectra, | ||
calc_aelo_version=calc_aelo_version, | ||
asce_version=asce_version_full, | ||
lon=lon, lat=lat, site_class=site_class_display_name, site_name=site_name) | ||
lon=lon, lat=lat, site_class=site_class_display_name, | ||
site_name=site_name) | ||
) | ||
|
||
|
||
|
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.
action type (POST) and retrieved data maybe a nice info add