def polling_event_loop(): time.sleep(1) while True: try: r = requests.post('http://127.0.0.1:5000/refresh_github_state', timeout=360) r.raise_for_status() r = requests.post('http://127.0.0.1:5000/refresh_batch_state', timeout=360) r.raise_for_status() r = requests.post('http://127.0.0.1:5000/heal', timeout=360) r.raise_for_status() except Exception as e: log.error(f'Could not poll due to exception: {e}') time.sleep(REFRESH_INTERVAL_IN_SECONDS)
def polling_event_loop(): time.sleep(1) while True: try: r = requests.post( 'http://127.0.0.1:5000/refresh_github_state', timeout=360) r.raise_for_status() r = requests.post( 'http://127.0.0.1:5000/refresh_batch_state', timeout=360) r.raise_for_status() r = requests.post('http://127.0.0.1:5000/heal', timeout=360) r.raise_for_status() except Exception as e: log.error(f'Could not poll due to exception: {e}') time.sleep(REFRESH_INTERVAL_IN_SECONDS)
def refresh_from_batch_job(self, job): state = job.cached_status()['state'] if state == 'Complete': return self.update_from_completed_batch_job(job) elif state == 'Cancelled': log.error( f'a job for me was cancelled {short_str_build_job(job)} {self.short_str()}') job.delete() return self._new_build(try_new_build(self.source, self.target)) else: assert state == 'Created', f'{state} {job.id} {job.attributes} {self.short_str()}' assert 'target' in job.attributes, job.attributes assert 'image' in job.attributes, job.attributes target = FQSHA.from_json(json.loads(job.attributes['target'])) image = job.attributes['image'] if target == self.target: return self._new_build(Building(job, image, target.sha)) else: log.info(f'found deploy job {job.id} for wrong target {target}, should be {self.target}') job.delete() return self
def deploy_build_finished(self, target, job): assert isinstance(target, FQSHA) assert isinstance(job, Job), f'{job.id} {job.attributes}' expected_job = self.deploy_jobs.get(target.ref, None) if expected_job is None: log.error(f'notified of unexpected deploy job {job.id} (I am not waiting ofr any for {target.short_str()})') return if expected_job.id != job.id: log.error(f'notified of unexpected deploy job {job.id}, expected {expected_job.id} for {target.short_str()}') return assert job.cached_status()['state'] == 'Complete' exit_code = job.cached_status()['exit_code'] del self.deploy_jobs[target.ref] if exit_code != 0: log.error(f'deploy job {job.id} failed for {target.short_str()}') else: log.info(f'deploy job {job.id} succeeded for {target.short_str()}') self.latest_deployed[target.ref] = target.sha job.delete()