Skip to content

Commit

Permalink
Merge pull request #15 from jayste/bugfix/schedule-fail-on-new-pipeline
Browse files Browse the repository at this point in the history
fixed schedule failing when requesting new instance and no pipeline
  • Loading branch information
henriquegemignani committed Mar 17, 2017
2 parents 7bb8b8e + d990b66 commit e489a95
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions gocd/api/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,21 @@ def schedule(self, variables=None, secure_variables=None, materials=None,
# TODO: Replace this with whatever is the official way as soon as gocd#990 is fixed.
# https://github.com/gocd/gocd/issues/990
if return_new_instance:
last_run = self.history()['pipelines'][0]['counter']
pipelines = self.history()['pipelines']
if len(pipelines) == 0:
last_run = None
else:
last_run = pipelines[0]['counter']
response = self._post('/schedule', ok_status=202, **scheduling_args)
if not response:
return response

max_tries = 10
while max_tries > 0:
current = self.instance()
if current['counter'] > last_run:
if not last_run and current:
return current
elif last_run and current['counter'] > last_run:
return current
else:
time.sleep(backoff_time)
Expand Down

0 comments on commit e489a95

Please sign in to comment.