Skip to content

Commit a6c8f38

Browse files
committed
Updating README.rst ...
1 parent 30edd71 commit a6c8f38

File tree

2 files changed

+84
-17
lines changed

2 files changed

+84
-17
lines changed

README.rst

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,6 @@ Sample User Apps/Modules/Scripts
234234

235235
.. image:: docs/mdxreader.png
236236

237-
.. code-block:: python
238-
239-
240237
.. code-block:: python
241238
242239
def run_query(connection_string:str, command_text:str, result_model:str='DictOfList', column_mapping:dict={},
@@ -346,4 +343,52 @@ Sample User Apps/Modules/Scripts
346343

347344
``notify_args``
348345

349-
This is also a dictionary, any items it carries will be passed to the notification service as input arguments.
346+
This is also a dictionary. In general, any items it carries will be passed to the notification service as input arguments.
347+
However, if we want to include detailed result data and/or error information in the notification,
348+
then what parameter name(s) does the notification service use to receive them?
349+
We make a convention to use two special keys in this dictionary to indicate these two particular parameter names:
350+
351+
- '``[=]``' key: the value of this special key indicates the parameter name through which the notification service will receive detailed **result data**.
352+
*(this is optional) If not specified, detailed result data will not be sent to the notification service;*
353+
354+
- '``[!]``' key: the value of this special key indicates the parameter name through which the notification service will receive detailed **error information**.
355+
*(this is optional) If not specified, detailed error information will not be sent to the notification service;
356+
in this case, the notification itself cannot tell whether the process has completed successfully or encountered any errors,
357+
then the notification service may require some other channel to know whether the process succeeded or failed.*
358+
359+
|
360+
361+
Let's end this section with an example payload that covers as many options as possible:
362+
363+
.. code-block:: JSON
364+
365+
{
366+
"connection_string": "Provider=MSOLAP;Data Source=The_OLAP;Initial Catalog=The_Cube;Integrated Security=SSPI;Format=Tabular;Connect Timeout=3600",
367+
"command_text": "WITH ... SELECT ... ON COLUMNS, ... ON ROWS FROM ... WHERE ...",
368+
369+
"result_model": "SqlTvp",
370+
"column_mapping": {
371+
"Column X Caption": "inProductType",
372+
"Column Y Caption": "inSalesAmount",
373+
"Column Z Caption": ""
374+
},
375+
376+
"pass_result_to_url": "http://dbwebapi.dev.com/sqldev/the_db.dbo.load_mdx_result",
377+
"more_args": {
378+
"inAsOfDate": "2020-05-01"
379+
},
380+
381+
"notify_url": "http://notification.dev.com/send_message",
382+
"notify_args": {
383+
"[=]": "inResult",
384+
"[!]": "inError",
385+
"inBatchId": 123456,
386+
"inAsOfDate": "2020-05-01"
387+
}
388+
}
389+
390+
|
391+
392+
----
393+
394+
|

Sample/UserApps/MdxReader/mdx_task.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,30 @@
1212
from simple_rest_call import request_json
1313

1414

15+
def _notify(result, error=None, notify_url:str=None, notify_args:dict=None) -> bool:
16+
result_param_convention = '[=]'
17+
error_param_convention = '[!]'
18+
19+
if notify_url:
20+
if isinstance(notify_args, dict):
21+
result_param_name = notify_args.pop(result_param_convention, None)
22+
error_param_name = notify_args.pop(error_param_convention, None)
23+
else:
24+
result_param_name = error_param_name = None
25+
26+
if result_param_name:
27+
notify_args[result_param_name] = result
28+
29+
if error_param_name:
30+
notify_args[error_param_name] = error
31+
32+
request_json(notify_url, notify_args)
33+
34+
return True
35+
else:
36+
return False
37+
38+
1539
def run_query(connection_string:str, command_text:str, result_model:str='DictOfList', column_mapping:dict={},
1640
pass_result_to_url:str=None, more_args:dict=None, notify_url:str=None, notify_args:dict=None):
1741

@@ -22,22 +46,20 @@ def run_query(connection_string:str, command_text:str, result_model:str='DictOfL
2246
result = client.execute(command_text, result_model, column_mapping)
2347

2448
if pass_result_to_url:
25-
if isinstance(result, dict) and more_args:
26-
result.update(more_args)
49+
if more_args:
50+
if isinstance(result, dict):
51+
result.update(more_args)
52+
elif isinstance(result, list):
53+
for row in result:
54+
if isinstance(row, dict):
55+
row.update(more_args)
2756

28-
result = request_json(pass_result_to_url, result)
57+
result = request_json(pass_result_to_url, result) # Chain above result to DbWebApi for storage or further processing
2958

30-
if notify_url:
31-
request_json(notify_url, {'result': result})
59+
_notify(result, None, notify_url, notify_args) # Send a notification with result data
3260

3361
return result
3462

35-
except Exception as e:
36-
if notify_url:
37-
if notify_args is None:
38-
notify_args = {}
39-
notify_args.update({'error': e, 'result': result})
40-
41-
request_json(notify_url, notify_args)
42-
else:
63+
except Exception as err:
64+
if not _notify(result, err, notify_url, notify_args): # Send a notification with result data and/or error information
4365
raise

0 commit comments

Comments
 (0)