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

Status patches #162

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 1 addition & 15 deletions ckanext/versioned_datastore/lib/datastore_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,31 +290,17 @@ def is_ingestible(resource):

def get_queue_length(queue_name):
"""
This is a *very* hacky way to get the length of a queue, including anything already
This will only get the pending jobs in a queue, not any jobs that are currently
processing.

:param queue_name: the name of the queue to check, e.g. 'download'
:return: length of queue as int
"""
# because only pending jobs are counted, not active/running, if you add to the queue
# and job_list can't see it, the queue was empty; if it can, something else is
# already running.
def _temp_job():
time.sleep(1)

job = toolkit.enqueue_job(
_temp_job,
queue=queue_name,
title=f'{queue_name} queue status test',
rq_kwargs={'ttl': '1s'},
)

queued_jobs = toolkit.get_action('job_list')(
{'ignore_auth': True}, {'queues': [queue_name]}
)

job.delete()

return len(queued_jobs)


Expand Down
16 changes: 6 additions & 10 deletions ckanext/versioned_datastore/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,10 @@ def modify_status_reports(self, status_reports):
'label': toolkit._('Downloads'),
'value': queued_downloads,
'group': toolkit._('Queues'),
'help': toolkit._(
'Number of downloads either currently processing or waiting in the queue'
),
'help': toolkit._('Number of downloads waiting in the queue'),
'state': 'good'
if queued_downloads == 0
else ('ok' if queued_downloads < 3 else 'bad'),
if queued_downloads < 2
else ('ok' if queued_downloads < 4 else 'bad'),
}
)

Expand All @@ -204,12 +202,10 @@ def modify_status_reports(self, status_reports):
'label': toolkit._('Imports'),
'value': queued_imports,
'group': toolkit._('Queues'),
'help': toolkit._(
'Number of import jobs either currently processing or waiting in the queue'
),
'help': toolkit._('Number of import jobs waiting in the queue'),
'state': 'good'
if queued_imports == 0
else ('ok' if queued_imports < 3 else 'bad'),
if queued_imports < 2
else ('ok' if queued_imports < 4 else 'bad'),
}
)

Expand Down
Loading