Skip to content

Commit

Permalink
Merge pull request #6 from NaturalHistoryMuseum/josh/status_partial
Browse files Browse the repository at this point in the history
Allow requester to define whether they want a full status or not
  • Loading branch information
jrdh authored Oct 13, 2021
2 parents ac1f4d5 + cb948e7 commit 998b2e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions iiif/profiles/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,17 @@ async def close(self):
"""
pass

async def get_status(self) -> dict:
async def get_status(self, full: bool = False) -> dict:
"""
Returns some stats about the profile.
:return: a dict of stats
"""
return {
status = {
'name': self.name,
'info_json_cache_size': len(self.info_json_cache),
'sources': get_path_stats(self.source_path),
'cache': get_path_stats(self.cache_path),
}
if full:
status['sources'] = get_path_stats(self.source_path)
status['cache'] = get_path_stats(self.cache_path)
return status
4 changes: 2 additions & 2 deletions iiif/profiles/mss.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ async def close(self):
self.ic_fast_pool.shutdown()
self.ic_slow_pool.shutdown()

async def get_status(self) -> dict:
async def get_status(self, full: bool = False) -> dict:
"""
Returns some nice stats about what the runners are up to and such.
:return: a dict of stats
"""
status = await super().get_status()
status = await super().get_status(full)
runners = (self.doc_runner, self.fetch_runner)
status['runners'] = {
runner.name: await runner.get_status() for runner in runners
Expand Down
6 changes: 4 additions & 2 deletions iiif/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ async def on_shutdown():


@app.get('/status')
async def status() -> dict:
async def status(full: bool = False) -> dict:
"""
Returns the status of the server along with some stats about current resource usages.
:param full: boolean parameter indicating whether to provide a full status or just the
essentials. The full status may take longer to generate. Default: False.
:return: a dict
"""
return {
'status': ':)',
'default_profile': state.config.default_profile_name,
'processing': state.dispatcher.get_status(),
'profiles': {
profile.name: await profile.get_status()
profile.name: await profile.get_status(full)
for profile in state.profiles.values()
}
}
Expand Down

0 comments on commit 998b2e4

Please sign in to comment.