Module Async Scheduling
Modules can easily tie in to ColdBox's async scheduling engine by defining a config/Scheduler.cfc file. This file only needs a configure method. Inside the file, you can define tasks to run asynchronously on a schedule and ColdBox will take care of the rest.
1
component {
2
3
property name="settings" inject="coldbox:moduleSettings:unleashsdk";
4
property name="log" inject="logbox:logger:{this}";
5
6
function configure() {
7
task( "unleashsdk-refresh-features" )
8
.call( getInstance( "[email protected]" ), "refreshFeatures" )
9
.every( variables.settings.refreshInterval, "seconds" )
10
.before( function() {
11
if ( log.canDebug() ) {
12
log.debug( "Starting to fetch new features from Unleash" );
13
}
14
} )
15
.onSuccess( function( task, results ) {
16
if ( log.canInfo() ) {
17
log.info( "Successfully refreshed features", results );
18
}
19
} )
20
.onFailure( function( task, exception ) {
21
if ( log.canError() ) {
22
log.error(
23
"Exception when running task [unleashsdk-refresh-features]:",
24
exception
25
);
26
}
27
} );
28
29
task( "unleashsdk-send-metrics" )
30
.call( getInstance( "[email protected]" ), "sendMetrics" )
31
.every( variables.settings.metricsInterval, "seconds" )
32
.delay( variables.settings.metricsInterval, "seconds" )
33
.before( function() {
34
if ( log.canDebug() ) {
35
log.debug( "Starting to send metrics to Unleash" );
36
}
37
} )
38
.onSuccess( function( task, results ) {
39
if ( log.canInfo() ) {
40
log.info(
41
"Successfully sent metrics to Unleash features",
42
results
43
);
44
}
45
} )
46
.onFailure( function( task, exception ) {
47
if ( log.canError() ) {
48
log.error(
49
"Exception when running task [unleashsdk-send-metrics]:",
50
exception
51
);
52
}
53
} );
54
}
55
56
}
Copied!
Copy link
Edit on GitHub