MCPcopy Create free account
hub / github.com/dbcli/mssql-cli / _check_create_db_status

Function _check_create_db_status

tests/mssqltestutils.py:140–165  ·  view source on GitHub ↗

Uses retry logic with sys.dm_operation_status to check statis of create database job.

(db_name, client)

Source from the content-addressed store, hash-verified

138 return False
139
140def _check_create_db_status(db_name, client):
141 """
142 Uses retry logic with sys.dm_operation_status to check statis of create database job.
143 """
144 query_check_status = u"SELECT TOP 1 state_desc, error_desc FROM sys.dm_operation_status " \
145 u"WHERE major_resource_id = '{}' AND operation = 'CREATE DATABASE' " \
146 u"ORDER BY start_time DESC".format(db_name)
147
148 # retry for 5 minutes until db status is no longer 'processing'
149 datetime_end_loop = datetime.now() + timedelta(minutes=5)
150 state_desc, error_desc = None, None
151 while datetime.now() < datetime_end_loop:
152 for row, _, status, _, is_error in client.execute_query(query_check_status):
153 if is_error:
154 raise ConnectionError("Checking database creation status failed: {}"\
155 .format(status))
156 state_desc = row[0][0]
157 error_desc = row[0][1]
158
159 if state_desc != 'PROCESSING':
160 break
161
162 # call sleep so db isn't overburdened with requests
163 time.sleep(5)
164
165 return (state_desc, error_desc)
166
167def clean_up_test_db(test_db_name):
168 client = create_mssql_cli_client()

Callers 1

create_test_dbFunction · 0.85

Calls 2

formatMethod · 0.45
execute_queryMethod · 0.45

Tested by

no test coverage detected