Skip to content
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

return_progress as arg for run_query #601

Merged
merged 41 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3facc14
arg naming
burnout87 Oct 11, 2023
4623ae0
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Oct 12, 2023
37c692f
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Oct 16, 2023
3a7d70d
DataServerQueryReturnProgress
burnout87 Oct 17, 2023
1921567
return_progress inside get_query_products, passed to run_query of dat…
burnout87 Oct 17, 2023
405f326
return_progress inside get_query_products, passed to run_query of dat…
burnout87 Oct 17, 2023
121838b
no return_progress for data_server_query
burnout87 Oct 17, 2023
1757f59
passing return_progress to get_query_products
burnout87 Oct 17, 2023
bc44f6d
dedicated functions for returning query progress
burnout87 Oct 17, 2023
13d7096
dummy plugin
burnout87 Oct 17, 2023
2b3d663
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Oct 18, 2023
7285b4f
avoid code repetition inside ProductQuery
burnout87 Oct 18, 2023
33e9d54
arg in get_query_products
burnout87 Oct 18, 2023
17aa0be
arg in get_query_products
burnout87 Oct 18, 2023
5eab752
empty-async-return-progress instrument
burnout87 Oct 18, 2023
f5c24fe
build prod_list also in case of return_progress
burnout87 Oct 18, 2023
02754ab
removed unused imports
burnout87 Oct 19, 2023
b847656
added missing config for new dummy instrument
burnout87 Oct 19, 2023
158fcb0
fixing test
burnout87 Oct 19, 2023
e21f941
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Oct 19, 2023
4b25d94
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Oct 25, 2023
9c6143b
arg reformatting
burnout87 Oct 25, 2023
79c1054
extending ReturnProgressProductQuery
burnout87 Oct 25, 2023
a625362
always returns query_prod_list
burnout87 Oct 25, 2023
8719636
dedicated test
burnout87 Oct 25, 2023
176a595
Merge branch 'return_progress-arg-run_analysis' of github.com:oda-hub…
burnout87 Oct 25, 2023
ad39a6d
Real query_type
burnout87 Oct 25, 2023
d954c55
reformatting method signature
burnout87 Oct 26, 2023
f18d3fb
dummy get_progress_run returns also the current product value
burnout87 Oct 31, 2023
3dfe1d2
not forcing to status one in case of return_progress
burnout87 Oct 31, 2023
cf1f3eb
adapted test
burnout87 Oct 31, 2023
0cad7b5
return_progress-arg-run_analysis
burnout87 Nov 2, 2023
c263685
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Nov 2, 2023
782c621
revert oda_api branch
burnout87 Nov 2, 2023
64ba7b5
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Nov 8, 2023
672974f
test specific oda_api branch
burnout87 Nov 8, 2023
e6a9fa3
back on the master oda_api branch
burnout87 Nov 9, 2023
eeabef5
using test oda_api branch
burnout87 Nov 9, 2023
1967319
master branch for oda_api workflow
burnout87 Nov 9, 2023
f25a7ed
avoid duplicaiton
burnout87 Nov 13, 2023
67d9b16
Merge branch 'master' into return_progress-arg-run_analysis
burnout87 Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cdci_data_analysis/analysis/instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def run_query(self, product_type,
dry_run=False,
api=False,
decoded_token=None,
return_progress=False,
**kwargs):

if logger is None:
Expand Down Expand Up @@ -433,6 +434,7 @@ def run_query(self, product_type,
config=config,
logger=logger,
sentry_dsn=sentry_dsn,
return_progress=return_progress,
api=api)
if query_out.status_dictionary['status'] == 0:
if 'comment' in query_out.status_dictionary.keys():
Expand Down
69 changes: 64 additions & 5 deletions cdci_data_analysis/analysis/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@
def get_dummy_products(self,instrument, config=None,**kwargs):
raise RuntimeError(f'{self}: get_dummy_products needs to be implemented in derived class')

