'Try to process one cron job.
This selects in database all the jobs that should be processed. It then
tries to lock each of them and, if it succeeds, run the cron job (if it
doesn\'t succeed, it means the job was already locked to be taken care
of by another thread) and return.
If a job was processed, returns True, otherwise returns False.'

@classmethod
def _acquire_job(cls, db_name):

    db = odoo.sql_db.db_connect(db_name)
    threading.current_thread().dbname = db_name
    jobs = []
    try:
        with db.cursor() as cr:
            cr.execute('SELECT    1    FROM    ir_module_module    WHERE    name=%s    AND    latest_version=%s', ('base', BASE_VERSION))
            if cr.fetchone():
                cr.execute("SELECT    *    FROM    ir_cron\n                                                                                                                                        WHERE    numbercall    !=    0\n                                                                                                                                                        AND    active    AND    nextcall    <=    (now()    at    time    zone    'UTC')\n                                                                                                                                        ORDER    BY    priority")
                jobs = cr.dictfetchall()
            else:
                _logger.warning('Skipping    database    %s    as    its    base    version    is    not    %s.', db_name, BASE_VERSION)
    except psycopg2.ProgrammingError as e:
        if (e.pgcode == '42P01'):
            _logger.warning('Tried    to    poll    an    undefined    table    on    database    %s.', db_name)
        else:
            raise
    except Exception:
        _logger.warning('Exception    in    cron:', exc_info=True)
    for job in jobs:
        lock_cr = db.cursor()
        try:
            lock_cr.execute("SELECT    *\n                                                                                                                                            FROM    ir_cron\n                                                                                                                                            WHERE    numbercall    !=    0\n                                                                                                                                                        AND    active\n                                                                                                                                                        AND    nextcall    <=    (now()    at    time    zone    'UTC')\n                                                                                                                                                        AND    id=%s\n                                                                                                                                            FOR    UPDATE    NOWAIT", (job['id'],), log_exceptions=False)
            locked_job = lock_cr.fetchone()
            if (not locked_job):
                _logger.debug('Job    `%s`    already    executed    by    another    process/thread.    skipping    it', job['name'])
                continue
            _logger.debug('Starting    job    `%s`.', job['name'])
            job_cr = db.cursor()
            try:
                registry = odoo.registry(db_name)
                registry[cls._name]._process_job(job_cr, job, lock_cr)
            except Exception:
                _logger.exception('Unexpected    exception    while    processing    cron    job    %r', job)
            finally:
                job_cr.close()
        except psycopg2.OperationalError as e:
            if (e.pgcode == '55P03'):
                _logger.debug('Another    process/thread    is    already    busy    executing    job    `%s`,    skipping    it.', job['name'])
                continue
            else:
                raise
        finally:
            lock_cr.close()
    if hasattr(threading.current_thread(), 'dbname'):
        del threading.current_thread().dbname
