Rework outbox delivery

master
teknomunk 9 months ago
parent 845666b3d5
commit 1c47ab7fbd

@ -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);

Loading…
Cancel
Save