Retrieve a status from remote service. Set the up/down state and log.

def run(self, service_id, **kwargs):
        """
        Retrieve a status from remote service. Set the up/down state and log.
        """
        log = self.get_logger(**kwargs)

        log.info("Loading Service for healthcheck")
        try:
            service = Service.objects.get(id=service_id)
            log.info("Getting health for <%s>" % (service.name))
            status = self.get_health(service.url, service.token)
            try:
                result = status.json()

                if (not service.up and result['up']):
                    last_up_at = service.get_last_up_time()
                    if last_up_at:
                        downtime = timezone.now() - last_up_at
                        fire_metric.apply_async(kwargs={
                            "metric_name": 'services.downtime.%s.sum' % (
                                utils.normalise_string(service.name)),
                            "metric_value": downtime.seconds // 60
                        })

                service.up = result["up"]
                service.save()
                Status.objects.create(
                    service=service,
                    up=result["up"],
                    result=result["result"]
                )
                log.info("Service <%s> up: <%s>" % (service.name, service.up))
            except Exception:
                # can't decode means there was not a valid response
                log.info("Failed to parse response from <%s>" % (service.name))
                Status.objects.create(
                    service=service,
                    up=False,
                    result={"error": "No parseable response from service"}
                )
                service.up = False
                service.save()
            return "Completed healthcheck for <%s>" % (service.name)
        except ObjectDoesNotExist:
            logger.error('Missing Service', exc_info=True)

        except SoftTimeLimitExceeded:
            logger.error(
                'Soft time limit exceed processing poll of service \
                 via Celery.',
                exc_info=True)