def run(self, service_id, **kwargs):
log = self.get_logger(**kwargs)<EOL>log.info("<STR_LIT>")<EOL>try:<EOL><INDENT>service = Service.objects.get(id=service_id)<EOL>log.info("<STR_LIT>" % (service.name))<EOL>status = self.get_health(service.url, service.token)<EOL>try:<EOL><INDENT>result = status.json()<EOL>if (not service.up and result['<STR_LIT>']):<EOL><INDENT>last_up_at = service.get_last_up_time()<EOL>if last_up_at:<EOL><INDENT>downtime = timezone.now() - last_up_at<EOL>fire_metric.apply_async(kwargs={<EOL>"<STR_LIT>": '<STR_LIT>' % (<EOL>utils.normalise_string(service.name)),<EOL>"<STR_LIT>": downtime.seconds // <NUM_LIT><EOL>})<EOL><DEDENT><DEDENT>service.up = result["<STR_LIT>"]<EOL>service.save()<EOL>Status.objects.create(<EOL>service=service,<EOL>up=result["<STR_LIT>"],<EOL>result=result["<STR_LIT:result>"]<EOL>)<EOL>log.info("<STR_LIT>" % (service.name, service.up))<EOL><DEDENT>except Exception:<EOL><INDENT>log.info("<STR_LIT>" % (service.name))<EOL>Status.objects.create(<EOL>service=service,<EOL>up=False,<EOL>result={"<STR_LIT:error>": "<STR_LIT>"}<EOL>)<EOL>service.up = False<EOL>service.save()<EOL><DEDENT>return "<STR_LIT>" % (service.name)<EOL><DEDENT>except ObjectDoesNotExist:<EOL><INDENT>logger.error('<STR_LIT>', exc_info=True)<EOL><DEDENT>except SoftTimeLimitExceeded:<EOL><INDENT>logger.error(<EOL>'<STR_LIT>',<EOL>exc_info=True)<EOL><DEDENT>
Retrieve a status from remote service. Set the up/down state and log.