Skip to content

Instantly share code, notes, and snippets.

@owenallenaz
Created October 29, 2012 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenallenaz/3971371 to your computer and use it in GitHub Desktop.
Save owenallenaz/3971371 to your computer and use it in GitHub Desktop.
Scheduling in Coldfusion without cfschedule, server access, or the Coldfusion Administrator
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();
}
}
}
<!--- increment the counter --->
<cfset Application.counter++>
<!--- check the status of the counter --->
<cfoutput>#Application.counter#</cfoutput>
<!--- 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