~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/jobs/store.py

  • Committer: Aaron Bentley
  • Date: 2013-02-12 18:57:02 UTC
  • mfrom: (149 charmworld)
  • mto: This revision was merged to the branch mainline in revision 150.
  • Revision ID: aaron@canonical.com-20130212185702-9gnf40ao17a7uw7v
Merged trunk into mongo-urls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# licensed under the GNU Affero General Public License version 3 (see
3
3
# the file LICENSE).
4
4
 
5
 
from datetime import datetime
6
 
import json
7
5
import logging
8
 
from urllib2 import urlopen
9
6
 
10
7
from config import STORE_IN_QUEUE
11
8
from config import STORE_OUT_QUEUE
12
 
from config import STORE_URL
13
9
from utils import get_queues
14
 
 
15
 
log = logging.getLogger("charm.store")
16
 
 
17
 
 
18
 
def check_store(charm):
19
 
    if charm['owner'] == 'charmers':
20
 
        address = "cs:%s/%s" % (charm["series"], charm["name"])
21
 
    else:
22
 
        address = "cs:~%s/%s/%s" % (
23
 
            charm["owner"], charm["series"], charm["name"])
24
 
 
25
 
    data = _store_get(address)
26
 
 
27
 
    if 'errors' in data or 'warnings' in data:
28
 
        if charm['owner'] == 'charmers':
29
 
            log.info("rechecking %s with ~charmers", address)
30
 
            retry_address = "cs:~%s/%s/%s" % (
31
 
                charm["owner"], charm["series"], charm["name"])
32
 
            retry_data = _store_get(retry_address)
33
 
            if 1:
34
 
# Update the url to the user qualified name.
35
 
#            if not 'errors' in retry_data \
36
 
#               and not 'warnings' in retry_data:
37
 
                data = retry_data
38
 
                address = retry_address
39
 
 
40
 
    if 'errors' in data or 'warnings' in data:
41
 
        log.warning("store error on %s %s" % (address, data))
42
 
 
43
 
    data["store_checked"] = datetime.now().ctime()
44
 
 
45
 
    charm['store_data'] = data
46
 
    charm['store_url'] = address + "-%d" % data['revision']
47
 
 
48
 
 
49
 
def _store_get(address):
50
 
    url = STORE_URL + "/charm-info?charms=%s&stats=0" % address
51
 
    contents = urlopen(url).read()
52
 
    data = json.loads(contents)
53
 
    data = data[address]
54
 
    data['address'] = address
55
 
    return data
56
 
 
57
 
 
58
 
def run(in_queue, out_queue):
59
 
    while 1:
60
 
        item = in_queue.next()
61
 
        if not item:
62
 
            return
63
 
        try:
64
 
            charm_data = item.payload
65
 
            log.debug("Checking store for %s", charm_data["branch_spec"])
66
 
            check_store(charm_data)
67
 
        except Exception, e:
68
 
            log.exception("store error on %s: %s", charm_data, str(e))
69
 
            continue
70
 
        else:
71
 
            out_queue.put(charm_data)
72
 
        finally:
73
 
            # Remove the job from the input queue.
74
 
            item.complete()
 
10
from worker import check_charms_store
75
11
 
76
12
 
77
13
if __name__ == '__main__':
79
15
        level=logging.INFO,
80
16
        format="%(asctime)s: %(name)s@%(levelname)s: %(message)s")
81
17
    in_queue, out_queue = get_queues(STORE_IN_QUEUE, STORE_OUT_QUEUE)
82
 
    run(in_queue, out_queue)
 
18
    check_charms_store(in_queue, out_queue)