English 中文(简体)
我如何找到下一个运行时间 来安排任务?
原标题:How do I find out the next run time for a Scheduled Task?

在9号冷冻区,有没有快速的方法 来找出下一次 计划的任务 将试图运行?

最佳回答

I would rather call a lower level API or such to have CF calculate it in the same way it normally would. I ve dumped the various services and see no obvious methods to call that would help.

AFAIK 不存在单行解决方案。 计算日期的主要方法为 < code> CronTabEntry. nextRunTime 。 < code> CronTabEntry 类代表单项任务的设置。 < code> NextRunTime 方法根据任务设置计算下一个 < em> 潜在 运行日期。 过期和暂停的任务的处理在其他地方进行, 在运行时进行 。

要重复您调用 < code> nextRunTime 并添加处理过期任务的逻辑。 虽然 < code> nextRunTime 方法是私密的, 但仍可以通过反射访问该方法, 可借助 < a href==" http://docs. oracle.com/javase/6/docs/ api/java/lang/ reflect/ AccessObject. html#setAccessAccess %28boolean% 29" rel="nofollow" >Method. setAccess(bolean) 。

我拼凑了下面的函数来演示。 大部分是反射调用( 在 CF 中比 java 等值多一点动词 ) 。 总之, 它应该返回 CF 调度器所用的相同日期 。

《议事规则》:

  • If the task end date/time has passed, returns an emtpy string ""
  • If it is a one-time task, that already executed, returns an empty string ""
  • For all other tasks (including paused tasks), returns the next scheduled date

<强>用法:

result = new TaskUtil().getNextRunTime("SomeTask");
WriteDump(result);

< 强 > CFC

component {
     public struct function getNextRunTime(required string scheduledTaskName) {

        // load task settings from factory
        local.cron = createobject("java","coldfusion.server.ServiceFactory").getCronService();
        local.task = local.cron.findTask( arguments.scheduledTaskName );

        // abort if we cannot find the task ..
        if ( isNull(local.task) ) {
            throw ("The specified task was not found: ["& arguments.scheduledTaskName &"]");
        }     

        // Calculate the next POTENTIAL schedule date 
        local.isRecurring = listFindNoCase("daily,weekly,monthly", local.task.interval);
        local.dateClass   = createObject("java", "java.util.Date").getClass();
        local.longClass   = createObject("java", "java.lang.Long").TYPE;
        local.stringClass = createObject("java", "java.lang.String").getClass();

        // Construct the appropriate arguments 
        // Note: must load arguments / class types into arrays for java reflection 
        if (local.isRecurring) {
            local.args  = [ local.task.getStartDate(), local.task.getStartTime(), local.task.interval ];
            local.types = [ local.dateClass, local.dateClass, local.stringClass ];
        }
        else {
            local.args  = [ local.task.getStartDate(), local.task.getStartTime(), local.task.getEndTime(), javacast("long", val(local.task.interval) * 1000) ];
            local.types = [ local.dateClass, local.dateClass, local.dateClass, local.longClass ];
        }

        // Call CF s internal method to calculate the next date (UNDOCUMENTED)    
        local.internalMethod = local.task.getClass().getDeclaredMethod("NextRunTime", local.types );
        local.internalMethod.setAccessible( true );
        local.nextRunOnDate = local.internalMethod.invoke( local.task, local.args );

        // Determine if the task will be rescheduled
        local.isExpired   = false;
        if ( local.task.interval != "once" && structKeyExists( local.task, "end_date") ) {
            // It is non-recurring, so determine if it already expired
            local.expiresOnDate = local.task.mergeDates( local.task.getEndDate(), local.task.getEndTime() );
            local.isExpired   = dateCompare( local.nextRunOnDate, local.expiresOnDate, "s") >= 0;
        }
        else if ( local.task.interval == "once" && local.task.disabled) {
            // It is a one time task that already executed
            local.isExpired   = true;
        }

        // construct and return results    
        local.result = {};
        local.result.name          = local.task.task;
        local.result.isPaused    = local.task.paused;
        local.result.isExpired   = local.isExpired;
        local.result.nextRunTime = local.isExpired ? "" : local.nextRunOnDate;

        return local.result;
    }    
}
问题回答

暂无回答




相关问题
JQuery AJAX .load - flash chart doesnt load in IE

An IE issue has me completely stumped. I have a coldfusion page that uses JQuery s AJAX .load function to load in a new flash file that is generated by coldFusion s cfchart tag. This works completely ...

Best Coldfusion Library for OpenID [closed]

I am getting ready to start a project that requires using OpenID within Coldfusion 8. I have found a number of different options and was wondering what has worked the best, get s the most support, ...

Find ColdFusion Generated ID

Is there a way to find the elements generated by ColdFusion s <CFLayout> and <CFLayoutArea> tags? These tags: <cflayout type="tab" name="MyAccount"> <cflayoutarea name="...

ColdFusion COM error

I am upgrading from CF4.5 to CF8. Calls to COM dll s that used to work in version 4.5 now throw a "Complex object types cannot be converted to simple values.." error. The COM object has a few arrays ...

What s the best way to write engine-specific CFML code?

Sometimes it is necessary to write different code for Adobe ColdFusion vs Railo vs OpenBD, due to differences in implementation. Do people have a specific method that they use for this? For example, ...

热门标签