1 from __future__ import print_function
7 from crunchstat_summary import logger
10 class CollectionReader(object):
11 def __init__(self, collection_id):
12 logger.debug('load collection %s', collection_id)
13 collection = arvados.collection.CollectionReader(collection_id)
14 filenames = [filename for filename in collection]
15 if len(filenames) != 1:
17 "collection {} has {} files; need exactly one".format(
18 collection_id, len(filenames)))
19 self._reader = collection.open(filenames[0])
20 self._label = "{}/{}".format(collection_id, filenames[0])
26 return iter(self._reader)
29 class LiveLogReader(object):
32 def __init__(self, job_uuid):
33 logger.debug('load stderr events for job %s', job_uuid)
34 self.job_uuid = job_uuid
39 def _get_all_pages(self):
43 ['object_uuid', '=', self.job_uuid],
44 ['event_type', '=', 'stderr']]
47 page = arvados.api().logs().index(
50 filters=filters + [['id','>',str(last_id)]],
51 ).execute(num_retries=2)
52 got += len(page['items'])
54 '%s: received %d of %d log events',
56 got + page['items_available'] - len(page['items']))
57 for i in page['items']:
58 for line in i['properties']['text'].split('\n'):
59 self._queue.put(line+'\n')
61 if (len(page['items']) == 0 or
62 len(page['items']) >= page['items_available']):
65 self._queue.put(self.EOF)
68 self._queue = Queue.Queue()
69 self._thread = threading.Thread(target=self._get_all_pages)
70 self._thread.daemon = True
75 line = self._queue.get()