public function run_post(Request $request, $id)
 {
     $msg = Utils::output($request);
     file_put_contents(storage_path("tmp/log" . $id . ".txt"), $msg, FILE_APPEND | LOCK_EX);
     $client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client('tcp://127.0.0.1:8889'));
     $client->connect();
     $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $id, "msg" => $msg]));
     $client->close();
 }
Esempio n. 2
0
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     echo "Run task: #" . $this->job_id, "\n";
     $task = Tasks::find($this->job_id);
     $task->status = Tasks::RUN;
     $task->save();
     $client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client('tcp://127.0.0.1:8889'));
     $client->setHost('127.0.0.1');
     $client->connect();
     $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::RUN])]));
     $builder = new ProcessBuilder();
     $builder->setPrefix('ansible-playbook');
     $builder->setArguments(["-i", "inv" . $this->job_id, "yml" . $this->job_id]);
     $builder->setWorkingDirectory(storage_path("roles"));
     $process = $builder->getProcess();
     $process->run();
     //echo $process->getOutput() . "\n";
     $client->send(json_encode(["command" => webSocket::BROADCASTIF, "jobid" => $this->job_id, "msg" => json_encode(["jid" => $this->job_id, "status" => Tasks::FINISH])]));
     $client->close();
     $task->status = Tasks::FINISH;
     $task->content = file_get_contents(storage_path("tmp/log" . $this->job_id . ".txt"));
     $task->save();
     unlink(storage_path("roles/yml" . $this->job_id));
     unlink(storage_path("roles/inv" . $this->job_id));
     unlink(storage_path("tmp/log" . $this->job_id . ".txt"));
     echo "End task: #" . $this->job_id, "\n";
 }
Esempio n. 3
0
 function sendTo($contact_ids_array, $message)
 {
     if (!$this->server) {
         return;
     }
     $response = null;
     $uu_ids = [];
     foreach ($contact_ids_array as $id) {
         $uu_ids[] = $this->app->current_website_name . '_' . $id;
     }
     $data = ['clients' => $uu_ids, 'message' => $message, 'cmd' => 'notification'];
     $client = new \Hoa\Websocket\Client(new \Hoa\Socket\Client($this->server));
     $client->on('message', function (\Hoa\Event\Bucket $bucket) use(&$response) {
         $data = $bucket->getData();
         $response = $data['message'];
         return $response;
     });
     $client->connect();
     $client->send(json_encode($data));
     $client->receive();
     $client->close();
     return $response;
 }