Skip to content
Permalink
Browse files

PRESIDECMS-1732 allow configuration of heartbeat host names

Also tidy up 'setlastrun() in heartbeats to be only in one place
  • Loading branch information...
DominicWatson committed Nov 8, 2019
1 parent e486c46 commit c520efbf96435b18221cb6e7a77f7ffb5e510c62
@@ -34,7 +34,7 @@
"cbstorages":"1.3.0+14",
"cbjavaloader":"1.5.0+35",
"coldbox":"5.4.0",
"cfconcurrent":"2.1.2"
"cfconcurrent":"2.1.3"
},
"devDependencies":{
"testbox":"2.7.0"
@@ -512,6 +512,23 @@ component {
, derivativeGenerator = "derivativeGeneratorService"
};

settings.heartbeats = {
defaultHostname = settings.env.DEFAULT_HEARTBEAT_HOSTNAME ?: cgi.server_name
, assetQueue = {}
, cacheBoxReap = {}
, healthCheck = {}
, adhocTask = {}
, taskmanager = {}
, emailQueue = {}
};

settings.heartbeats.assetQueue.hostname = settings.env.ASSETQUEUE_HEARTBEAT_HOSTNAME ?: settings.heartbeats.defaultHostname;
settings.heartbeats.adhocTask.hostname = settings.env.ADHOCTASK_HEARTBEAT_HOSTNAME ?: settings.heartbeats.defaultHostname;
settings.heartbeats.taskmanager.hostname = settings.env.TASKMANAGER_HEARTBEAT_HOSTNAME ?: settings.heartbeats.defaultHostname;
settings.heartbeats.emailQueue.hostname = settings.env.EMAILQUEUE_HEARTBEAT_HOSTNAME ?: settings.heartbeats.defaultHostname;
settings.heartbeats.cacheBoxReap.hostname = settings.env.CACHEBOXREAP_HEARTBEAT_HOSTNAME ?: settings.heartbeats.defaultHostname;
settings.heartbeats.healthCheck.hostname = settings.env.HEALTHCHECK_HEARTBEAT_HOSTNAME ?: settings.heartbeats.defaultHostname;

_loadConfigurationFromExtensions();

environments = {
@@ -8,25 +8,27 @@ component {
// CONSTRUCTOR
/**
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
*
*/
public any function init(
required string threadName
, required numeric intervalInMs
, required any scheduledThreadpoolExecutor
, string feature = ""
, string feature = ""
, string hostname = cgi.server_name
) {
_setThreadName( arguments.threadName );
_setIntervalInMs( arguments.intervalInMs );
_setScheduledThreadpoolExecutor( arguments.scheduledThreadpoolExecutor );
_setFeature( arguments.feature );
_setHostname( arguments.hostname );

return this;
}

public void function run() {
$getRequestContext().autoSetSiteByHost();
$run();
setLastRun();
}

public void function $run() {
@@ -51,11 +53,12 @@ component {
, initialDelay = 0
, period = _getIntervalInMs()
, timeUnit = tpe.getObjectFactory().MILLISECONDS
, hostname = _getHostname()
);

setStartTime();

$systemOutput( "Started #_getThreadName()# heartbeat." );
$systemOutput( "Started #_getThreadName()# heartbeat with hostname: #_getHostname()#" );

_setTaskFuture( taskFuture );
}
@@ -153,4 +156,11 @@ component {
private void function _setTaskFuture( required any taskFuture ) {
_taskFuture = arguments.taskFuture;
}

private string function _getHostname() {
return _hostname;
}
private void function _setHostname( required string hostname ) {
_hostname = arguments.hostname;
}
}
@@ -8,17 +8,20 @@ component extends="AbstractHeartBeat" {
/**
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
* @assetQueueService.inject presidecms:dynamicservice:assetQueue
* @hostname.inject coldbox:setting:heartbeats.assetqueue.hostname
*
*/
public function init(
required any scheduledThreadpoolExecutor
, required any assetQueueService
, required string hostname
, numeric instanceNumber = 1
, string threadName = "Preside Asset Queue Processor #arguments.instanceNumber#"
){
super.init(
threadName = arguments.threadName
, scheduledThreadpoolExecutor = arguments.scheduledThreadpoolExecutor
, hostname = arguments.hostname
, intervalInMs = 2000
, feature = "assetQueueHeartBeat"
);
@@ -38,8 +41,6 @@ component extends="AbstractHeartBeat" {
} catch( any e ) {
$raiseError( e );
}

setLastRun();
}

// GETTERS AND SETTERS
@@ -8,18 +8,21 @@ component extends="AbstractHeartBeat" {
/**
* @cachebox.inject cachebox
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
* @hostname.inject coldbox:setting:heartbeats.cacheboxreap.hostname
*
*/
public function init(
required any scheduledThreadpoolExecutor
, required any cachebox
, required string hostname
, string threadName = "Preside Cache Reap Heartbeat"
){
_setCachebox( arguments.cachebox );

super.init(
threadName = arguments.threadName
, scheduledThreadpoolExecutor = arguments.scheduledThreadpoolExecutor
, hostname = arguments.hostname
, intervalInMs = ( 1000 * 60 ) // 1 minutes
);

@@ -37,7 +40,6 @@ component extends="AbstractHeartBeat" {
} catch( any e ) {
$raiseError( e );
}
setLastRun();
}

// GETTERS AND SETTERS
@@ -8,19 +8,22 @@ component extends="AbstractHeartBeat" {
/**
* @healthCheckService.inject healthCheckService
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
* @hostname.inject coldbox:setting:heartbeats.healthcheck.hostname
*
*/
public function init(
required any healthCheckService
, required any scheduledThreadpoolExecutor
, required string serviceId
, required numeric intervalInMs
, required string hostname
, string threadName = "Preside Service Healthcheck: #arguments.serviceId#"
){
super.init(
threadName = arguments.threadName
, scheduledThreadpoolExecutor = arguments.scheduledThreadpoolExecutor
, intervalInMs = arguments.intervalInMs
, hostname = arguments.hostname
, feature = "healthchecks"
);

@@ -43,7 +46,6 @@ component extends="AbstractHeartBeat" {
} catch( any e ) {
$raiseError( e );
}
setLastRun();
}

// GETTERS AND SETTERS
@@ -8,14 +8,19 @@ component extends="AbstractHeartBeat" {
/**
* @adhocTaskmanagerService.inject adhocTaskmanagerService
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
*
* @hostname.inject coldbox:setting:heartbeats.adhoctask.hostname
*/
public function init( required any adhocTaskmanagerService, required any scheduledThreadpoolExecutor ){
public function init(
required any adhocTaskmanagerService
, required any scheduledThreadpoolExecutor
, required string hostname
){
super.init(
threadName = "Preside Heartbeat: Adhoc Tasks"
, intervalInMs = 1000
, scheduledThreadpoolExecutor = arguments.scheduledThreadpoolExecutor
, feature = "adhocTaskHeartBeat"
, hostname = arguments.hostname
);

_setAdhocTaskmanagerService( arguments.adhocTaskmanagerService );
@@ -30,8 +35,6 @@ component extends="AbstractHeartBeat" {
} catch( any e ) {
$raiseError( e );
}

setLastRun();
}


@@ -8,11 +8,12 @@ component extends="AbstractHeartBeat" {
/**
* @emailMassSendingService.inject emailMassSendingService
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
*
* @hostname.inject coldbox:setting:heartbeats.emailqueue.hostname
*/
public function init(
required any emailMassSendingService
, required any scheduledThreadpoolExecutor
, required string hostname
, numeric instanceNumber = 1
, string threadName = "Preside Email Queue Processor #arguments.instanceNumber#"
){
@@ -21,6 +22,7 @@ component extends="AbstractHeartBeat" {
, scheduledThreadpoolExecutor = arguments.scheduledThreadpoolExecutor
, intervalInMs = 5000
, feature = "emailQueueHeartBeat"
, hostname = arguments.hostname
);

_setInstanceNumber( arguments.instanceNumber );
@@ -40,8 +42,6 @@ component extends="AbstractHeartBeat" {
} catch( any e ) {
$raiseError( e );
}

setLastRun();
}

// GETTERS AND SETTERS
@@ -9,14 +9,20 @@ component extends="AbstractHeartBeat" {
/**
* @taskmanagerService.inject taskmanagerService
* @scheduledThreadpoolExecutor.inject presideScheduledThreadpoolExecutor
* @hostname.inject coldbox:setting:heartbeats.taskmanager.hostname
*
*/
public function init( required any taskmanagerService, required any scheduledThreadpoolExecutor ){
public function init(
required any taskmanagerService
, required any scheduledThreadpoolExecutor
, required string hostname
){
super.init(
threadName = "Preside Heartbeat: Scheduled Tasks"
, intervalInMs = 1000
, scheduledThreadpoolExecutor = arguments.scheduledThreadpoolExecutor
, feature = "taskmanagerHeartBeat"
, hostname = arguments.hostname
);

_setTaskmanagerService( arguments.taskmanagerService );
@@ -36,8 +42,6 @@ component extends="AbstractHeartBeat" {
} catch( any e ) {
$raiseError( e );
}

setLastRun();
}


@@ -13,7 +13,7 @@ component displayName="Ad-hoc Task Manager Service" {
* @siteService.inject siteService
* @threadUtil.inject threadUtil
* @logger.inject logbox:logger:taskmanager
* @executor.inject presideTaskManagerExecutor
* @executor.inject presideAdhocTaskManagerExecutor
*/
public any function init(
required any siteService
@@ -0,0 +1,15 @@
/**
* @singleton true
* @presideService true
*
*/
component extends="PresideTaskManagerExecutor" {
/**
* @hostname.inject coldbox:setting:heartbeats.adhocTask.hostname
*
*/
public any function init( required string hostname ) {
return super.init( argumentCollection=arguments )
}

}
@@ -5,16 +5,27 @@
*/
component extends="cfconcurrent.ExecutorService" {

public any function init() {
/**
* @hostname.inject coldbox:setting:heartbeats.taskmanager.hostname
*
*/
public any function init( required string hostname ) {
var appName = _getAppName();

_setHostname( arguments.hostName );

return super.init(
serviceName = "PresideTaskManagerThreadPool-#appName#"
, maxConcurrent = 0
, threadNamePattern = "PresideTaskManagerThreadPool-#appName#-${poolno}-Thread-${threadno}"
);
}

// submit, passing hostname set in config
public function submit( task, hostname=_getHostName() ) {
return super.submit( argumentCollection=arguments );
}

// shutdown behaviour for when application is reloading
public void function shutdown( ){
super.stop();
@@ -27,4 +38,12 @@ component extends="cfconcurrent.ExecutorService" {
return appSettings.PRESIDE_APPLICATION_ID ?: ( appSettings.name ?: "" );
}

// getters and setters
private string function _getHostname() {
return _hostname;
}
private void function _setHostname( required string hostname ) {
_hostname = arguments.hostname;
}

}

0 comments on commit c520efb

Please sign in to comment.
You can’t perform that action at this time.