def main():
    with RecordsDB() as records_db:
        records_parser = RecordsParser(records_db)

        with CountriesDB() as countries_db:
            queue = RedisQueue(name='jobs',
                               namespace='queue',
                               decode_responses=True)
            job_in_json = queue.wait_and_dequeue()

            while job_in_json is not None:

                job = json.loads(job_in_json)

                country_id = job['country_id']
                country_name = countries_db.get_country_from_id(country_id)
                num_records = job['num_records']

                if country_name is None:
                    raise Exception("Country name cannot be None!")

                records_parser.get_records(country=country_name,
                                           country_id=country_id,
                                           max_records=num_records)

                job_in_json = queue.wait_and_dequeue()
def clear_jobs():
    queue = RedisQueue(name='jobs', namespace='queue', decode_responses=True)
    job_in_json = queue.wait_and_dequeue()

    while job_in_json is not None:
        job_in_json = queue.wait_and_dequeue()