@@ -21,14 +21,12 @@ def __init__(self, queue, *handlers):
21
21
self ._thread = None
22
22
23
23
def dequeue (self , block = True ):
24
- """
25
- Dequeue a record and return item.
26
- """
24
+ """Dequeue a record and return item."""
27
25
return self .queue .get (block )
28
26
29
27
def start (self ):
30
- """
31
- Start the listener.
28
+ """Start the listener.
29
+
32
30
This starts up a background thread to monitor the queue for
33
31
items to process.
34
32
"""
@@ -37,17 +35,17 @@ def start(self):
37
35
t .start ()
38
36
39
37
def prepare (self , record ):
40
- """
41
- Prepare a record for handling.
38
+ """Prepare a record for handling.
39
+
42
40
This method just returns the passed-in record. You may want to
43
41
override this method if you need to do any custom marshalling or
44
42
manipulation of the record before passing it to the handlers.
45
43
"""
46
44
return record
47
45
48
46
def handle (self , record ):
49
- """
50
- Handle an item.
47
+ """Handle an item.
48
+
51
49
This just loops through the handlers offering them the record
52
50
to handle.
53
51
"""
@@ -56,15 +54,15 @@ def handle(self, record):
56
54
handler (record )
57
55
58
56
def _monitor (self ):
59
- """
60
- Monitor the queue for items, and ask the handler
61
- to deal with them.
57
+ """Monitor the queue for items, and ask the handler to deal with them.
58
+
62
59
This method runs on a separate, internal thread.
63
60
The thread will terminate if it sees a sentinel object in the queue.
64
61
"""
65
- assert self ._stop .isSet () or not self ._stop_nowait .isSet (), \
66
- "invalid internal state _stop_nowait can not be set " \
67
- "if _stop is not set"
62
+ err_msg = ("invalid internal state:"
63
+ " _stop_nowait can not be set if _stop is not set" )
64
+ assert self ._stop .isSet () or not self ._stop_nowait .isSet (), err_msg
65
+
68
66
q = self .queue
69
67
has_task_done = hasattr (q , 'task_done' )
70
68
while not self ._stop .isSet ():
@@ -92,8 +90,8 @@ def _monitor(self):
92
90
break
93
91
94
92
def stop (self , nowait = False ):
95
- """
96
- Stop the listener.
93
+ """Stop the listener.
94
+
97
95
This asks the thread to terminate, and then waits for it to do so.
98
96
Note that if you don't call this before your application exits, there
99
97
may be some records still left on the queue, which won't be processed.
@@ -114,7 +112,8 @@ def stop(self, nowait=False):
114
112
115
113
class ReportPortalServiceAsync (object ):
116
114
"""Wrapper around service class to transparently provide async operations
117
- to agents."""
115
+ to agents.
116
+ """
118
117
119
118
def __init__ (self , endpoint , project , token , api_base = "api/v1" ,
120
119
error_handler = None , log_batch_size = 20 ):
@@ -142,10 +141,11 @@ def __init__(self, endpoint, project, token, api_base="api/v1",
142
141
self .listener .start ()
143
142
144
143
def terminate (self , nowait = False ):
145
- """
146
- Finalize and stop service
147
- :param nowait: Set to True to terminate imediately and skip processing
148
- messages still in the queue
144
+ """Finalize and stop service
145
+
146
+ Args:
147
+ nowait: set to True to terminate immediately and skip processing
148
+ messages still in the queue
149
149
"""
150
150
logger .debug ("Terminating service" )
151
151
@@ -175,8 +175,8 @@ def _post_log_batch(self):
175
175
self .log_batch = []
176
176
177
177
def process_log (self , ** log_item ):
178
- """
179
- Special handler for log messages.
178
+ """Special handler for log messages.
179
+
180
180
Accumulate incoming log messages and post them in batch.
181
181
"""
182
182
logger .debug ("Processing log item: %s" , log_item )
@@ -185,8 +185,9 @@ def process_log(self, **log_item):
185
185
self ._post_log_batch ()
186
186
187
187
def process_item (self , item ):
188
- """
189
- Main item handler. Called by queue listener.
188
+ """Main item handler.
189
+
190
+ Called by queue listener.
190
191
"""
191
192
logger .debug ("Processing item: %s (queue size: %s)" , item ,
192
193
self .queue .qsize ())
@@ -256,10 +257,11 @@ def finish_test_item(self, end_time, status, issue=None):
256
257
257
258
def log (self , time , message , level = None , attachment = None ):
258
259
"""Logs a message with attachment.
259
- attachment is a dict of:
260
- name: name of attachment
261
- data: file content
262
- mime: content type for attachment
260
+
261
+ The attachment is a dict of:
262
+ name: name of attachment
263
+ data: file content
264
+ mime: content type for attachment
263
265
"""
264
266
logger .debug ("log queued" )
265
267
0 commit comments