<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Function to manage the Redis Queue. In summary
this function either

  (a) starts a new queue if no jobs are pending
  (b) fetches statistics from a running queue
  (c) cancels a queue and starts again

This function was designed to be called directly
by the routes so that the final user knows what
is the current status of the running queues.

'''<commit_msg>improving the output of queue functions<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Function to manage the Redis Queue. In summary
this function either

  (a) starts a new queue if no jobs are pending
  (b) fetches statistics from a running queue
  (c) cancels a queue and starts again

This function was designed to be called directly
by the routes so that the final user knows what
is the current status of the running queues.

'''
import flask

from rq import Queue
from redis import Redis

def getStatus(queue_id='default'):
  '''
  Gets status of queue.

  '''
  queue = Queue(connection=Redis(), name=queue_id)
  result = {
    'message': 'Queue `{name}` is not empty. {n} jobs are being processed.'.format(name=queue_id, n=queue.count),
    'empty': queue.is_empty(),
    'count': queue.count,
    'ids': queue.get_job_ids()
  }

  return result

def cleanQueue(queue_id='default'):
  '''
  Cleans specified queue.

  '''
  queue = Queue(connection=Redis(), name=queue_id)
  result = {
      'success': True,
      'message': 'Cleaned {n} jobs successfully from `{name}`.'.format(n=queue.empty(), name=queue_id)
    }
  return result
{'fraction_non_alphanumeric': 0.11033608116677235, 'fraction_numerical': 0.0012682308180088776, 'mean_word_length': 3.7963525835866263, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4485634', 'n_tokens_mistral': 488, 'n_tokens_neox': 480, 'n_words': 194}