Skip to content

Commit

Permalink
Fix client and make core scanner nicer
Browse files Browse the repository at this point in the history
  • Loading branch information
lnauta committed Jan 2, 2025
1 parent e68cafa commit e92f9a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 9 additions & 6 deletions examples/core-scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@
picaslogger.propagate = False

client = CouchDB(url=picasconfig.PICAS_HOST_URL, db=picasconfig.PICAS_DATABASE, username=picasconfig.PICAS_USERNAME, password=picasconfig.PICAS_PASSWORD)
work_1c_avail = client.is_view_nonempty("todo1c", design_doc="MonitorCores")
work_4c_avail = client.is_view_nonempty("todo4c", design_doc="MonitorCores")

design_doc_1c = "MonitorSingleCore"
design_doc_4c = "MonitorMultiCore"
work_1c_avail = client.is_view_nonempty("todo", design_doc=design_doc_1c)
work_4c_avail = client.is_view_nonempty("todo", design_doc=design_doc_4c)

if work_1c_avail and work_4c_avail:
picaslogger.info(f"Starting a picas clients checking view todo1c and view todo4c")
picaslogger.info(f"Starting a picas clients checking design document {design_doc_1c} and design document {design_doc_4c}")
command = ["sbatch", "single-core-job.sh"]
execute(command)
command = ["sbatch", "multi-core-job.sh"]
execute(command)
elif work_1c_avail:
picaslogger.info(f"Starting a picas client checking view todo1c")
picaslogger.info(f"Starting a picas client checking design document {design_doc_1c}")
command = ["sbatch", "single-core-job.sh"]
execute(command)
elif work_4c_avail:
picaslogger.info(f"Starting a picas client checking view todo4c")
picaslogger.info(f"Starting a picas client checking design document {design_doc_4c}")
command = ["sbatch", "multi-core-job.sh"]
execute(command)
else:
picaslogger.info(f"Not starting a picas client, there is nothing to do in views todo1c and todo4c")
picaslogger.info(f"Not starting a picas client, there is nothing to do in views todo and for the designdocs {design_doc_1c} and {design_doc_4c}")
9 changes: 6 additions & 3 deletions picas/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,19 @@ def is_view_nonempty(self, view, **view_params):
:param view: database view to scan for tokens
:return: bool
"""
# To ensure proper logging when design_doc is not passed into is_view_nonempty,
# the variable is created as the default used in self.view. Otherwise the f-string below breaks on default input.
design_doc = view_params.setdefault('design_doc', "Monitor")
try:
doc = self.get_single_from_view(view, **view_params)
task = Task(doc)
picaslogger.debug(doc)
picaslogger.debug(task['input'])
picaslogger.info(f"Database view {view} is non-empty.")
picaslogger.info(f"View {view} under design document {design_doc} is non-empty.")
return True
except IndexError as e:
picaslogger.info(f"Database view {view} is empty: {e}")
picaslogger.info(f"View {view} under design document {design_doc} is empty: {e}")
return False
except ResourceNotFound as e:
picaslogger.info(f"Non-existing database view passed: {view}")
picaslogger.info(f"Non-existing view and design document passed: {view} in {design_doc}")
return False

0 comments on commit e92f9a7

Please sign in to comment.