当前位置: 首页>>代码示例>>PHP>>正文


PHP Cron::setEnableJob方法代码示例

本文整理汇总了PHP中Cron::setEnableJob方法的典型用法代码示例。如果您正苦于以下问题:PHP Cron::setEnableJob方法的具体用法?PHP Cron::setEnableJob怎么用?PHP Cron::setEnableJob使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cron的用法示例。


在下文中一共展示了Cron::setEnableJob方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testEnableDisableJobsBySetter

 /**
  * Test method for enable and disable jobs by using the setter methods
  *
  * @covers \Liebig\Cron\Cron::setEnableJob
  * @covers \Liebig\Cron\Cron::setDisableJob
  * @covers \Liebig\Cron\Cron::isJobEnabled
  */
 public function testEnableDisableJobsBySetter()
 {
     $iTest1 = 0;
     $iTest2 = 0;
     $iTest3 = 0;
     Cron::add('test1', '* * * * *', function () use(&$iTest1) {
         $iTest1++;
         return false;
     }, true);
     Cron::add('test2', '* * * * *', function () use(&$iTest2) {
         $iTest2++;
         return false;
     }, true);
     Cron::add('test3', '* * * * *', function () use(&$iTest3) {
         $iTest3++;
         return false;
     }, false);
     $this->assertEquals(true, Cron::isJobEnabled('test1'));
     $this->assertEquals(true, Cron::isJobEnabled('test2'));
     $this->assertEquals(false, Cron::isJobEnabled('test3'));
     $this->assertEquals(null, Cron::isJobEnabled('test4'));
     Cron::run();
     $this->assertEquals(1, $iTest1);
     $this->assertEquals(1, $iTest2);
     $this->assertEquals(0, $iTest3);
     $this->assertEquals(1, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(2, \Liebig\Cron\Models\Job::count());
     $this->assertEquals(true, Cron::setEnableJob('test3'));
     $this->assertEquals(true, Cron::isJobEnabled('test1'));
     $this->assertEquals(true, Cron::isJobEnabled('test2'));
     $this->assertEquals(true, Cron::isJobEnabled('test3'));
     $this->assertEquals(null, Cron::isJobEnabled('test4'));
     Cron::run();
     $this->assertEquals(2, $iTest1);
     $this->assertEquals(2, $iTest2);
     $this->assertEquals(1, $iTest3);
     $this->assertEquals(2, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(5, \Liebig\Cron\Models\Job::count());
     $this->assertEquals(true, Cron::setDisableJob('test1'));
     $this->assertEquals(true, Cron::setDisableJob('test3'));
     $this->assertEquals(false, Cron::setDisableJob('noSuchJob'));
     $this->assertEquals(false, Cron::isJobEnabled('test1'));
     $this->assertEquals(true, Cron::isJobEnabled('test2'));
     $this->assertEquals(false, Cron::isJobEnabled('test3'));
     $this->assertEquals(null, Cron::isJobEnabled('test4'));
     Cron::run();
     $this->assertEquals(2, $iTest1);
     $this->assertEquals(3, $iTest2);
     $this->assertEquals(1, $iTest3);
     $this->assertEquals(3, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(6, \Liebig\Cron\Models\Job::count());
     $this->assertEquals(true, Cron::setEnableJob('test2', false));
     $this->assertEquals(false, Cron::isJobEnabled('test1'));
     $this->assertEquals(false, Cron::isJobEnabled('test2'));
     $this->assertEquals(false, Cron::isJobEnabled('test3'));
     $this->assertEquals(null, Cron::isJobEnabled('test4'));
     Cron::run();
     $this->assertEquals(2, $iTest1);
     $this->assertEquals(3, $iTest2);
     $this->assertEquals(1, $iTest3);
     $this->assertEquals(4, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(6, \Liebig\Cron\Models\Job::count());
     $this->assertEquals(true, Cron::setEnableJob('test1', true));
     $this->assertEquals(true, Cron::isJobEnabled('test1'));
     $this->assertEquals(false, Cron::isJobEnabled('test2'));
     $this->assertEquals(false, Cron::isJobEnabled('test3'));
     $this->assertEquals(null, Cron::isJobEnabled('test4'));
     Cron::run();
     $this->assertEquals(3, $iTest1);
     $this->assertEquals(3, $iTest2);
     $this->assertEquals(1, $iTest3);
     $this->assertEquals(5, \Liebig\Cron\Models\Manager::count());
     $this->assertEquals(7, \Liebig\Cron\Models\Job::count());
 }
开发者ID:hilltool,项目名称:cron,代码行数:81,代码来源:CronTest.php

示例2: app_path

});
/*
|--------------------------------------------------------------------------
| Require The Filters File
|--------------------------------------------------------------------------
|
| Next we will load the filters file for the application. This gives us
| a nice separate location to store our route and application filter
| definitions instead of putting them all in the main routes file.
|
*/
require app_path() . '/filters.php';
/*
|--------------------------------------------------------------------------
| Lieberg Cron Jobs
|--------------------------------------------------------------------------
|	this will help us excute all our cron job functions
| 	
| 
| 
|
*/
Event::listen('cron.collectJobs', function () {
    Cron::add('update', '* * * * *', function () {
        // Do some crazy things unsuccessfully every minute
        $orders = Order::where('activity', '=', '0')->delete();
        return true;
    });
    Cron::setEnableJob('update');
    $report = Cron::run();
});
开发者ID:bernardowiredu,项目名称:unlocking-site,代码行数:31,代码来源:global.php


注:本文中的Cron::setEnableJob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。