From 1c47ab7fbd7eaff85b5a7bf946ccf576f62e5e4c Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 27 Jul 2023 20:26:02 -0500 Subject: [PATCH] Rework outbox delivery --- src/controller/outbox.c | 43 +++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/controller/outbox.c b/src/controller/outbox.c index fcbcc32..698e870 100644 --- a/src/controller/outbox.c +++ b/src/controller/outbox.c @@ -336,35 +336,28 @@ static bool process_pending() int head = fs_list_get("data/outbox/HEAD"); int tail = fs_list_get("data/outbox/TAIL"); bool result = false; - bool do_fork = false; - //for( int i = tail + 1; i <= head; ++i ) { - for( int i = head; i > tail; --i ) { - if( !do_fork || !fork() ) { - struct outbox_envelope* env = outbox_envelope_from_id( i ); - if( !env ) { - // Envelope file doesn't exist, advance tail + + int limit = 10; + for( int i = head; (i > tail ) && ( limit > 0 ); --i ) { + struct outbox_envelope* env = outbox_envelope_from_id( i ); + if( !env ) { + if( i == tail+1 ) { + // Envelope already sent, advance tail fs_list_set( "data/outbox/TAIL", i ); tail += 1; - } else if( env ) { - if( env->sent ) { - if( i == tail+1 ) { - // Envelope already sent, advance tail - fs_list_set( "data/outbox/TAIL", i ); - tail += 1; - } - } else if( process_envelope(env) ) { - printf( "Done with outbox/%d.json\n", i ); - result = true; - } - outbox_envelope_free(env); - } - fflush(stdout); - if( do_fork ) { - exit(EXIT_SUCCESS); + result = true; } } else { - usleep(50000); + if( env->sent ) { + outbox_envelope_delete(env); + } else if( process_envelope(env) ) { + limit -= 1; + printf( "Done with outbox/%d.json\n", i ); + result = true; + outbox_envelope_delete(env); + } } + fflush(stdout); } return result; @@ -377,7 +370,7 @@ void process_outbox() while( !terminate ) { bool activity = false; activity |= process_pending(); - activity |= cleanup_box("data/outbox"); + //activity |= cleanup_box("data/outbox"); if( !activity ) { fflush(stdout);