Skip to content
Permalink
Browse files

PRESIDECMS-1501 periodically clear related caches for email sending q…

…ueue while processing

Caches must be manually cleared because they are by-passed by default in our background thread
  • Loading branch information...
DominicWatson committed Mar 13, 2019
1 parent fa25395 commit ae46bd14e93689fa791522d4d938d7dc41f29484
@@ -406,6 +406,39 @@ component extends="resources.HelperObjects.PresideBddTestCase" {
expect( service.$callLog().removeFromQueue[i] ).toBe( [ emails[i].id ] );
}
} );

it( "should manually clear queue query caches because we are bypassing cache due to running in background thread", function(){
var service = _getService();
var rateLimit = 31;
var emails = [];

for( var i=1; i<=40; i++ ) {
emails.append({
id = CreateUUId()
, template = CreateUUId()
, recipient = CreateUUId()
});
}
emails.append({});

service.$( "$getPresideSetting" ).$args( "email", "ratelimit", 100 ).$results( rateLimit );
service.$( "autoQueueScheduledSendouts", 345 );

var resultsList = "";
for( var i=1; i<=emails.len(); i++ ){
resultsList = resultsList.listAppend( "emails[#i#]" );
}
Evaluate( "service.$( ""getNextQueuedEmail"" ).$results( #resultsList# )" );

mockEmailService.$( "send", true );
service.$( "removeFromQueue", 1 );

service.processQueue();
expect( mockPresideObjectService.$callLog().clearRelatedCaches.len() ).toBe( 5 );
for( var log in mockPresideObjectService.$callLog().clearRelatedCaches ) {
expect( log ).toBe( [ "email_mass_send_queue" ] );
}
} );
} );

describe( "autoQueueScheduledSendouts()", function(){
@@ -515,6 +548,7 @@ component extends="resources.HelperObjects.PresideBddTestCase" {
service.$( "$getPresideObjectService", mockPresideObjectService );
service.$( "$isInterrupted", false );
mockPresideObjectService.$( "getDbAdapterForObject", mockDbAdapter );
mockPresideObjectService.$( "clearRelatedCaches" );

mockDbAdapter.$( "getNowFunctionSql", "nowwweee()" );

@@ -54,6 +54,7 @@ component {
var processedCount = 0;
var queuedEmail = "";
var emailService = _getEmailService();
var poService = $getPresideObjectService();

do {
queuedEmail = getNextQueuedEmail();
@@ -73,8 +74,12 @@ component {
}

removeFromQueue( queuedEmail.id );
if ( !processedCount mod 10 ) {
poService.clearRelatedCaches( "email_mass_send_queue" );
}
} while( ++processedCount < rateLimit && !$isInterrupted() );

poService.clearRelatedCaches( "email_mass_send_queue" );
}

/**

0 comments on commit ae46bd1

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.