Browse Source

Start db in onWorkerStart (#5126)

jcheron 5 years ago
parent
commit
73f5a3ac66

+ 2 - 2
frameworks/PHP/ubiquity/.ubiquity/_workerman.php

@@ -12,8 +12,8 @@ $config["sessionName"]=null;
 $address=$sConfig['host'].':'.$sConfig['port'];
 $config ["siteUrl"] = 'http://'.$address;
 require ROOT . './../vendor/autoload.php';
-require ROOT.'config/workerServices.php';
 $workerServer=new \Ubiquity\servers\workerman\WorkermanServer();
 $workerServer->init($config, __DIR__);
-$workerServer->setDefaultCount();
+$workerServer->setDefaultCount(2);
+require ROOT.'config/workerServices.php';
 $workerServer->run($sConfig['host'],$sConfig['port'],$sConfig['socket']??[]);

+ 5 - 2
frameworks/PHP/ubiquity/app/config/workerServices.php

@@ -1,5 +1,8 @@
 <?php
 \Ubiquity\cache\CacheManager::startProd($config);
 \Ubiquity\controllers\Startup::$templateEngine = new \Ubiquity\views\engine\micro\MicroTemplateEngine();
-\Ubiquity\orm\DAO::setModelsDatabases(["models\\Fortune"=>"worker","models\\World"=>"worker"]);
-\Ubiquity\orm\DAO::startDatabase($config,'worker');
+\Ubiquity\orm\DAO::setModelsDatabases(["models\\Fortune"=>'worker',"models\\World"=>'worker']);
+$workerServer->onWorkerStart=function() use($config){
+	\Ubiquity\orm\DAO::startDatabase($config,'worker');
+};
+

+ 1 - 1
frameworks/PHP/ubiquity/ubiquity-workerman-pgsql.dockerfile

@@ -33,6 +33,6 @@ RUN php composer.phar install --optimize-autoloader --classmap-authoritative --n
 
 RUN chmod 777 -R /ubiquity/.ubiquity/*
 
-RUN sed -i "s|worker|pgsql|g" /ubiquity/app/config/workerServices.php
+RUN sed -i "s|'worker'|'pgsql'|g" /ubiquity/app/config/workerServices.php
 
 CMD /ubiquity/vendor/bin/Ubiquity serve -t=workerman -p=8080 -h=0.0.0.0