Commit eb859e83 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Merge branch 'macclane-notifications' into spartan (Refonte du Worker/affectations)

parents 70846c2b 1d7dacbb
Loading
Loading
Loading
Loading
Loading
+37 −87
Changes for bin/oscar-worker.php: 37 added lines, 87 removed lines.
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@
// Chemin "simplifié"
chdir(dirname(__DIR__));

$oscarCmd = '/usr/bin/php bin/oscar.php console ';

// Autoload & Co
require __DIR__.'/../vendor/autoload.php';

@@ -28,139 +30,87 @@ $oscarConfigurationService = $app->getServiceManager()->get(\Oscar\Service\Oscar
// Worker
$worker = new GearmanWorker();
$worker->addServer($oscarConfigurationService->getGearmanHost());
$worker->addFunction('indexPerson', 'oscarJob_indexPerson');
$worker->addFunction('personSearchUpdate', 'oscarJob_indexPerson');
$worker->addFunction('indexActivity', 'oscarJob_indexActivity');
$worker->addFunction('activitySearchUpdate', 'oscarJob_indexActivity');
$worker->addFunction('notificationActivityPerson', 'oscarJob_notificationActivityPerson');
$worker->addFunction('purgeNotificationsPersonActivity', 'oscarJob_purgeNotificationsPersonActivity');

$worker->addFunction('updateIndexActivity', 'oscarJob_updateIndexActivity');
$worker->addFunction('updateIndexPerson', 'oscarJob_updateIndexPerson');
$worker->addFunction('updateIndexOrganization', 'oscarJob_updateIndexOrganization');
$worker->addFunction('updateNotificationsActivity', 'oscarJob_updateNotificationsActivity');

$worker->addFunction('hello', 'oscarJob_hello');

// Affiche dans le journalctl -u oscarworker.service -f
echo "OSCAR WORKER STARTED\n";
echo "Version: " . \Oscar\OscarVersion::getBuild() . "\n";
$execDev = "2";
echo "OSCAR WORKER STARTED ".\Oscar\OscarVersion::getBuild()."\n";

while($worker->work());

function getServiceManager(){
    global $app;
    return $app->getServiceManager();
}

while($worker->work());

function oscarJob_indexActivity(GearmanJob $job){
function oscarJob_updateIndexActivity(GearmanJob $job){
    global $oscarCmd;
    $params = json_decode($job->workload());



    try {
        if( !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant ID");
            throw new Exception("Paramètres manquant 'activityid'");
        }
        /** @var \Oscar\Service\ProjectGrantService $activityService */
        $activityService = getServiceManager()->get(\Oscar\Service\ProjectGrantService::class);


        $activityid = $params->activityid;
        $activityService->getLoggerService()->info("[GEARMAN] Indexation de Activity $activityid");
        $activity = $activityService->getActivityById($activityid);
        echo date('y-m-d H:i:s')." Rebuid Index [$activityid] $activity\n";
        $activityService->searchUpdate($activity);
        echo "[worker] indexactivity " . $activityid;
        exec($oscarCmd . ' indexactivity \'{"activityid":'. $params->activityid .'}\'');

    } catch (Exception $e) {
        $activityService->getLoggerService()->info("[GEARMAN] Error " . $e->getMessage());
        echo "[ERR] " . $e->getMessage() ."\n";
    }
}

function oscarJob_indexPerson(GearmanJob $job){
function oscarJob_updateIndexPerson(GearmanJob $job){
    global $oscarCmd;
    $params = json_decode($job->workload());

    try {
        if( !property_exists($params, 'personid') ){
            throw new Exception("Paramètres manquant ID");
            throw new Exception("Paramètres manquant 'personid'");
        }
        /** @var \Oscar\Service\PersonService $personService */
        $personService = getServiceManager()->get(\Oscar\Service\PersonService::class);

        $personId = $params->personid;

        getServiceManager()->get('Logger')->info("[GEARMAN] Indexation de Person $personId");
        $person = $personService->getPerson($personId);
        echo date('y-m-d H:i:s')." Rebuid Index [$personId] $person\n";
        $personService->getSearchEngineStrategy()->update($person);
        $personid = $params->personid;
        echo "[worker] indexperson " . $personid;
        exec($oscarCmd . ' indexperson \'{"personid":'. $personid .'}\'');

    } catch (Exception $e) {
        getServiceManager()->get('Logger')->info("[GEARMAN] Error " . $e->getMessage());
        echo "[ERR] " . $e->getMessage() . "\n";
    }
}

function oscarJob_notificationActivityPerson(GearmanJob $job){
function oscarJob_updateIndexOrganization(GearmanJob $job){
    global $oscarCmd;
    $params = json_decode($job->workload());

    try {
        if( !property_exists($params, 'personid') || !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant ID");
        if( !property_exists($params, 'organizationid') ){
            throw new Exception("Paramètres manquant 'organizationid'");
        }

        /** @var \Oscar\Service\ProjectGrantService $projectGrantService */
        $projectGrantService = getServiceManager()->get(\Oscar\Service\ProjectGrantService::class);

        /** @var \Oscar\Service\PersonService $personService */
        $personService = getServiceManager()->get(\Oscar\Service\PersonService::class);

        /** @var \Oscar\Service\NotificationService $notificationService */
        $notificationService = getServiceManager()->get(\Oscar\Service\NotificationService::class);

        $personId = $params->personid;
        $person = $personService->getPerson($personId);

        $activityId = $params->activityid;
        $activity = $projectGrantService->getActivityById($activityId);

        getServiceManager()->get('Logger')->info("[GEARMAN] Notification Person:$personId - Activity:$activityId");

        echo date('y-m-d H:i:s')." Notification Activity Person [$activityId, $personId] $activity >  $person\n";
        $notificationService->generateNotificationsForActivity($activity, $person);
        $organizationid = $params->organizationid;
        echo "[worker] indexorganization " . $organizationid;
        exec($oscarCmd . ' indexorganization \'{"organizationid":'. $organizationid .'}\'');

    } catch (Exception $e) {
        echo "[ERR] " . $e->getMessage() . "\n";
        getServiceManager()->get('Logger')->info("[GEARMAN] Error " . $e->getMessage());
    }
}

function oscarJob_updateNotificationsActivity(GearmanJob $job){
    global $oscarCmd;

function oscarJob_purgeNotificationsPersonActivity(GearmanJob $job){
    $params = json_decode($job->workload());

    try {
        if( !property_exists($params, 'personid') || !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant ID");
        if( !property_exists($params, 'activityid') ){
            throw new Exception("Paramètres manquant 'activityid'");
        }

        /** @var \Oscar\Service\ProjectGrantService $projectGrantService */
        $projectGrantService = getServiceManager()->get(\Oscar\Service\ProjectGrantService::class);

        /** @var \Oscar\Service\PersonService $personService */
        $personService = getServiceManager()->get(\Oscar\Service\PersonService::class);

        /** @var \Oscar\Service\NotificationService $notificationService */
        $notificationService = getServiceManager()->get(\Oscar\Service\NotificationService::class);

        $personId = $params->personid;
        $person = $personService->getPerson($personId);

        $activityId = $params->activityid;
        $activity = $projectGrantService->getActivityById($activityId);

        getServiceManager()->get('Logger')->info("[GEARMAN] Purge notification Person:$personId Activity:$activityId");

        echo date('y-m-d H:i:s')." PURGE Notification Activity Person [$activityId, $personId] $activity >  $person\n";
        $notificationService->purgeNotificationsPersonActivity($activity, $person);
        $activityid = $params->activityid;
        echo "[worker] notificationsactivity " . $activityid;
        exec($oscarCmd . ' notificationsactivity \'{"activityid":'. $params->activityid .'}\'');

    } catch (Exception $e) {
        getServiceManager()->get('Logger')->info("[GEARMAN] Error " . $e->getMessage());
        echo "[ERR] " . $e->getMessage() ."\n";
    }
}
@@ -186,7 +136,7 @@ function oscarJob_hello(GearmanJob $job){
        echo "Hello with " . print_r($params) . "\n";

        // Envoi d'un log vers OSCAR
        $loggerService->info("[GEARMAN] a bien reçu la tâche HELLO");
        getServiceManager()->get('Logger')->info(" > [gearman:call] TEST OK]");

        $job->sendComplete("TRAITEMENT RÉUSSI");

+20 −7
Changes for config/autoload/global.php: 20 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -227,13 +227,26 @@ return array(
        ],

        'horslots' => [
//            'conges' => [ 'code' => 'conges',  'label' => 'Congés',  'description' => 'Congès, RTT, récupération', 'icon' => true ],
//            'training' => [ 'code' => 'training',  'label' => 'Formation',  'description' => 'Vous avez suivi un formation, DIFF, etc...', 'icon' => true ],
//            'teaching' => [ 'code' => 'teaching',  'label' => 'Enseignement',  'description' => 'Cours, TD, fonction pédagogique', 'icon' => true ],
//            'sickleave' => [ 'code' => 'sickleave', 'label' => 'Arrêt maladie',  'description' => '', 'icon' => true ],
//            //  'absent' => [ 'code' => 'absent',  'label' => 'Absent',  'description' => '', 'icon' => true ],
//            'research' => [ 'code' => 'research', 'label' => 'Autre recherche',  'description' => 'Autre projet de recherche (sans feuille de temps)', 'icon' => true ],
//            'other' => [ 'code' => 'other', 'label' => 'Divers',  'description' => 'Autre activité', 'icon' => true ],
            ////////////////////////////////// EXEMPLE de CONFIGURATION DES HORS-LOTS
//            'conges' => [ 'code' => 'conges',  'label' => 'Congés',
//                'group' => 'abs',
//                'description' => 'Congès, RTT, récupération', 'icon' => true ],
//            'training' => [ 'code' => 'training',  'label' => 'Formation',
//                'group' => 'other',
//                'description' => 'Vous avez suivi un formation, DIFF, etc...', 'icon' => true ],
//            'teaching' => [ 'code' => 'teaching',  'label' => 'Enseignement',
//                'group' => 'education',
//                'description' => 'Cours, TD, fonction pédagogique', 'icon' => true ],
//            'sickleave' => [ 'code' => 'sickleave', 'label' => 'Arrêt maladie',
//                'group' => 'abs',
//                'description' => '', 'icon' => true ],
//            'research' => [ 'code' => 'research', 'label' => 'Autre recherche',
//                'group' => 'research',
//                'description' => 'Autre projet de recherche (sans feuille de temps)', 'icon' => true ],
//            'other' => [ 'code' => 'other', 'label' => 'Divers',
//                'group' => 'other',
//                'description' => 'Autre activité', 'icon' => true ],

        ],


+2 −1
Changes for module/Oscar/config/module.config.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ return array(
                // PROJET
                ////////////////////////////////////////////////////////////////
                [   'controller' =>   'Project',
                    'action' => ['show', 'new', 'edit', 'search', 'makeProject'],
                    'action' => ['show', 'new', 'edit', 'search', 'makeProject', 'persons', 'organizations'],
                    'roles' => ['user'],
                ],
                [   'controller' =>   'Project',
@@ -806,6 +806,7 @@ return array(
            \Oscar\Service\ConnectorService::class => \Oscar\Service\ConnectorServiceFactory::class,
            \Oscar\Service\ContractDocumentService::class => \Oscar\Service\ContractDocumentServiceFactory::class,
            'Logger' => \Oscar\Service\LoggerServiceFactory::class,
            \Oscar\Service\GearmanJobLauncherService::class => \Oscar\Service\GearmanJobLauncherServiceFactory::class,
            \Oscar\Service\MailingService::class => \Oscar\Service\MailingServiceFactory::class,
            \Oscar\Service\MaintenanceService::class => \Oscar\Service\MaintenanceServiceFactory::class,
            \Oscar\Service\MilestoneService::class => \Oscar\Service\MilestoneServiceFactory::class,
+14 −0
Changes for module/Oscar/config/routes.yml: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -547,6 +547,20 @@ project:
                defaults:
                    action: search

        persons:
            type: segment
            options:
                route: /persons/:idproject
                defaults:
                    action: persons

        organizations:
            type: segment
            options:
                route: /organizations/:idproject
                defaults:
                    action: organizations

################################################################################
# GESTION des PERSONNES
person:
+50 −0
Changes for module/Oscar/src/Oscar/Command/OscarActivityNotificationUpdateCommand.php: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php
/**
 * Created by PhpStorm.
 * User: bouvry
 * Date: 04/10/19
 * Time: 11:49
 */

namespace Oscar\Command;

use Exception;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class OscarActivityNotificationUpdateCommand extends OscarAdvancedCommandAbstract
{
    protected static $defaultName = OscarCommandAbstract::COMMAND_ACTIVITY_NOTIFICATION_UPDATE;

    const ARGUMENT_ACTIVITY_ID = 'activityid';

    protected function configure()
    {
        parent::configure();
        $this
            ->setDescription("Actualisation des notification pour une activité")
            ->addArgument(self::ARGUMENT_ACTIVITY_ID, InputArgument::REQUIRED, "ID de l'activité");
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        parent::execute($input, $output);

        $activityId = $input->getArgument(self::ARGUMENT_ACTIVITY_ID);

        try {
            $activity = $this->getProjectGrantService()->getActivityById($activityId);

            if (!$this->ask("Actualiser les notifications de l'activité '$activity' ?")) {
                $this->debug("CMD aborded " . $this->getName());
                return 0;
            }
            $this->getProjectGrantService()->getNotificationService()->updateNotificationsActivity($activity);

            return $this->finalSuccess("Notifications pour '$activity' mises à jour");
        } catch (Exception $e) {
            return $this->finalFatalError($e);
        }
    }
}
 No newline at end of file
Loading