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 select=['id', 'properties'],
52 ).execute(num_retries=2)
53 got += len(page['items'])
55 '%s: received %d of %d log events',
57 got + page['items_available'] - len(page['items']))
58 for i in page['items']:
59 for line in i['properties']['text'].split('\n'):
60 self._queue.put(line+'\n')
62 if (len(page['items']) == 0 or
63 len(page['items']) >= page['items_available']):
66 self._queue.put(self.EOF)
69 self._queue = Queue.Queue()
70 self._thread = threading.Thread(target=self._get_all_pages)
71 self._thread.daemon = True
76 line = self._queue.get()