-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathModuleConfig.cfc
More file actions
143 lines (131 loc) · 5.05 KB
/
ModuleConfig.cfc
File metadata and controls
143 lines (131 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
component {
this.name = "cbq";
this.author = "Eric Peterson";
this.webUrl = "https://github.com/coldbox-modules/cbq";
this.cfmapping = "cbq";
variables.customInterceptionPointMethodNames = "onCBQJobAdded,onCBQJobMarshalled,onCBQJobComplete,onCBQJobException,onCBQJobFailed";
function configure() {
settings = {
// The path the custom config file to register connections and worker pools
"configPath" : "config.cbq",
// Flag if workers should be registered.
// If your application only pushes to the queues, you can set this to `false`.
"registerWorkers" : getSystemSetting( "CBQ_REGISTER_WORKERS", true ),
// The interval to poll for changes to the worker pool scaling.
// Defaults to 0 which turns off the scheduled scaling feature.
"scaleInterval" : 0,
// The default amount of time, in seconds, to delay a job.
// Used if the connection and job doesn't define their own.
"defaultWorkerBackoff" : 0,
// The default amount of time, in seconds, to wait before timing out a job.
// Used if the connection and job doesn't define their own.
"defaultWorkerTimeout" : 60,
// The default amount of time, in seconds, to wait for a connection to shutdown before killing it when requesting a shutdown.
"defaultConnectionShutdownTimeout" : 60,
// The default amount of time, in seconds, to wait for tasks to complete before killing them when requesting a shutdown.
"defaultWorkerShutdownTimeout" : 60,
// The default amount of attempts to try before failing a job.
// Used if the connection and job doesn't define their own.
"defaultWorkerMaxAttempts" : 1,
// Datasource information for tracking batches.
"batchRepositoryProperties" : {
"tableName" : "cbq_batches",
"datasource" : "", // `datasource` can also be a struct
"queryOptions" : {}, // The sibling `datasource` property overrides any defined datasource in queryOptions.
"cleanup" : {
"enabled" : false,
"frequency" : ( task ) => {
task.everyDay();
},
"criteria" : ( qb, currentUnixTimestamp ) => {
qb.where( ( q ) => {
q.where(
"cancelledDate",
"<=",
currentUnixTimestamp - ( 60 * 60 * 24 * 30 )
); // 30 days
q.orWhere(
"completedDate",
"<=",
currentUnixTimestamp - ( 60 * 60 * 24 * 30 )
); // 30 week
} );
}
}
},
// Flag to turn on logging failed jobs to a database table.
"logFailedJobs" : false,
// Datasource information for logging failed jobs.
"logFailedJobsProperties" : {
"tableName" : "cbq_failed_jobs",
"datasource" : "", // `datasource` can also be a struct.
"queryOptions" : {}, // The sibling `datasource` property overrides any defined datasource in `queryOptions`.
"cleanup" : {
"enabled" : false,
"frequency" : ( task ) => {
task.everyDay();
},
"criteria" : ( q, currentUnixTimestamp ) => {
q.where(
"failedDate",
"<=",
currentUnixTimestamp - ( 60 * 60 * 24 * 30 )
); // 30 days
}
}
},
// Flag to allow restricting Job interceptor execution using a `jobPattern` annotation.
"registerJobInterceptorRestrictionAspect" : false
};
interceptorSettings = { "customInterceptionPoints" : variables.customInterceptionPointMethodNames };
interceptors = [ { "class" : "#moduleMapping#.interceptors.LogFailedJobsInterceptor" } ];
}
function afterAspectsLoad() {
variables.wirebox
.registerNewInstance( name = "Config@cbq", instancePath = settings.configPath )
.setVirtualInheritance( "BaseConfig@cbq" )
.setThreadSafe( true )
.setScope( variables.wirebox.getBinder().SCOPES.SINGLETON );
var config = variables.wirebox.getInstance( "Config@cbq" );
config.reset();
config.configure();
// Get ColdBox environment settings and if same convention of 'environment'() found, execute it.
var environment = variables.controller.getSetting( "ENVIRONMENT" );
if ( structKeyExists( config, environment ) ) {
invoke( config, environment );
}
config.registerConnections();
if ( settings.registerWorkers ) {
config.registerWorkerPools();
}
if ( settings.registerJobInterceptorRestrictionAspect ) {
if ( !binder.getListeners().some( ( listener ) => listener.class.contains( "aop.Mixer" ) ) ) {
binder.listener(
class = "coldbox.system.aop.Mixer",
properties = {},
register = true
);
}
binder.mapAspect( "CBQJobInterceptorRestriction" ).to( "#moduleMapping#.models.JobInterceptorRestriction" );
binder.bindAspect(
binder.match().any(),
binder
.match()
.methods( variables.customInterceptionPointMethodNames )
.annotatedWith( "jobPattern" ),
"CBQJobInterceptorRestriction"
);
}
}
function onUnload() {
var config = variables.wirebox.getInstance( "Config@cbq" );
var workerPools = config.getWorkerPools()
for ( var pool in workerPools ) {
workerPools[ pool ].shutdown();
}
var connections = config.getConnections();
for ( var conn in connections ) {
connections[ conn ].shutdown( force = false, timeout = settings.defaultConnectionShutdownTimeout );
}
}
}