~ursinha/ubuntu-ci-services-itself/401-copying-di-check

« back to all changes in this revision

Viewing changes to branch-source-builder/run_worker

  • Committer: francis.ginther@canonical.com
  • Date: 2014-01-31 17:06:36 UTC
  • mto: This revision was merged to the branch mainline in revision 233.
  • Revision ID: francis.ginther@canonical.com-20140131170636-iwe5o3046phdydo3
Adds dput and ppa watch functionality to the branch source builder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import logging
19
19
import os
20
20
import sys
 
21
import time
21
22
 
 
23
import upload_package
 
24
import watch_ppa
22
25
 
23
26
logging.basicConfig(level=logging.INFO)
24
27
log = logging.getLogger(__name__)
27
30
# and add it, so we can always safely import stuff
28
31
sys.path.append(os.path.join(os.path.dirname(__file__), '../ci-utils'))
29
32
from ci_utils import amqp_utils
30
 
 
 
33
TIME_BETWEEN_CHECKS = 60
31
34
 
32
35
def on_message(msg):
33
 
    log.info('on_message: %s', msg.body)
 
36
    log.info('on_message: {}'.format(msg.body))
34
37
    params = json.loads(msg.body)
35
38
    sources = params['source_packages']
36
39
    ppa = params['ppa']
 
40
    log.info('The PPA is: {}'.format(ppa))
37
41
    trigger = params['progress_trigger']
38
42
    amqp_utils.progress_update(trigger, params)
39
43
 
40
 
    # TODO build stuff
41
 
 
42
 
    if amqp_utils.progress_completed(trigger):
43
 
        log.error('Unable to notify progress-trigger completition of action')
44
 
 
45
 
    # remove from queue so request becomes completed
46
 
    msg.channel.basic_ack(msg.delivery_tag)
 
44
    # TODO Replace these hardcoded parameters with params from the message
 
45
    archive_ppa = 'ppa:ci-engineering-airline/ci-archive'
 
46
    series = 'trusty'
 
47
    try:
 
48
        upload_list = upload_package.upload_source_packages(ppa, sources)
 
49
        log.info('upload_list: {}'.format(upload_list))
 
50
        start_time = time.time()
 
51
        while True:
 
52
            (ret, status) = watch_ppa.watch_ppa(start_time, series, ppa,
 
53
                                                archive_ppa, None,
 
54
                                                upload_list)
 
55
            progress = {}
 
56
            for key in status:
 
57
                progress[key] = str(status[key])
 
58
            log.info('progress: {}'.format(progress))
 
59
            params['status'] = progress
 
60
            amqp_utils.progress_update(trigger, params)
 
61
            if ret == -1:
 
62
                log.info('Going to sleep for {}'.format(TIME_BETWEEN_CHECKS))
 
63
                time.sleep(TIME_BETWEEN_CHECKS)
 
64
            else:
 
65
                log.info('All done')
 
66
                break
 
67
 
 
68
        if amqp_utils.progress_completed(trigger):
 
69
            log.error('Unable to notify progress-trigger completition of action')
 
70
    except EnvironmentError as e:
 
71
        log.error('Exception: {}'.format(e))
 
72
    finally:
 
73
        # remove from queue so request becomes completed
 
74
        log.info('Acking the request: {}'.format(msg.body))
 
75
        msg.channel.basic_ack(msg.delivery_tag)
47
76
 
48
77
 
49
78
if __name__ == '__main__':