@@ -317,102 +317,61 @@ def _cleanup(self):
317317 mailman_log ('qrunner' , 'IncomingRunner._cleanup: Cleanup complete' )
318318
319319 def _oneloop (self ):
320- mailman_log ( 'qrunner' , 'IncomingRunner._oneloop: Starting loop' )
320+ """Process one batch of messages from the incoming queue."""
321321 # First, list all the files in our queue directory.
322322 # Switchboard.files() is guaranteed to hand us the files in FIFO
323323 # order. Return an integer count of the number of files that were
324324 # available for this qrunner to process.
325- files = self ._switchboard .files ()
326- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Found %d files to process' , len (files ))
327-
328- for filebase in files :
329- try :
330- # Log that we're starting to process this file
331- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Starting to process queue file: %s' , filebase )
332-
333- # Ask the switchboard for the message and metadata objects
334- # associated with this filebase.
325+ try :
326+ # Get the list of files to process
327+ files = self ._switchboard .files ()
328+ filecnt = len (files )
329+
330+ # Only log at debug level if we found files to process
331+ if filecnt > 0 :
332+ mailman_log ('debug' , 'IncomingRunner._oneloop: Found %d files to process' , filecnt )
333+
334+ # Process each file
335+ for filebase in files :
335336 try :
337+ # Dequeue the file
336338 msg , msgdata = self ._switchboard .dequeue (filebase )
337- if msg is None or msgdata is None :
338- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Failed to dequeue file %s - invalid message data' , filebase )
339- # Move to shunt queue
340- try :
341- src = os .path .join (self ._switchboard .whichq (), filebase + '.bak' )
342- dst = os .path .join (mm_cfg .BADQUEUE_DIR , filebase + '.psv' )
343- if not os .path .exists (mm_cfg .BADQUEUE_DIR ):
344- os .makedirs (mm_cfg .BADQUEUE_DIR , 0o770 )
345- os .rename (src , dst )
346- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Moved invalid file to shunt queue: %s -> %s (reason: null message or metadata)' , filebase , dst )
347- except Exception as e :
348- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Failed to move invalid file to shunt queue: %s' , str (e ))
339+ if msg is None :
349340 continue
350341
351- mailman_log ('qrunner ' , 'IncomingRunner._oneloop: Successfully dequeued file %s' , filebase )
342+ mailman_log ('info ' , 'IncomingRunner._oneloop: Successfully dequeued file %s' , filebase )
352343
353- # Validate message data structure
354- if not isinstance (msgdata , dict ):
355- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Invalid message data structure for file %s: expected dict, got %s' ,
356- filebase , type (msgdata ))
357- # Move to shunt queue
358- try :
359- src = os .path .join (self ._switchboard .whichq (), filebase + '.bak' )
360- dst = os .path .join (mm_cfg .BADQUEUE_DIR , filebase + '.psv' )
361- if not os .path .exists (mm_cfg .BADQUEUE_DIR ):
362- os .makedirs (mm_cfg .BADQUEUE_DIR , 0o770 )
363- os .rename (src , dst )
364- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Moved invalid file to shunt queue: %s -> %s (reason: invalid message data structure)' , filebase , dst )
365- except Exception as e :
366- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Failed to move invalid file to shunt queue: %s' , str (e ))
367- continue
344+ # Process the message
345+ try :
346+ # Get the list name from the message data
347+ listname = msgdata .get ('listname' , mm_cfg .MAILMAN_SITE_LIST )
348+
349+ # Process the message
350+ result = self ._dispose (listname , msg , msgdata )
351+
352+ # If the message should be kept in the queue, requeue it
353+ if result :
354+ self ._switchboard .enqueue (msg , msgdata )
355+ mailman_log ('info' , 'IncomingRunner._oneloop: Message requeued for later processing: %s' , filebase )
356+ else :
357+ mailman_log ('info' , 'IncomingRunner._oneloop: Message processing complete, moving to shunt queue %s (msgid: %s)' ,
358+ filebase , msg .get ('message-id' , 'n/a' ))
359+
360+ except Exception as e :
361+ mailman_log ('error' , 'IncomingRunner._oneloop: Error processing message: %s\n %s' ,
362+ str (e ), traceback .format_exc ())
363+ # Move to shunt queue on error
364+ self ._shunt .enqueue (msg , msgdata )
368365
369- # Validate required message data fields
370- required_fields = ['listname' ]
371- missing_fields = [field for field in required_fields if field not in msgdata ]
372- if missing_fields :
373- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Missing required fields in message data for file %s: %s' ,
374- filebase , ', ' .join (missing_fields ))
375- # Move to shunt queue
376- try :
377- src = os .path .join (self ._switchboard .whichq (), filebase + '.bak' )
378- dst = os .path .join (mm_cfg .BADQUEUE_DIR , filebase + '.psv' )
379- if not os .path .exists (mm_cfg .BADQUEUE_DIR ):
380- os .makedirs (mm_cfg .BADQUEUE_DIR , 0o770 )
381- os .rename (src , dst )
382- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Moved invalid file to shunt queue: %s -> %s (reason: missing required fields: %s)' ,
383- filebase , dst , ', ' .join (missing_fields ))
384- except Exception as e :
385- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Failed to move invalid file to shunt queue: %s' , str (e ))
386- continue
387-
388366 except Exception as e :
389- mailman_log ('qrunner ' , 'IncomingRunner._oneloop: Failed to dequeue file %s: %s' , filebase , str ( e ))
390- continue
367+ mailman_log ('error ' , 'IncomingRunner._oneloop: Error dequeuing file %s: %s\n %s' ,
368+ filebase , str ( e ), traceback . format_exc ())
391369
392- # Process the message
393- more = self ._dispose (msgdata ['listname' ], msg , msgdata )
394- if more :
395- # The message needs more processing, so enqueue it at the
396- # end of the self._switchboard's queue.
397- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Message needs more processing, requeuing %s' , filebase )
398- self ._switchboard .enqueue (msg , msgdata )
399- else :
400- # The message is done being processed by this qrunner, so
401- # shunt it off to the next queue.
402- msgid = msg .get ('message-id' , 'n/a' )
403- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Message processing complete, moving to shunt queue %s (msgid: %s)' , filebase , msgid )
404- self ._shunt .enqueue (msg , msgdata )
405- except Exception as e :
406- # Log the error and requeue the message for later processing
407- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Error processing queue file %s: %s\n %s' ,
408- filebase , str (e ), traceback .format_exc ())
409- if msg is not None and msgdata is not None :
410- try :
411- self ._switchboard .enqueue (msg , msgdata )
412- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Successfully requeued file %s' , filebase )
413- except Exception as e2 :
414- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Failed to requeue file %s: %s' , filebase , str (e2 ))
415-
416- mailman_log ('qrunner' , 'IncomingRunner._oneloop: Loop complete, processed %d files' , len (files ))
417- return len (files )
370+ # Only log completion at debug level if we processed files
371+ if filecnt > 0 :
372+ mailman_log ('debug' , 'IncomingRunner._oneloop: Loop complete, processed %d files' , filecnt )
373+
374+ except Exception as e :
375+ mailman_log ('error' , 'IncomingRunner._oneloop: Unexpected error in main loop: %s\n %s' ,
376+ str (e ), traceback .format_exc ())
418377
0 commit comments