Simone
06/30/2023, 3:12 PMTim
06/30/2023, 3:16 PMTim
06/30/2023, 3:17 PMonComplete
attribute to set up chained tasks.Simone
06/30/2023, 3:17 PMSimone
06/30/2023, 3:20 PMTim
06/30/2023, 3:25 PMcfschedule(action="create", task="child5", url="path/to/a/cfm");
cfschedule(action="create", task="child4", url="path/to/a/cfm" onComplete="child5");
cfschedule(action="create", task="child3", url="path/to/a/cfm" onComplete="child4");
cfschedule(action="create", task="child2", url="path/to/a/cfm" onComplete="child3");
cfschedule(action="create", task="child1", url="path/to/a/cfm" onComplete="child2");
cfschedule(action="create", task="parent", url="path/to/a/cfm" onComplete="child1" cron="0 0 0 * * ?");
Tim
06/30/2023, 3:26 PMonComplete
, but just in case, that's why I defined them backwards.Simone
06/30/2023, 3:29 PMSimone
06/30/2023, 3:30 PM<cfset scheduledFiles = ["file1.cfm", "file2.cfm", "file3.cfm", "file4.cfm", "file5.cfm", "file6.cfm", "file7.cfm", "file8.cfm", "file9.cfm", "file10.cfm"]>
<cfset startDate = now()>
<cfloop index="i" from="1" to="10">
<cfset taskName = "Task" & i>
<cfset scheduledFile = scheduledFiles[i]>
<cfscript>
taskService = createObject("java", "coldfusion.server.ServiceFactory").getTaskService();
taskService.createTask(taskName, scheduledFile, "0 0 */1 * * ?", startDate);
</cfscript>
</cfloop>
now 1 want file1.cfm should run on oncomplete and run others one after anotherTim
06/30/2023, 3:41 PM<cfscript>
scheduledFiles = ["file1.cfm", "file2.cfm", "file3.cfm", "file4.cfm", "file5.cfm", "file6.cfm", "file7.cfm", "file8.cfm", "file9.cfm", "file10.cfm"];
startDate = now();
for(i = 1; i <= scheduledFiles.len(); i++) {
attributeColletion = {
action: "create",
task: "Task#i#,
url: scheduledFiles[i],
startDate: startDate
};
if( i == 1 ) {
attributeCollection.cronTime = "0 0 */1 * * ?";
}
if( i != scheduledFiles.len() ) {
attributeCollection.onComplete = "Task#i+1#";
}
cfschedule(attributeCollection=attributeCollection);
}
</cfscript>
Tim
06/30/2023, 3:42 PMTim
06/30/2023, 3:46 PMoncomplete
for all but the last one, and to have the schedule info on only the first one.Simone
06/30/2023, 7:59 PMSimone
06/30/2023, 7:59 PMSimone
06/30/2023, 8:01 PMSimone
06/30/2023, 8:01 PMTim
06/30/2023, 8:13 PM<cfloop index="i" from="1" to="#ArrayLen(scheduledFiles)#">
I think.bkbk
07/03/2023, 8:27 AMSimone
07/04/2023, 12:38 PMcfschedule sucks, it oes not work with attributecollection
Simone
07/04/2023, 1:00 PM<cfset scheduledFiles = ["File1.cfm", "File2.cfm", "File3.cfm", "File4.cfm", "File5.cfm", "File6.cfm"]>
<cfset startDate = DateFormat(DateAdd('d',-1,now()),'mm/dd/yyyy')>
<cfloop index="i" from="1" to="#ArrayLen(scheduledFiles)#">
<cfschedule action="create" task= "#scheduledFiles[i]#"
url= "#application.servername##scheduledFiles[i]#"
startDate= "#startDate#"
starttime='#timeFormat(dateAdd("s", 30, now()), "HH:mm:ss")#'
group="iO"
username="admin"
password="admin">
<cfif i eq 1>
<cfschedule action="update" task= "#scheduledFiles[i]#"
url= "#application.servername##scheduledFiles[i]#"
startDate= "#startDate#"
starttime='#timeFormat(dateAdd("s", 30, now()), "HH:mm:ss")#'
group="iO"
username="admin"
password="admin"
>
</cfif>
<cfif i neq ArrayLen(scheduledFiles)>
<cfschedule action="update" task= "#scheduledFiles[i]#"
url= "#application.servername##scheduledFiles[i]#"
startDate= "#startDate#"
starttime='#timeFormat(dateAdd("s", 30, now()), "HH:mm:ss")#'
group="iO"
username="admin"
password="admin"
>
</cfif>
</cfloop>
Simone
07/04/2023, 1:00 PMMonte Chan
07/04/2023, 2:22 PMSimone
07/04/2023, 3:13 PMSimone
07/04/2023, 3:13 PMMonte Chan
07/04/2023, 3:17 PMSimone
07/04/2023, 3:17 PMMonte Chan
07/04/2023, 3:18 PMSimone
07/04/2023, 3:19 PMSimone
07/04/2023, 3:19 PMSimone
07/04/2023, 3:19 PMSimone
07/04/2023, 3:21 PMSimone
07/04/2023, 3:21 PMTim
07/05/2023, 12:50 AMSimone
07/05/2023, 2:19 AMTim
07/05/2023, 2:22 AMMonte Chan
07/05/2023, 2:23 AMMonte Chan
07/05/2023, 2:38 AMSimone
07/05/2023, 3:17 AMMonte Chan
07/05/2023, 3:27 AMMonte Chan
07/05/2023, 3:28 AMbkbk
07/05/2023, 6:39 AMbkbk
07/05/2023, 6:54 AM@Simone: "is there a way i can write some other way so the tasks should run after the one has been completed,"
Yes. Suppose you know that the maximum time each task will run for is 1 hour. Then you could just manually create tasks whose start-date/start-times are 1 hour and 5 minutes apart.
And how to create the tasks manually without writing a single line of code? See my earlier suggestion.lmajano
07/05/2023, 9:14 AMJohn Wilson
07/05/2023, 6:00 PMSimone
07/05/2023, 7:34 PMSimone
07/05/2023, 7:35 PMJohn Wilson
07/05/2023, 7:40 PMCreate/update task ( run this once on startup for every task you want to define ) -
cfschedule(
action = "update",
task = "GenerateAlerts",
operation = "HTTPRequest",
startDate = "5/12/2016",
startTime="6:00 AM",
endTime="6:00 PM",
interval="300",
url = "<http://localhost:5000/generate/alerts>",
path = expandPath("/logs"),
file = "generateAlerts.htm",
requesttimeout = "600"
);
Then in the GenerateAlerts task, if you wanted to run generateAlerts2, you would:
cfschedule( action = "run", task = "GenerateAlerts2" );
https://cfdocs.org/cfscheduleSimone
07/06/2023, 2:25 AMSimone
07/06/2023, 2:26 AMMonte Chan
07/06/2023, 3:35 PMSimone
07/06/2023, 4:33 PMSimone
07/06/2023, 4:33 PMSimone
07/06/2023, 4:33 PMSimone
07/07/2023, 2:06 AM<!--- Query the database to fetch the pending tasks --->
<cfquery name="getPendingTasks" datasource="yourDataSource">
SELECT * FROM tasks WHERE status = 'pending'
</cfquery>
<!--- Loop through the pending tasks --->
<cfloop query="getPendingTasks">
<!--- Perform the task and check if it succeeds --->
<cfset taskSucceeded = performTask(currentRow.taskId)>
<!--- Update the task status and schedule time based on success --->
<cfif taskSucceeded>
<cfset newStatus = 'complete'>
<cfset newScheduleTime = DateAdd('h', 1, currentRow.scheduleTime)>
<cfelse>
<cfset newStatus = 'pending'>
<cfset newScheduleTime = currentRow.scheduleTime>
</cfif>
<!--- Update the task in the database with the new status and schedule time --->
<cfquery name="updateTask" datasource="yourDataSource">
UPDATE tasks
SET status = <cfqueryparam value="#newStatus#" cfsqltype="cf_sql_varchar">,
scheduleTime = <cfqueryparam value="#newScheduleTime#" cfsqltype="cf_sql_timestamp">
WHERE taskId = <cfqueryparam value="#currentRow.taskId#" cfsqltype="cf_sql_integer">
</cfquery>
</cfloop>
performTask is a function which will perform task one after the other like cfschedule run because i have created those tasks in the cfschedular and every task runs and give me status of true/false, just wondering i have to wait for the results to return adn move to next step, should i use some threads or how, this is freajking very confusing nowbkbk
07/07/2023, 8:13 AMSimone
07/07/2023, 11:44 AMSimone
07/07/2023, 11:45 AMSimone
07/07/2023, 11:46 AMSimone
07/07/2023, 12:21 PM<cffunction name="performTask">
<cfargument name="taskID" required="true" default="">
<cfargument name="taskName" required="true" default="">
<cfschedule action="run" task="#arguments.taskName#">
</cffunction>
Simone
07/07/2023, 12:44 PMSimone
07/07/2023, 2:29 PMSimone
07/08/2023, 12:18 AM<cfthread action="run" name="performTaskThread#taskId#">
<cfset taskSucceeded = performTask(taskURL,taskName)>
</cfthread>