mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 14:03:30 +00:00 
			
		
		
		
	scheduled_messages: Remove batching logic.
The previous logic would attempt to send a large number of unrelated messages in a single transaction, which is just asking for trouble in the event that one of the attempts fails.
This commit is contained in:
		@@ -30,12 +30,18 @@ Usage: ./manage.py deliver_scheduled_messages
 | 
				
			|||||||
        try:
 | 
					        try:
 | 
				
			||||||
            while True:
 | 
					            while True:
 | 
				
			||||||
                with transaction.atomic():
 | 
					                with transaction.atomic():
 | 
				
			||||||
                    messages_to_deliver = ScheduledMessage.objects.filter(
 | 
					                    scheduled_message = (
 | 
				
			||||||
                        scheduled_timestamp__lte=timezone_now(), delivered=False
 | 
					                        ScheduledMessage.objects.filter(
 | 
				
			||||||
                    ).select_for_update()
 | 
					                            scheduled_timestamp__lte=timezone_now(), delivered=False
 | 
				
			||||||
                    for scheduled_message in messages_to_deliver:
 | 
					                        )
 | 
				
			||||||
 | 
					                        .select_for_update()
 | 
				
			||||||
 | 
					                        .first()
 | 
				
			||||||
 | 
					                    )
 | 
				
			||||||
 | 
					                    if scheduled_message is not None:
 | 
				
			||||||
                        send_scheduled_message(scheduled_message)
 | 
					                        send_scheduled_message(scheduled_message)
 | 
				
			||||||
 | 
					                        continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                # If there's no overdue scheduled messages, go to sleep until the next minute.
 | 
				
			||||||
                cur_time = timezone_now()
 | 
					                cur_time = timezone_now()
 | 
				
			||||||
                time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0)
 | 
					                time_next_min = (cur_time + timedelta(minutes=1)).replace(second=0, microsecond=0)
 | 
				
			||||||
                sleep_time = (time_next_min - cur_time).total_seconds()
 | 
					                sleep_time = (time_next_min - cur_time).total_seconds()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user