blob: 6998cf3bc34870ccd356d6592e815fadc5c831f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
from celery import shared_task
from jenkins.models import JenkinsSlave, JenkinsStatistic
from .adapter import *
@shared_task
def sync_jenkins():
update_jenkins_slaves()
def update_jenkins_slaves():
jenkins_slaves = get_all_slaves()
for slave in jenkins_slaves:
jenkins_slave, created = JenkinsSlave.objects.get_or_create(name=slave['displayName'],
url=get_slave_url(slave))
jenkins_slave.ci_slave = is_ci_slave(slave['displayName'])
jenkins_slave.dev_pod = is_dev_pod(slave['displayName'])
jenkins_slave.status = get_slave_status(slave)
last_job = get_jenkins_job(jenkins_slave.name)
if last_job is not None:
last_job = parse_job(last_job)
jenkins_slave.last_job_name = last_job['name']
jenkins_slave.last_job_url = last_job['url']
jenkins_slave.last_job_scenario = last_job['scenario']
jenkins_slave.last_job_branch = last_job['branch']
jenkins_slave.last_job_installer = last_job['installer']
jenkins_slave.last_job_result = last_job['result']
jenkins_slave.save()
jenkins_statistic = JenkinsStatistic(slave=jenkins_slave)
if jenkins_slave.status == 'online' or jenkins_slave.status == 'building':
jenkins_statistic.online = True
if jenkins_slave.status == 'offline':
jenkins_statistic.offline = True
if jenkins_slave.status == 'online / idle':
jenkins_statistic.idle = True
jenkins_statistic.save()
|