var retResult = StructNew(); var minInterval = getRebuildFeedCacheInterval(); var schedTaskApp = "ptSocialMedia"; var schedTaskBean = "socialMediaScheduledTasksDAO"; var schedTaskMethod = "runCacheRebuildScheduledTask"; var rebuildFeedCacheschedTaskName = getRebuildFeedCacheScheduledTaskName(); var schedTaskNameSuffix = getScheduledTaskSuffix(); var schedTaskName = rebuildFeedCacheschedTaskName & schedTaskNameSuffix; var CSRF_Token = application.ADF.csSecurity.getCSRF_Token(); var schedTaskFile = "rebuild-feed-cache.cfm"; var schedTaskPath = "/_cs_apps/pt_social_media/scheduled/"; var schedTaskDirPath = ExpandPath(schedTaskPath); var schedTaskDirFilePath = schedTaskDirPath & schedTaskFile; var serverUrl = (( cgi.https == 'on' ) ? 'https' : 'http') & '://' & cgi.SERVER_NAME & (( cgi.SERVER_PORT == 80 OR cgi.SERVER_PORT == 443 ) ? '' : ':' & cgi.SERVER_PORT); var fullSchedTaskURL = serverUrl & schedTaskPath & schedTaskFile; // WRONG! var fullSchedTaskURL = "https://#cgi.server_name#:#cgi.server_port##application.ADF.ajaxProxy#?app=#schedTaskApp#&bean=#schedTaskBean#&method=#schedTaskMethod#&CSRF_Token=#CSRF_Token#"; var logFilePrefix = dateFormat(now(), "yyyymmdd") & "." & request.site.name & "."; var schedLogFileName = logFilePrefix & schedTaskName & ".log"; // Get the Source File to copy var schedTaskSrcFilePath = application.ADF.url & "/apps/pt_social_media/site-files/_cs_apps/pt_social_media/" & schedTaskFile; var schedTaskSrcDirFilePath = ExpandPath(schedTaskSrcFilePath); // Set the Scheduled tasks defaults var defaultMinTimeout = 15; var defaultMinInterval = 15; var defaultStartDate = now(); var defaultStartTime = '00:01:00'; // 12:01:00 AM // NOT NEEDED - var defaultStartDateTime = defaultStartDate & " " & defaultStartTime; var schedStartDate = ""; var schedStartTime = ""; // NOT NEEDED - var schedStartDateTime = ""; var schedTaskInterval = defaultMinInterval * 60; // Convert to seconds var schedTaskTimeout = defaultMinTimeout * 60; // Convert to seconds var dirResult = ''; var copyResult = ''; // Create the directory structure if needed dirResult = application.ptSocialMedia.utils.createDataFileFolders(filePath=schedTaskDirFilePath); // Copy the scheduler file to the site copyResult = application.ADF.csData.csFile(action="COPY",source=schedTaskSrcDirFilePath,destination=schedTaskDirPath); if ( StructKeyExists(copyResult,"success") AND copyResult.success EQ true ) retResult.error = false; else { retResult.error = true; retResult.status = "failed"; retResult.details = copyResult; } if ( retResult.error EQ false ) { if ( IsNumeric(minInterval) AND minInterval GT 0 ) schedTaskInterval = minInterval * 60; // Convert to seconds // No longer setting the Schedule task for minInterval in the future // - Now setting it for the next day /* if ( IsNumeric(minInterval) AND minInterval GT 0 ) { schedTaskInterval = minInterval * 60; // Convert to seconds // Set the the Start Date/Time to be the MinInterval from now (default 15 mins) schedStartDateTime = DateAdd('n', minInterval, defaultStartDateTime); } else { // Set the the Start Date/Time to be the from 15 mins from now schedStartDateTime = DateAdd('n', defaultMinInterval, defaultStartDateTime); }*/ // Set the schedule start date schedStartDate = defaultStartDate; // - Updated to 1 day from now to start at the beginning the next day // (Since date/time must be in the future!) schedStartDate = DateAdd("d",1,defaultStartDate); schedStartDate = DateFormat(schedStartDate, "mm/dd/yyyy"); // Set the schedule start time schedStartTime = TimeFormat(defaultStartTime, "HH:mm"); // The setScheduledTask function returns void... so try/catch it try { retResult = application.ptSocialMedia.utils.setRecurringScheduledTask( url=fullSchedTaskURL, taskName=schedTaskName, schedLogFileName=schedLogFileName, interval=schedTaskInterval, startDate=schedStartDate, startTime=schedStartTime, timeout=schedTaskTimeout ); /* retResult returns: authenicated:true/false and "status":success/failed and on error "msg" */ if ( !StructKEyExists(retResult,"status") OR retResult.status EQ "failed" ) { retResult.error = true; retResult.status = "failed"; } else { retResult.error = false; } } catch (any e) { retResult.error = true; retResult.status = "failed"; retResult.ErrorDetails = cfcatch; } } if ( retResult.error ) { //Log the Error doErrorLogging("socialMediaScheduledTasksDAO","createCacheRebuildScheduledTask",retResult); } return retResult; var runStatus = false; // Check if the time limit has exceeded, and clear the variable - Default: 20 mins if ( DateDiff("n", server.ADF.ptSocialMedia.cacheThreadStart, now()) GT 20 ) server.ADF.ptSocialMedia.cacheThreadStatus = "none"; runStatus = true; //Log the runCacheRebuildScheduledTask Status var appName = 'ptSocialMedia'; var methodName = 'socialMediaScheduledTasksDAO'; var processName = 'socialMediaScheduledTasksDAO'; var logMsg = 'Cache Rebuild Status: #runStatus#'; var logData = server.ADF.ptSocialMedia; var addBreak = true; var addTimeStamp = true; application.ADF.log.doTextLogging(methodName=methodName,processName=processName,appName=appName,logMsg=logMsg,logData=logData,addBreak=addBreak,addTimeStamp=addTimeStamp); // ,breakChar,breakSize,delimiter,fileNameOverride,addTimeStamp,logDir,restartFile // Check to make sure the build on restart thread is not running /*if ( server.ADF.ptSocialMedia.cacheThreadStatus NEQ 'running' ) { thread action="run" name="ptSocialMediaCache-Build" { application.ptSocialMedia.socialMediaCacheController.buildSocialMediaCache(); } server.ADF.ptSocialMedia.cacheThreadStart = now(); server.ADF.ptSocialMedia.cacheThreadEnd = ""; server.ADF.ptSocialMedia.cacheThreadStatus = "running"; runStatus = true; }*/ return runStatus; var rebuildFeedCacheschedTaskName = getRebuildFeedCacheScheduledTaskName(); var schedTaskNameSuffix = getScheduledTaskSuffix(); var schedTaskName = rebuildFeedCacheschedTaskName & schedTaskNameSuffix; return deleteScheduledTaskItem(scheduleName=schedTaskName); try { application.ptSocialMedia.utils.deleteScheduledTask(arguments.scheduleName); return true; } catch(Any e) { return false; }