mirror of
https://github.com/status-im/cabot.git
synced 2025-02-25 02:45:16 +00:00
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from os import environ as env
|
|
|
|
from django.conf import settings
|
|
import requests
|
|
from datetime import datetime
|
|
from django.utils import timezone
|
|
from celery.utils.log import get_task_logger
|
|
|
|
logger = get_task_logger(__name__)
|
|
|
|
auth = (settings.JENKINS_USER, settings.JENKINS_PASS)
|
|
|
|
|
|
def get_job_status(jobname):
|
|
ret = {
|
|
'active': True,
|
|
'succeeded': False,
|
|
'blocked_build_time': None,
|
|
'status_code': 200
|
|
}
|
|
endpoint = settings.JENKINS_API + 'job/%s/api/json' % jobname
|
|
resp = requests.get(endpoint, auth=auth, verify=True)
|
|
status = resp.json
|
|
ret['status_code'] = resp.status_code
|
|
if status['color'].startswith('blue'):
|
|
ret['active'] = True
|
|
ret['succeeded'] = True
|
|
elif status['color'] == 'disabled':
|
|
ret['active'] = False
|
|
ret['succeeded'] = False
|
|
if status['queueItem'] and status['queueItem']['blocked']:
|
|
time_blocked_since = datetime.utcfromtimestamp(
|
|
float(status['queueItem']['inQueueSince']) / 1000).replace(tzinfo=timezone.utc)
|
|
ret['blocked_build_time'] = (timezone.now() - time_blocked_since).total_seconds()
|
|
return ret
|