Skip to content

Commit 806efaf

Browse files
committed
COLDBOX-1396
Performance optimizations of the entire scheduler and task registrations
1 parent 586c3da commit 806efaf

8 files changed

Lines changed: 287 additions & 199 deletions

File tree

system/async/executors/ScheduledExecutor.cfc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ component extends="Executor" accessors="true" singleton {
168168
* @method The method on the cfc to call, defaults to "run" (optional)
169169
*/
170170
ScheduledTask function newSchedule( required task, method = "run" ){
171-
return this.newTask( argumentCollection = arguments );
171+
return this.newTask( argumentCollection = arguments )
172172
}
173173

174174
/**
@@ -178,15 +178,17 @@ component extends="Executor" accessors="true" singleton {
178178
* @debug Add debugging logs to System out, disabled by default
179179
* @task The closure or cfc that represents the task (optional)
180180
* @method The method on the cfc to call, defaults to "run" (optional)
181+
* @scheduler The scheduler to set into the task, defaults to this (optional)
181182
*/
182183
ScheduledTask function newTask(
183184
name = "task-#getName()#-#createUUID()#",
184185
debug = false,
185186
task,
186-
method = "run"
187+
method = "run",
188+
scheduler
187189
){
188-
arguments.executor = this;
189-
return new coldbox.system.async.tasks.ScheduledTask( argumentCollection = arguments );
190+
arguments.executor = this
191+
return new coldbox.system.async.tasks.ScheduledTask( argumentCollection = arguments )
190192
}
191193

192194
/****************************************************************

system/async/tasks/ScheduledTask.cfc

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -190,53 +190,59 @@ component accessors="true" {
190190
* @task The closure or cfc that represents the task (optional)
191191
* @method The method on the cfc to call, defaults to "run" (optional)
192192
* @debug Add debugging logs to System out, disabled by default
193+
* @scheduler The scheduler to set into the task (optional)
193194
*/
194195
ScheduledTask function init(
195196
required name,
196197
required executor,
197198
any task = "",
198199
method = "run",
199200
debug = false,
200-
group = ""
201+
group = "",
202+
scheduler
201203
){
202-
// Utility class
203-
variables.util = new coldbox.system.core.util.Util();
204+
// Store scheduler if sent!
205+
if( !isNull( arguments.scheduler ) ){
206+
variables.scheduler = arguments.scheduler
207+
variables.util = variables.scheduler.getUtil()
208+
} else{
209+
variables.util = new coldbox.system.core.util.Util()
210+
}
211+
204212
// Link up the executor and name
205-
variables.executor = arguments.executor;
206-
variables.name = arguments.name;
207-
variables.group = arguments.group;
213+
variables.executor = arguments.executor
214+
variables.name = arguments.name
215+
variables.group = arguments.group
208216
// time unit helper
209-
variables.dateTimeHelper = new coldbox.system.async.time.DateTimeHelper();
210-
variables.timeUnitHelper = new coldbox.system.async.time.TimeUnit();
217+
variables.dateTimeHelper = new coldbox.system.async.time.DateTimeHelper()
218+
variables.timeUnitHelper = new coldbox.system.async.time.TimeUnit()
211219
// Init Properties
212-
variables.task = arguments.task;
213-
variables.method = arguments.method;
220+
variables.task = arguments.task
221+
variables.method = arguments.method
214222
// Default Frequencies
215-
variables.delay = 0;
216-
variables.delayTimeUnit = "";
217-
variables.period = 0;
218-
variables.spacedDelay = 0;
219-
variables.timeUnit = "milliseconds";
220-
variables.noOverlaps = false;
223+
variables.delay = 0
224+
variables.delayTimeUnit = ""
225+
variables.period = 0
226+
variables.spacedDelay = 0
227+
variables.timeUnit = "milliseconds"
228+
variables.noOverlaps = false
221229
// Constraints
222-
variables.annually = false;
223-
variables.debug = arguments.debug;
224-
variables.disabled = false;
225-
variables.whenClosure = "";
226-
variables.dayOfTheMonth = 0;
227-
variables.dayOfTheWeek = 0;
228-
variables.weekends = false;
229-
variables.weekdays = false;
230-
variables.firstBusinessDay = false;
231-
variables.lastBusinessDay = false;
232-
variables.taskTime = "";
233-
variables.startOnDateTime = "";
234-
variables.endOnDateTime = "";
235-
variables.startTime = "";
236-
variables.endTime = "";
237-
variables.scheduled = false;
238-
// Probable Scheduler or not
239-
variables.scheduler = "";
230+
variables.annually = false
231+
variables.debug = arguments.debug
232+
variables.disabled = false
233+
variables.whenClosure = ""
234+
variables.dayOfTheMonth = 0
235+
variables.dayOfTheWeek = 0
236+
variables.weekends = false
237+
variables.weekdays = false
238+
variables.firstBusinessDay = false
239+
variables.lastBusinessDay = false
240+
variables.taskTime = ""
241+
variables.startOnDateTime = ""
242+
variables.endOnDateTime = ""
243+
variables.startTime = ""
244+
variables.endTime = ""
245+
variables.scheduled = false
240246
// Prepare execution tracking stats
241247
variables.stats = {
242248
// Save name just in case
@@ -260,17 +266,17 @@ component accessors="true" {
260266
// If the task has never ran or not
261267
"neverRun" : true,
262268
// Server Host
263-
"inetHost" : variables.util.discoverInetHost(),
269+
"inetHost" : isNull( arguments.scheduler) ? variables.util.discoverInetHost() : arguments.scheduler.getInetHost(),
264270
// Server IP
265-
"localIp" : variables.util.getServerIp()
266-
};
271+
"localIp" : isNull( arguments.scheduler) ? variables.util.getServerIp() : arguments.scheduler.getLocalIp()
272+
}
267273
// Prepare for the user to store metadata
268-
variables.meta = {};
274+
variables.meta = {}
269275
// Life cycle methods
270-
variables.beforeTask = "";
271-
variables.afterTask = "";
272-
variables.onTaskSuccess = "";
273-
variables.onTaskFailure = "";
276+
variables.beforeTask = ""
277+
variables.afterTask = ""
278+
variables.onTaskSuccess = ""
279+
variables.onTaskFailure = ""
274280

275281
debugLog(
276282
"init",
@@ -280,9 +286,9 @@ component accessors="true" {
280286
method : variables.method,
281287
debug : variables.debug
282288
}
283-
);
289+
)
284290

285-
return this;
291+
return this
286292
}
287293

288294
/**

0 commit comments

Comments
 (0)