def get_progress(self):
raise RuntimeError(f'{self}: get_progress needs to be implemented in derived class')

Check warning on line 384 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L384

Added line #L384 was not covered by tests

def get_dummy_progress(self, instrument, config=None,**kwargs):
raise RuntimeError(f'{self}: get_dummy_progress needs to be implemented in derived class')

Check warning on line 387 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L387

Added line #L387 was not covered by tests

def get_data_server_query(self,instrument,config=None,**kwargs):
traceback.print_stack()
raise RuntimeError(f'{self}: get_data_server_query needs to be implemented in derived class')
Expand Down Expand Up @@ -526,6 +532,35 @@

return query_out

def get_query_progress_details(self, instrument, job, query_type='Real', config=None, logger=None, scratch_dir=None, api=False):
if logger is None:
logger = self.get_logger()

Check warning on line 537 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L536-L537

Added lines #L536 - L537 were not covered by tests
Fixed Show fixed Hide fixed

query_out = QueryOutput()

Check warning on line 539 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L539

Added line #L539 was not covered by tests
Fixed Show fixed Hide fixed
# status=0

messages = {

Check warning on line 542 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L542

Added line #L542 was not covered by tests
Fixed Show fixed Hide fixed
'message': '',
'debug_message': '',
'comment': '',
'warning': ''
}
try:
if query_type != 'Dummy':
q = self.get_data_server_query(instrument, config)
q.get_progress()

Check warning on line 551 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L548-L551

Added lines #L548 - L551 were not covered by tests
else:
status = 0
Fixed Show fixed Hide fixed
self.query_prod_list = self.get_dummy_progress(instrument,

Check warning on line 554 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L553-L554

Added lines #L553 - L554 were not covered by tests
config=config,
out_dir=scratch_dir,
api=api)

job.set_done()
except Exception as e:
sentry_sdk.capture_exception(e)
raise InternalError(f"unexpected error while getting query progress details with {instrument}, {e}")

Check warning on line 562 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L559-L562

Added lines #L559 - L562 were not covered by tests

def get_query_products(self,instrument,job,run_asynch,query_type='Real',logger=None,config=None,scratch_dir=None,sentry_dsn=None,api=False):
if logger is None:
logger = self.get_logger()
Expand All @@ -545,7 +580,9 @@
if query_type != 'Dummy':
q = self.get_data_server_query(instrument,config)

res, data_server_query_out = q.run_query(call_back_url=job.get_call_back_url(), run_asynch=run_asynch, logger=logger)
res, data_server_query_out = q.run_query(call_back_url=job.get_call_back_url(),
run_asynch=run_asynch,
logger=logger)

for field in ['message', 'debug_message', 'comment', 'warning']:
if field in data_server_query_out.status_dictionary.keys():
Expand All @@ -570,7 +607,10 @@

else:
status=0
self.query_prod_list = self.get_dummy_products(instrument,config=config,out_dir=scratch_dir,api=api)
self.query_prod_list = self.get_dummy_products(instrument,
config=config,
out_dir=scratch_dir,
api=api)

#self.query_prod_list = QueryProductList(prod_list=prod_list)

Expand Down Expand Up @@ -677,7 +717,8 @@
config=None,
logger=None,
sentry_dsn=None,
api=False):
api=False,
return_progress=False):

# print ('--> running query for ',instrument.name,'with config',config)
if logger is None:
Expand All @@ -700,18 +741,36 @@


if query_out.status_dictionary['status'] == 0:
query_out = self.get_query_products(instrument,job,run_asynch, query_type=query_type, logger=logger, config=config, scratch_dir=scratch_dir, sentry_dsn=sentry_dsn, api=api)
query_out = self.get_query_products(instrument,
job,
run_asynch,
query_type=query_type,
logger=logger,
config=config,
scratch_dir=scratch_dir,
sentry_dsn=sentry_dsn,
api=api)
self._t_query_steps['after_get_query_products'] = _time.time()

