Commit 9813dd34 authored by Rob Carleski's avatar Rob Carleski 🇮🇸
Browse files

Add retries for resource fetch after creation.

* Also add defaults for resource type and description
parent d4b6163f
......@@ -36,7 +36,6 @@ class Resource:
'type',
self.resource_type
])
sleep(1)
except CalledProcessError:
self.logger.error(
'Failed to create resource.',
......@@ -44,17 +43,25 @@ class Resource:
)
exit(2)
try:
resource_info = cmd([
self.config['google']['gam_command'],
'info',
'resource',
self.resource_id
])
self.email = re.findall(b'Email: (.+)', resource_info)[0]
except CalledProcessError:
for n in range(5):
try:
resource_info = cmd([
self.config['google']['gam_command'],
'info',
'resource',
self.resource_id
])
self.email = re.findall(b'Email: (.+)', resource_info)[0]
break
except CalledProcessError:
self.logger.error(
'Unable to fetch resource. Retrying.',
extra={'entity': self.name}
)
sleep(5)
else:
self.logger.error(
'Failed to fetch resource data after creation.',
'Permenant failure fetching resource. Exiting.',
extra={'entity': self.name}
)
exit(2)
......@@ -168,12 +175,14 @@ def main():
parser.add_argument(
'--resource_type',
'-t',
help='The resource type.'
help='The resource type.',
default=''
)
parser.add_argument(
'--description',
'-d',
help='A description of the resource.'
help='A description of the resource.',
default=''
)
parser.add_argument(
'--config',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment