Impacted versions: 10.0

If the PostgreSQL server is down, cron threads will crash when trying to connect to the db. When Odoo is running in multithreading mode, they won't properly recover once the PostgreSQL is back up. The consequence is that the Odoo instance will seem to be working fine after the downtime, while actually none of the Scheduled Actions are being processed (the Email Queue Manager for example).

The impact is not as big in multiprocessing mode because new WorkerCrons are spawned after crash.

**Steps to reproduce**:

- start Odoo in multithreading mode (`workers=0`)
- wait a few minutes
- notice how scheduled actions are running properly:

```
2017-02-28 05:40:10,944 23155 DEBUG ? odoo.service.server: cron0 polling for jobs
2017-02-28 05:40:10,947 23155 DEBUG xp_10_test_pg_downtime odoo.addons.base.ir.ir_cron: Starting job `Test`.
```

- stop PostgreSQL server (make sure that all connections are closed: `sudo pkill -9 postgres`)
- notice the cron threads crashing:

```
Exception in thread odoo.service.cron.cron0:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/opt/openerp/code/xp/10.0/odoo/odoo/service/server.py", line 238, in target
    self.cron_thread(i)
  File "/opt/openerp/code/xp/10.0/odoo/odoo/service/server.py", line 220, in cron_thread
    acquired = odoo.addons.base.ir.ir_cron.ir_cron._acquire_job(db_name)
  File "/opt/openerp/code/xp/10.0/odoo/odoo/addons/base/ir/ir_cron.py", line 185, in _acquire_job
    cr = db.cursor()
  File "/opt/openerp/code/xp/10.0/odoo/odoo/sql_db.py", line 623, in cursor
    return Cursor(self.__pool, self.dbname, self.dsn, serialized=serialized)
  File "/opt/openerp/code/xp/10.0/odoo/odoo/sql_db.py", line 164, in __init__
    self._cnx = pool.borrow(dsn)
  File "/opt/openerp/code/xp/10.0/odoo/odoo/sql_db.py", line 506, in _locked
    return fun(self, *args, **kwargs)
  File "/opt/openerp/code/xp/10.0/odoo/odoo/sql_db.py", line 574, in borrow
    **connection_info)
  File "/opt/openerp/.local/share/virtualenvs/odoo-10.0/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
    conn = _connect(dsn, connection_factory=connection_factory, async=async)
OperationalError: could not connect to server: Connection refused
	Is the server running on host "localhost" (::1) and accepting
	TCP/IP connections on port 5432?
could not connect to server: Connection refused
	Is the server running on host "localhost" (127.0.0.1) and accepting
	TCP/IP connections on port 5432?
```

- restart PostgreSQL server
- notice that Odoo is working again
- BUT scheduled actions are not: no trace of crons "polling for jobs" in the logs anymore.

A spontaneous fix for multithreading-mode is to catch the Exception and let the cron thread retry to connect later, here:

https://github.com/odoo/odoo/blob/10.0/odoo/service/server.py#L220

```
                    try:
                        acquired = odoo.addons.base.ir.ir_cron.ir_cron._acquire_job(db_name)
                    except Exception as e:
                        _logger.debug('cron%d encountered an Exception: %s', number, e)
                        break
```

But you might want to fix this issue at `ir_cron` level ;)
except Exception:
                    _logger.exception('Unexpected exception while processing cron job %r', job)
                finally:
                    job_cr.close()
            except psycopg2.OperationalError, 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
    def _try_lock(self, cr, uid, ids, context=None):
        """Try to grab a dummy exclusive write-lock to the rows with the given ids,
           to make sure a following write() or unlink() will not block due
           to a process currently executing those cron tasks"""
        try:
            cr.execute("""SELECT id FROM "%s" WHERE id IN %%s FOR UPDATE NOWAIT""" % self._table,
                       (tuple(ids),), log_exceptions=False)
        except psycopg2.OperationalError:
            cr.rollback() # 
            raise osv.except_osv(_("Record cannot be modified right now"),
                                 _("This cron task is currently being executed and may not be modified, "
                                  "please try again in a few minutes"))
    def create(self, cr, uid, vals, context=None):