Skip to content

Commit

Permalink
fix worker hang after SIGCLD when db conn timeout, new managers
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogiovinazzi committed Sep 5, 2017
1 parent fd4b850 commit d43752a
Show file tree
Hide file tree
Showing 20 changed files with 525 additions and 309 deletions.
4 changes: 4 additions & 0 deletions queue_monitor.php
@@ -0,0 +1,4 @@
<?php

var_dump(unserialize(file_get_contents('tests/root/run/queue.worker.lock')));

4 changes: 4 additions & 0 deletions schedule_monitor.php
@@ -0,0 +1,4 @@
<?php

var_dump(unserialize(file_get_contents('tests/root/run/schedule.worker.lock')));

24 changes: 23 additions & 1 deletion src/Comodojo/Extender/Components/Database.php
@@ -1,8 +1,9 @@
<?php namespace Comodojo\Extender\Components;

use \Comodojo\Foundation\Base\Configuration;
use \Comodojo\Extender\Traits\ConfigurationTrait;
use \Comodojo\Foundation\Base\ConfigurationTrait;
use \Doctrine\ORM\Tools\Setup;
use \Doctrine\ORM\Tools\SchemaValidator;
use \Doctrine\ORM\EntityManager;
use \Doctrine\DBAL\DriverManager;
use \Doctrine\DBAL\Configuration as DoctrineConfiguration;
Expand Down Expand Up @@ -139,6 +140,27 @@ public static function init(Configuration $configuration) {

}

public static function validate(Configuration $configuration) {

$db = new Database($configuration);

$em = $db->getEntityManager();
$validator = new SchemaValidator($em);

$result = [
'MAPPING' => empty($validator->validateMapping()),
'SYNC' => $validator->schemaInSyncWithMetadata()
];

unset($validator);
$em->getConnection()->close();
$em->close();
unset($db);

return $result;

}

protected static function getConnectionParameters(Configuration $configuration) {

$connection_params = $configuration->get('database-params');
Expand Down
18 changes: 14 additions & 4 deletions src/Comodojo/Extender/ExtenderDaemon.php
Expand Up @@ -4,8 +4,8 @@
use \Comodojo\Extender\Workers\QueueWorker;
use \Comodojo\Extender\Task\Table as TasksTable;
use \Comodojo\Extender\Task\Request;
use \Comodojo\Extender\Task\TaskParameters;
use \Comodojo\Extender\Traits\ConfigurationTrait;
use \Comodojo\Foundation\Base\ConfigurationTrait;
use \Comodojo\Extender\Components\Database;
use \Comodojo\Extender\Traits\TasksTableTrait;
use \Comodojo\Extender\Queue\Manager as QueueManager;
use \Comodojo\Extender\Schedule\Manager as ScheduleManager;
Expand All @@ -20,6 +20,7 @@
use \Comodojo\Foundation\Utils\ArrayOps;
use \Comodojo\SimpleCache\Manager as SimpleCacheManager;
use \Psr\Log\LoggerInterface;
use \Exception;

class ExtenderDaemon extends AbstractDaemon {

Expand All @@ -32,7 +33,7 @@ class ExtenderDaemon extends AbstractDaemon {
protected static $default_properties = array(
'pidfile' => '',
'socketfile' => '',
'socketbuffer' => 8192,
'socketbuffer' => 102400,
'sockettimeout' => 15,
'niceness' => 0,
'arguments' => '\\Comodojo\\Daemon\\Console\\DaemonArguments',
Expand Down Expand Up @@ -75,6 +76,15 @@ public function __construct(

public function setup() {

// try {
// if ( Database::validate($this->configuration) === false ){
// printf("\nWARNING: %s\n\n", "database seems to be not in sync!");
// }
// } catch (Exception $e) {
// printf("\nFATAL ERROR: %s\n\n", $e->getMessage());
// $this->end(1);
// }

$this->installWorkers();

$this->pushQueueCommands();
Expand Down Expand Up @@ -117,7 +127,7 @@ protected function pushQueueCommands() {
$this->getEvents()
);

return $manager->add($name, $request);
return $manager->add($request);
})
->add('queue:addBulk', function(array $requests, $daemon) {

Expand Down
9 changes: 3 additions & 6 deletions src/Comodojo/Extender/Queue/Manager.php
@@ -1,14 +1,14 @@
<?php namespace Comodojo\Extender\Queue;

use \Comodojo\Foundation\Base\Configuration;
use \Comodojo\Foundation\Base\ConfigurationTrait;
use \Comodojo\Foundation\Events\Manager as EventsManager;
use \Comodojo\Foundation\Logging\LoggerTrait;
use \Comodojo\Foundation\Events\EventsTrait;
use \Comodojo\Extender\Traits\ConfigurationTrait;
use \Comodojo\Extender\Components\Database;
use \Comodojo\Extender\Traits\EntityManagerTrait;
use \Comodojo\Extender\Task\Request;
use \Comodojo\Extender\Orm\Entities\Queue;
use \Comodojo\Extender\Components\Database;
use \Doctrine\ORM\EntityManager;
use \Psr\Log\LoggerInterface;
use \Exception;
Expand Down Expand Up @@ -39,7 +39,6 @@ class Manager {
/**
* Class constructor
*
* @param string $manager_name
* @param Configuration $configuration
* @param LoggerInterface $logger
* @param TasksTable $tasks
Expand Down Expand Up @@ -120,9 +119,7 @@ public function addBulk(array $queue) {
protected function doAddRequest(Request $request, EntityManager $em) {

$record = new Queue();
$record
->setName($request->getName())
->setRequest($request);
$record->setName($request->getName())->setRequest($request);

$em->persist($record);

Expand Down
3 changes: 1 addition & 2 deletions src/Comodojo/Extender/Schedule/Manager.php
Expand Up @@ -5,7 +5,7 @@
use \Comodojo\Foundation\Logging\LoggerTrait;
use \Comodojo\Foundation\Events\EventsTrait;
use \Comodojo\Extender\Components\Database;
use \Comodojo\Extender\Traits\ConfigurationTrait;
use \Comodojo\Foundation\Base\ConfigurationTrait;
use \Comodojo\Extender\Traits\EntityManagerTrait;
use \Comodojo\Extender\Orm\Entities\Schedule;
use \Doctrine\ORM\EntityManager;
Expand Down Expand Up @@ -39,7 +39,6 @@ class Manager {
/**
* Class constructor
*
* @param string $manager_name
* @param Configuration $configuration
* @param LoggerInterface $logger
* @param TasksTable $tasks
Expand Down
2 changes: 1 addition & 1 deletion src/Comodojo/Extender/Task/AbstractTask.php
Expand Up @@ -2,7 +2,7 @@

use \Comodojo\Foundation\Base\Configuration;
use \Comodojo\Extender\Interfaces\TaskInterface;
use \Comodojo\Extender\Traits\ConfigurationTrait;
use \Comodojo\Foundation\Base\ConfigurationTrait;
use \Comodojo\Foundation\Logging\LoggerTrait;
use \Comodojo\Daemon\Traits\PidTrait;
use \Comodojo\Foundation\Events\EventsTrait;
Expand Down

0 comments on commit d43752a

Please sign in to comment.