if query_out.status_dictionary['status'] == 0:
if job.status!='done':
if job.status != 'done':

query_out.prod_dictionary = {}
# TODO: add check if is asynch
# TODO: the asynch status will be in the qery_out class
# TODO: if asynch and running return proper query_out
# TODO: if asynch and done proceed

if return_progress:
self.get_query_progress_details(instrument,

Check warning on line 765 in cdci_data_analysis/analysis/queries.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/analysis/queries.py#L765

Added line #L765 was not covered by tests
job,
query_type=query_type,
logger=logger,
config=config,
scratch_dir=scratch_dir,
api=api
)

else:
if query_out.status_dictionary['status'] == 0:
#print('-->',query_out.status_dictionary)
Expand Down
2 changes: 2 additions & 0 deletions cdci_data_analysis/flask_app/dispatcher_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def __init__(self, app,


self.client_name = self.par_dic.pop('client-name', 'unknown')
self.return_progress = self.par_dic.pop('return-progress', False) == 'True'
if os.environ.get("DISPATCHER_ASYNC_ENABLED", "no") == "yes": # TODO: move to config!
self.async_dispatcher = self.par_dic.pop(
'async_dispatcher', 'True') == 'True' # why string true?? else false anyway
Expand Down Expand Up @@ -1909,6 +1910,7 @@ def run_query(self, off_line=False, disp_conf=None):
verbose=verbose,
dry_run=dry_run,
api=api,
return_progress=self.return_progress,
decoded_token=self.decoded_token)
self.log_query_progression("after instrument.run_query")
except RequestNotAuthorized as e:
Expand Down
53 changes: 38 additions & 15 deletions cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,21 @@

status = self.decide_status()
if status == "submitted":
# set done to submitted?
burnout87 marked this conversation as resolved.
Show resolved Hide resolved
query_out.set_done(message="job submitted mock",
debug_message="no message really",
job_status='submitted',
comment="mock comment",
warning="mock warning")
debug_message="no message really",
job_status='submitted',
comment="mock comment",
warning="mock warning")
elif status == "done":
# set done to submitted?
query_out.set_done(message="job done mock",
debug_message="no message really",
job_status='done',
comment="mock comment",
warning="mock warning")
debug_message="no message really",
job_status='done',
comment="mock comment",
warning="mock warning")
elif status == "failed":
# set done to submitted?
query_out.set_failed(message="job failed mock",
debug_message="no message really",
job_status='failed',
comment="mock comment",
warning="mock warning")
debug_message="no message really",
job_status='failed')
else:
NotImplementedError

Expand Down Expand Up @@ -164,6 +159,34 @@
return None, query_out


class ReturnProgressProductQuery(ProductQuery):
def __init__(self, name, parameters_list=None):
if parameters_list is None:
parameters_list = []
super().__init__(name, return_progress=True, parameters_list=parameters_list)

Check warning on line 166 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L164-L166

Added lines #L164 - L166 were not covered by tests


def run_query(self,
instrument,
scratch_dir,
job,
run_asynch,
query_type='Real',
config=None,
logger=None,
sentry_dsn=None,
api=False,
return_progress=False):
query_out = self.process_query_product(instrument, job, logger=logger, config=config, scratch_dir=scratch_dir,

Check warning on line 180 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L180

Added line #L180 was not covered by tests
sentry_dsn=sentry_dsn, api=api)
if query_out.status_dictionary['status'] == 0:
job.set_done()

Check warning on line 183 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L182-L183

Added lines #L182 - L183 were not covered by tests
else:
job.set_failed()

Check warning on line 185 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L185

Added line #L185 was not covered by tests

return query_out

Check warning on line 187 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L187

Added line #L187 was not covered by tests


class EmptyProductQuery(ProductQuery):

def __init__(self, name='unset-name', config=None, instrument=None):
Expand Down
Loading