Question :
Is there any way to check that scheduled task is already created? If not already exists create new one.
Code :
<!--- 1. By
using cfobject --->
<cfobject type="JAVA" action="Create" name="Service_factory" class="coldfusion.server.ServiceFactory">
<cfset Service_factory
= CreateObject("java", "coldfusion.server.ServiceFactory") />
<cfset
Scheduled_Tasks_Array = Service_factory.CronService.listAll() />
<cfdump var="#Scheduled_Tasks_Array#" />
<!--- 2. By
Using create object function --->
<cfdump var="#createobject("java","coldfusion.server.ServiceFactory").CronService.listAll()#" />
<!--- 3.By
reading the XML file neo-cron.xml--->
<cffile action="Read"
file="#Server.ColdFusion.RootDir#\lib\neo-cron.xml"
variable="TaskXML">
<!--- Convert
the WDDX to CFML - and array of structs --->
<cfwddx action="WDDX2CFML" input="#TaskXML#" output="Scheduled_Tasks_Array">
<!--- Dump all
the schedule tasks in CF Admin in Struct format. --->
<cfdump var="#Scheduled_Tasks_Array#" />
<cfif arraylen(Scheduled_Tasks_Array)
EQ 0>
<cfschedule
action = "update"
task = "test schedule 1"
startDate = "01/01/2013"
startTime = "00:00:00"
url = "www.google.com"
interval = "900"
operation = "HTTPRequest"
>
</cfif>
Output :

All the scheduled task data get stored in the XML file at the following location -
#Server.ColdFusion.RootDir#\lib\neo-cron.xml
One more thing, for coldfusion schedule task we can't give interval less than 60 seconds. Otherwise it will throw error as -
But I get to know that through the "neo-cron.xml" we can achieve this.Hope this help !!!
No comments:
Post a Comment