IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

cron job avec docker ne mappe pas ma classe [4.x]


Sujet :

Symfony PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut cron job avec docker ne mappe pas ma classe
    Bonjour à tous,

    Voilà j'ai un projet avec docker et supervisor qui run un cron ça marche nickel je le voit au log, par contre quand j'ajoute ma classe en paramètre qui est mappé dans mon service.yml le cron bloque pourtant dans un autre projet cela fonctionne parfaitement.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    <?php
     
    namespace App\Command;
     
    use App\Dao\ContactInformation;
    use App\Entity\CronJobData;
    use App\Service\NotificationApi;
    use Doctrine\ORM\EntityManagerInterface;
    use Symfony\Component\Console\Command\Command;
    use Symfony\Component\Console\Input\InputArgument;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Style\SymfonyStyle;
    use App\Repository\CronJobDataRepository;
     
    class CronNotificationCommand extends Command
    {
        protected static $defaultName = 'cron:notification';
        private $notification;
        private $idCurrentCronData;
     
        public function __construct(EntityManagerInterface $em, NotificationApi $notification)
        {
            parent::__construct();
            $this->em = $em;
            $this->notification = $notification;
        }
     
        protected function configure()
        {
            $this
                ->setDescription('Permit to send notificaton by cron job cron:notification')
                ->addArgument('keyMailjet', InputArgument::REQUIRED, 'see key in avaibles in EnumKeyMailjetId')
            ;
        }
     
        protected function execute(InputInterface $input, OutputInterface $output): int
        {
            $io = new SymfonyStyle($input, $output);
     
            $keyMailjet = (string)$input->getArgument('keyMailjet');
     
            $contact = $this->getContactInformation($keyMailjet);
            dd($contact);
            if($contact)
            {
                $response = $this->notification->sendNotification(
                    $keyMailjet,
                    $contact
                );
                $this->disableContactData($this->idCurrentCronData);
                $io->success('Cron currently work!');
     
                return 0;
            }
     
            $io->note('No data to send!');
            return -1;
     
        }
     
        /**
         * get contact information for notification
         *
         * @param string $keyMailjet
         * @return ContactInformation|null
         */
        private function getContactInformation(string $keyMailjet) : ?ContactInformation
        {
            // get active data and for the cron pass like parameter
            $contact = $this->em->getRepository(CronJobData::class)->findOneBy(
                ['active' => true, 'origin' => $keyMailjet],
                ['id' => 'DESC']
            );
     
            // no active data for this key
            if(empty($contact))
                throw new \Exception("no active data for this key!");
     
            $this->idCurrentCronData = $contact->getId();
     
            $contactInformation= new ContactInformation( $contact->getContactInformation() );
     
            return $contactInformation;
        }
     
        /**
         * Disable cron Data no selected in the next notification
         *
         * @param integer $id cron Data id to disable
         * @return void
         */
        private function disableContactData(int $id)
        {
            $cronData =  $this->em->getRepository(CronJobData::class)->find($id);
            $cronData->setActive(false);
            $this->em->persist($cronData);
            $this->em->flush();
        }
    }
    le service.yml j'ai cette ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    services:
        App\Service\NotificationApi:
    je ne comprends pas la classe dans un autre projet symfony est mappé exactement pareil mais ça ne fonctionne pas .
    merci de votre aide

  2. #2
    Membre Expert

    Homme Profil pro
    développeur
    Inscrit en
    Octobre 2013
    Messages
    1 583
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : développeur

    Informations forums :
    Inscription : Octobre 2013
    Messages : 1 583
    Par défaut
    auto réponse.

    C'était un problème de temps. En effet si vous modifiez le cronjob il faut que supervisord le capte si les services sont bien mappé dans la commande aucun soucis.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 04/12/2014, 19h14
  2. Exécuter un cron job quand mon pc n'est pas allumé
    Par Ismatus1 dans le forum Linux
    Réponses: 7
    Dernier message: 11/11/2011, 18h04
  3. Réponses: 9
    Dernier message: 16/08/2010, 15h09
  4. Menu CSS avec bordures - fonctionne firefox, pas ie
    Par Romalafrite dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 21/11/2004, 15h40
  5. probleme avec requete sql aime pas les strings
    Par lil_jam63 dans le forum Bases de données
    Réponses: 3
    Dernier message: 24/02/2004, 14h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo