Skip to content

Commit

Permalink
merge: #163 from patch
Browse files Browse the repository at this point in the history
  • Loading branch information
alycejenni committed Jul 8, 2024
2 parents 2384b48 + 49d9838 commit 73ae07e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
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

0 comments on commit 73ae07e

Please sign in to comment.