Prevent database queue from deadlock

Make sure that every call to the queue will check first if we are not already in the context of database queue.
If we are in the context of the database queue execute the block immediately without queuing it which will deadlock the code.