Skip to content

Commit 9c2c45d

Browse files
author
rob
committed
allow parameters to be passed into running methods
1 parent 1e736bc commit 9c2c45d

File tree

5 files changed

+64
-15
lines changed

5 files changed

+64
-15
lines changed

syscontrol/control_config.yaml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ process_configuration_stop_time:
2222
run_backups: '23:50'
2323
run_cleaners: '23:50'
2424
run_reports: '23:50'
25-
process_arguments:
26-
run_daily_prices_updates:
27-
download_by_zone:
28-
Asia: '07:00'
29-
EMEA: '18:00'
30-
US: '20:00'
25+
## Examples of passing arguments
26+
#arguments:
27+
# run_daily_prices_updates:
28+
# update_historical_prices: # everything in this block is passed as **kwargs to this method
29+
# download_by_zone:
30+
# Asia: '07:00'
31+
# EMEA: '18:00'
32+
# US: '20:00'
33+
# _methods_on_completion: # and this block is passed to all methods that run on completion only
34+
# a: 'test'
3135
# Examples:
3236
#process_configuration_previous_process:
3337
# run_systems: 'run_daily_prices_updates'

syscontrol/run_process.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,25 @@ def _main_loop_over_methods(self):
125125
if we_should_pause:
126126
continue
127127

128-
timer_class.check_and_run()
128+
kwargs = self._kwargs_for_method_and_process(timer_class.method_name)
129+
timer_class.check_and_run(**kwargs)
130+
131+
def _kwargs_for_method_and_process(self, method_name: str) -> dict:
132+
return self.diag_process.get_configured_kwargs_for_process_name_and_method(
133+
process_name=self.process_name, method=method_name
134+
)
129135

130136
def _finish(self):
131-
self.list_of_timer_functions.run_methods_which_run_on_exit_only()
137+
kwargs = self._kwargs_for_exit_only_method_and_process()
138+
self.list_of_timer_functions.run_methods_which_run_on_exit_only(**kwargs)
132139
self._finish_control_process()
133140
self.data.close()
134141

142+
def _kwargs_for_exit_only_method_and_process(self) -> dict:
143+
return self.diag_process.get_configured_kwargs_for_process_name_and_methods_that_run_on_completion(
144+
self.process_name
145+
)
146+
135147
def _finish_control_process(self):
136148
result_of_finish = self.data_control.finish_process(self.process_name)
137149

syscontrol/timer_functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def report_status(self) -> reportStatus:
110110
def log_msg(self, msg: str):
111111
self.log.msg(msg, type=self.process_name)
112112

113-
def check_and_run(self, last_run: bool = False):
113+
def check_and_run(self, last_run: bool = False, **kwargs):
114114
"""
115115
116116
:return: None
@@ -121,7 +121,7 @@ def check_and_run(self, last_run: bool = False):
121121
return None
122122

123123
self.setup_about_to_run_method()
124-
self.run_function()
124+
self.run_function(**kwargs)
125125
self.finished_running_method()
126126

127127
def check_if_okay_to_run(self, last_run=False) -> bool:
@@ -294,9 +294,9 @@ def store_in_db_run_start_method(self):
294294
data_process = dataControlProcess(self.data)
295295
data_process.log_start_run_for_method(self.process_name, self.method_name)
296296

297-
def run_function(self):
297+
def run_function(self, **kwargs):
298298
# Functions can't take args or kwargs or return anything; pure method
299-
self._function()
299+
self._function(**kwargs)
300300

301301
def finished_running_method(self):
302302
self.store_in_db_log_run_end_method()
@@ -323,9 +323,9 @@ def check_all_finished(self) -> bool:
323323

324324
return all_finished
325325

326-
def run_methods_which_run_on_exit_only(self):
326+
def run_methods_which_run_on_exit_only(self, **kwargs):
327327
for timer_class in self:
328-
timer_class.check_and_run(last_run=True)
328+
timer_class.check_and_run(last_run=True, **kwargs)
329329

330330
def seconds_until_next_method_runs(self) -> float:
331331
minutes_remaining = [

sysproduction/data/control_process.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
DEFAULT_START_TIME_STRING = "00:01"
2020
DEFAULT_STOP_TIME_STRING = "23:50"
2121
NAME_OF_TRADING_PROCESS = "run_stack_handler"
22+
LABEL_FOR_ARGS_METHOD_ON_COMPLETION = "_methods_on_completion"
2223

2324

2425
class dataControlProcess(productionDataLayerGeneric):
@@ -382,6 +383,37 @@ def get_list_of_process_names(self) -> list:
382383
result = self.db_control_process_data.get_list_of_process_names()
383384
return result
384385

386+
def get_configured_kwargs_for_process_name_and_methods_that_run_on_completion(
387+
self, process_name: str
388+
) -> dict:
389+
return self.get_configured_kwargs_for_process_name_and_method(
390+
process_name=process_name, method=LABEL_FOR_ARGS_METHOD_ON_COMPLETION
391+
)
392+
393+
def get_configured_kwargs_for_process_name_and_method(
394+
self, process_name: str, method: str
395+
) -> dict:
396+
configured_kwargs_for_process_name = (
397+
self.get_configured_kwargs_for_process_name(process_name)
398+
)
399+
configured_kwargs_for_process_name_and_method = (
400+
configured_kwargs_for_process_name.get(method, {})
401+
)
402+
403+
return configured_kwargs_for_process_name_and_method
404+
405+
def get_configured_kwargs_for_process_name(self, process_name: str) -> dict:
406+
configured_kwargs = self.configured_kwargs()
407+
configured_kwargs_for_process_name = configured_kwargs.get(process_name, {})
408+
409+
return configured_kwargs_for_process_name
410+
411+
def configured_kwargs(self) -> dict:
412+
kwargs = self.get_key_value_from_control_config("arguments")
413+
if kwargs is missing_data:
414+
return {}
415+
return kwargs
416+
385417
def get_key_value_from_control_config(self, item_name: str):
386418
config = self.get_control_config()
387419
item = config.get_element_or_missing_data(item_name)

sysproduction/update_historical_prices.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ class updateHistoricalPrices(object):
4040
def __init__(self, data):
4141
self.data = data
4242

43-
def update_historical_prices(self):
43+
def update_historical_prices(self, **kwargs):
44+
print("**kwargs** I am ignoring for now %s" % str(kwargs))
4445
data = self.data
4546
update_historical_prices_with_data(data)
4647

0 commit comments

Comments
 (0)