123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace EasySwoole\EasySwoole;
- use App\Crontab\ElasticSearchGoodsNewCrontab;
- use App\Crontab\ElasticSearchGoodsNewCrontab2;
- use EasySwoole\EasySwoole\AbstractInterface\Event;
- use EasySwoole\EasySwoole\Swoole\EventRegister;
- use EasySwoole\Crontab\Crontab;
- use App\Crontab\BalanceCrontab;
- use App\Crontab\XcxWarningCrontab;
- use EasySwoole\ORM\DbManager;
- use EasySwoole\ORM\Db\Connection;
- use EasySwoole\ORM\Db\Config;
- use App\Crontab\ElasticSearchGoodsCrontab;
- use App\Crontab\SeckillCrontab;
- class EasySwooleEvent implements Event
- {
- public static function initialize()
- {
- date_default_timezone_set('Asia/Shanghai');
-
- $mysql_conf = \EasySwoole\EasySwoole\Config::getInstance()->getConf('MYSQL');
- $config = new Config();
- $config->setDatabase($mysql_conf['database']);
- $config->setUser($mysql_conf['user']);
- $config->setPassword($mysql_conf['password']);
- $config->setHost($mysql_conf['host']);
- $config->setTimeout($mysql_conf['timeout']);
-
- $config->setGetObjectTimeout($mysql_conf['getObjectTimeout']);
- $config->setIntervalCheckTime($mysql_conf['intervalCheckTime']);
- $config->setMaxIdleTime($mysql_conf['maxIdleTime']);
- $config->setMinObjectNum($mysql_conf['minObjectNum']);
- $config->setMaxObjectNum($mysql_conf['maxObjectNum']);
- $config->setAutoPing($mysql_conf['autoPing']);
- DbManager::getInstance()->addConnection(new Connection($config));
- }
- public static function mainServerCreate(EventRegister $register)
- {
-
-
- $crontabConfig = new \EasySwoole\Crontab\Config();
-
-
- $crontabConfig->setTempDir(EASYSWOOLE_TEMP_DIR);
-
- $crontabConfig->setServerName('EasySwoole');
-
- $crontabConfig->setWorkerNum(3);
-
- $crontabConfig->setOnException(function (\Throwable $throwable) {
-
- });
-
- $crontab = \EasySwoole\EasySwoole\Crontab\Crontab::getInstance($crontabConfig);
-
- $crontab->register(new BalanceCrontab());
- $crontab->register(new SeckillCrontab());
- $crontab->register(new ElasticSearchGoodsNewCrontab2());
- $crontab->attachToServer(ServerManager::getInstance()->getSwooleServer());
- }
- }
|