wait_for_database.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:django-gitlab-boilerplate 作者: motius 项目源码 文件源码
def handle(self, *args, **options):
        try:
            connection = connections[options['database']]
        except ConnectionDoesNotExist:
            raise CommandError('Database "%s" does not exist in settings' % options['database'])

        for i in range(0, options['retries']):
            try:
                connection.cursor()
            except OperationalError:
                i += 1
                self.stdout.write('{} / {}: Waiting for database...'.format(i, options['retries']))
                sleep(options['sleep_time'])
            else:
                self.stdout.write(self.style.SUCCESS('Successfully connected to database'))
                return

        raise CommandError('Number of retries reached, exiting')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号