Esempio n. 1
0
 public function handle(Pusher $pusher)
 {
     $timeStarted = time();
     $key = $this->writePrivateKey();
     try {
         $this->release->update(['status' => Release::RUNNING, 'started_at' => new \DateTime()]);
         $ansible = new Ansible($this->release->path(), Release::INVENTORY_FILENAME, Release::PLAYBOOK_FILENAME, $this->release->inventory->params + ['private_key' => $key]);
         $process = $ansible->play();
         $process->start();
         $lastOut = $process->getOutput();
         while ($process->isRunning() && !$this->release->isCancelled()) {
             $out = $process->getOutput();
             if ($lastOut != $out) {
                 $this->updateRelease($process);
                 $pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray());
                 $lastOut = $out;
             }
             sleep(1);
         }
         if ($process->isRunning()) {
             $process->stop(0);
         }
         $this->fs()->delete($key);
         $this->updateRelease($process);
         if ($this->release->status == Release::CANCELLED) {
             $pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray());
         } elseif ($process->getExitCode() == 0) {
             $this->notifier()->notifySuccess($this->release);
             $this->release->update(['status' => Release::COMPLETED, 'time' => time() - $timeStarted]);
             $pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray());
         } else {
             $this->notifier()->notifyFailure($this->release, $process->getErrorOutput());
             throw new AnsibleException($this->release, $ansible, $process->getErrorOutput());
         }
     } catch (\Exception $e) {
         $this->release->update(['status' => Release::ERROR, 'time' => time() - $timeStarted]);
         $pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray());
         $this->fs()->delete($key);
         throw $e;
     }
 }
Esempio n. 2
0
 /**
  * @param Pusher $pusher
  * @throws \Exception
  */
 public function handle(Pusher $pusher)
 {
     try {
         if ($this->release->isCancelled()) {
             return;
         }
         $this->release->update(['status' => Release::PREPARING]);
         $pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray());
         $this->prepareReleaseDir();
         $this->createArchive();
         $this->extractArchive();
         $this->writePlaybooks();
         if ($this->release->isCancelled()) {
             return;
         }
         $this->dispatch(new PlaybookJob($this->release));
         $this->dispatch(new CleanupReleasesJob($this->release->repo));
     } catch (\Exception $e) {
         $this->release->update(['status' => Release::ERROR, 'raw_logs' => $e->getMessage()]);
         $pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray());
         throw $e;
     }
 }
Esempio n. 3
0
 public function get(Release $release)
 {
     return $release->toArray() + ['time_avg' => $release->avg()];
 }
Esempio n. 4
0
 protected function pushRelease(array $data = [])
 {
     $this->pusher->trigger(['releases'], "release-" . $this->release->id, $this->release->toArray() + $data);
 }