2

OK, I know it's not that simple. I have two db connections defined in my settings.py: default and cache. I'm using DatabaseCache backend from django.core.cache. I have database router defined so I can use separate database/schema/table for my models and for cache. Perfect!

Now sometimes my cache DB is not available and there are two cases:

  1. Connection to databse was established already when DB crashed - this is easy - I can use this recipe: http://code.activestate.com/recipes/576780-timeout-for-nearly-any-callable/ and wrap my query like this:

    try:
        timelimited(TIMEOUT, self._meta.cache.get, cache_key))
    expect TimeLimitExprired:
        # live without cache
    
  2. Connection to database wasn't yet established - so I need to wrap in timelimited some portion of code that actually establishes database connection. But I don't know where such code exists and how to wrap it selectively (i.e. wrap only cache connection, leave default connection without timeout)

Do you know how to do point 2?

Please note, this answer https://stackoverflow.com/a/1084571/940208 is not correct:

grep -R "connect_timeout" /usr/local/lib/python2.7/dist-packages/django/db

gives no results and cx_Oracle driver doesn't support this parameter as far as I know.

4
  • Are you using oracle as your db? Commented Nov 4, 2013 at 12:04
  • @MattWritesCode - if you haven’t notice, I included this link in my question saying this is not correct at all. Commented Nov 4, 2013 at 12:07
  • Please note that oracle/base.py do not modify connection settings (it only removes use_returning_into afair), as others backends do, so result of grep is predictable, yet connect_timeout will be passed as arg to Database.connect. Commented Nov 4, 2013 at 12:14
  • @alko - yes, I know it but in cx_Oracle documentation timeout parameter is not mentioned (strictly speaking it is in pool object but in very different meaning). Oracle philosophy is to set timeout on server not on client side so there is no client configuration that can define timeout. Commented Nov 4, 2013 at 12:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.