public function execute()
 {
     if (!$this->isReady('thedate', 'priority')) {
         return self::IGNO;
     }
     $date1 = date('Ymd', strtotime(Setting::get('last_date')));
     $date2 = date('Ymd', strtotime($this->option('thedate')));
     if ($date1 >= $date2) {
         return self::IGNO;
     }
     $mysql = \Myfox\Lib\Mysql::instance('default');
     $count = (int) $mysql->getOne($mysql->query(sprintf('SELECT COUNT(*) FROM %stask_queque WHERE autokid < %u AND priority <= %u ' . "AND task_flag NOT IN (%d,%d) AND task_type='import'", $mysql->option('prefix'), $this->id, $this->option('priority'), \Myfox\App\Queque::FLAG_IGNO, \Myfox\App\Queque::FLAG_DONE)));
     if ($count > 0) {
         $this->setError(sprintf('Waiting for %d import task(s)', $count));
         return self::FAIL;
     }
     if (!Router::flush()) {
         $this->setError('flush route failed');
         return self::FAIL;
     }
     Setting::set('last_date', $date2, '', '集群数据最新日期');
     // TODO:
     // CALL nodefox to reload route info info cache
     return self::SUCC;
 }
 public function test_should_sharding_table_router_set_and_get_works_fine()
 {
     $table = \Myfox\App\Model\Table::instance('numsplit');
     try {
         Router::set('numsplit', array(array('field' => array('thedate' => '20110610'), 'count' => 1201)));
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertTrue($e instanceof \Myfox\Lib\Exception);
         $this->assertContains('Column "cid" required for table "numsplit"', $e->getMessage());
     }
     $this->assertEquals(array('cid:1,thedate:20110610' => array(array('rows' => 1000, 'hosts' => '3,1', 'table' => 'numsplit_0.t_' . $table->get('autokid') . '_0'), array('rows' => 201, 'hosts' => '1,2', 'table' => 'numsplit_0.t_' . $table->get('autokid') . '_1')), 'cid:2,thedate:20110610' => array(array('rows' => 998, 'hosts' => '1,2', 'table' => 'numsplit_0.t_' . $table->get('autokid') . '_1'))), Router::set('numsplit', array(array('field' => array('thedate' => '2011-06-10', 'cid' => 1), 'count' => 1201), array('field' => array('thedate' => '2011-06-10', 'cid' => 2), 'count' => 998))));
     $this->assertEquals(array(), Router::get('numsplit', array('thedate' => '2011-6-10', 'cid' => 1, 'blablala' => 2)));
     Router::effect('numsplit', array('thedate' => 20110610, 'cid' => 1), 'numsplit_0.t_' . $table->get('autokid') . '_1', '1,2') && Router::flush();
     $routes = Router::get('numsplit', array('thedate' => '2011-6-10', 'cid' => 1, 'blablala' => 2));
     $result = array();
     foreach ($routes as $item) {
         unset($item['tabid'], $item['seqid']);
         $item['mtime'] = $item['mtime'] > 0 ? true : false;
         $result[] = $item;
     }
     $this->assertEquals(array(array('tbidx' => 'test_route_info_c', 'mtime' => true, 'hosts' => '1,2', 'table' => sprintf('numsplit_0.t_%d_1', $table->get('autokid')))), $result);
 }