public function postEnqueueCommand(Request $request) { $input = $request->only(['command']); try { $success = CommandQueue::enqueue($input['command']); } catch (CommandParserException $e) { return $this->unableToParseJsonResponse($e->getMessage()); } if ($success) { return response()->json(['message' => 'command_enqueued_successfully']); } else { return $this->internalServerErrorJsonResponse('Unable to enqueue command correctly'); } }
public function postEnqueueCommand(Request $request) { $initial = ExecutedCommand::latest(); $input = $request->only(['command']); try { $success = CommandQueue::enqueue($input['command']); } catch (CommandParserException $e) { return $this->unableToParseJsonResponse($e->getMessage()); } if (!$success) { return $this->internalServerErrorJsonResponse('Unable to enqueue command correctly'); } // Command enqueued successfully, now wait for response $getResponse = function () use($initial) { $result = ExecutedCommand::latest(); if ($result && $result->response && (!$initial || $result->timestamp !== $initial->timestamp)) { return response()->json($result); } else { return null; } }; return $this->serveLongPolling($getResponse, response()->json(['response' => 'none'])); }