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: ...@@ -36,7 +36,6 @@ class Resource:
'type', 'type',
self.resource_type self.resource_type
]) ])
sleep(1)
except CalledProcessError: except CalledProcessError:
self.logger.error( self.logger.error(
'Failed to create resource.', 'Failed to create resource.',
...@@ -44,17 +43,25 @@ class Resource: ...@@ -44,17 +43,25 @@ class Resource:
) )
exit(2) exit(2)
try: for n in range(5):
resource_info = cmd([ try:
self.config['google']['gam_command'], resource_info = cmd([
'info', self.config['google']['gam_command'],
'resource', 'info',
self.resource_id 'resource',
]) self.resource_id
self.email = re.findall(b'Email: (.+)', resource_info)[0] ])
except CalledProcessError: 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( self.logger.error(
'Failed to fetch resource data after creation.', 'Permenant failure fetching resource. Exiting.',
extra={'entity': self.name} extra={'entity': self.name}
) )
exit(2) exit(2)
...@@ -168,12 +175,14 @@ def main(): ...@@ -168,12 +175,14 @@ def main():
parser.add_argument( parser.add_argument(
'--resource_type', '--resource_type',
'-t', '-t',
help='The resource type.' help='The resource type.',
default=''
) )
parser.add_argument( parser.add_argument(
'--description', '--description',
'-d', '-d',
help='A description of the resource.' help='A description of the resource.',
default=''
) )
parser.add_argument( parser.add_argument(
'--config', '--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