Created
October 29, 2012 03:39
-
-
Save owenallenaz/3971371 to your computer and use it in GitHub Desktop.
Scheduling in Coldfusion without cfschedule, server access, or the Coldfusion Administrator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component { | |
this.name = "testingApp"; | |
public function onApplicationStart() { | |
// counter to prove the cron.cfm is firing | |
application.counter = 0; | |
} | |
public function onRequestEnd() { | |
// specify an index for the cache | |
local.cacheIndex = "cron_process"; | |
// grab an item from the index | |
local.cache = cacheGet(local.cacheIndex); | |
// cacheGet returns null, so if nothing is in the cache local.cache will not exist | |
if (!StructKeyExists(local, "cache")) { | |
// we must put the item in the cache BEFORE running the cfhttp, otherwise the cfhttp will trigger another cron hit and we'll be in an infinite loop | |
cachePut(local.cacheIndex, "ran at #now()#", CreateTimeSpan(0,0,0,10)); | |
// send off the cron job to wherever you desire | |
local.http = new http(url = "http://www.mywebsite.com/test/basic/caching/cron.cfm", timeout = 1); | |
local.http.addParam(type = "header", name = "connection", value = "keep-alive"); | |
local.http.send(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- increment the counter ---> | |
<cfset Application.counter++> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- check the status of the counter ---> | |
<cfoutput>#Application.counter#</cfoutput> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- restart the application to clear the timer ---> | |
<cfset ApplicationStop()> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment