/** * @inheritdoc * * @param Task $task */ public function handle(Task $task) { $config = $task->getData(); if ($config["driver"] === "mysql") { $config += ["host" => "127.0.0.1", "port" => 3306, "charset" => "utf8", "socket" => null]; } if ($config["remit"]["driver"] === "zeromq") { $config["remit"]["server"] += ["host" => "127.0.0.1"]; $config["remit"]["client"] += ["host" => "127.0.0.1"]; $server = new ZeroMqServer(new InMemoryLocation($config["remit"]["client"]["host"], $config["remit"]["client"]["port"])); $client = new ZeroMqClient(new InMemoryLocation($config["remit"]["server"]["host"], $config["remit"]["server"]["port"])); } $connection = new ExtendedPdo(new PDO($this->newConnectionString($config), $config["username"], $config["password"])); $server->addListener("q", function ($query, $values, $id) use($client, $connection) { $client->emit("r", [$connection->fetchAll($query, $values), $id]); }); $server->addListener("d", function () use($connection, $server, $client) { $client->emit("dd"); try { $connection->disconnect(); } catch (Exception $exception) { // TODO: find an elegant way to deal with this } $server->disconnect(); $client->disconnect(); Loop\stop(); }); Loop\periodic(0, function () use($server) { $server->tick(); }); Loop\run(); }
/** * @inheritdoc * * @param Task $task */ public function handle(Task $task) { $data = $task->getData(); if (isset($data["closure"])) { $closure = $data["closure"]; $closure($this, $task); } }
/** * @inheritdoc * * @param Task $task */ public function handle(Task $task) { $data = $task->getData(); if (isset($data["callback"])) { $callback = $data["callback"]; $callback(); } }
/** * @inheritdoc * * @return array */ public function getData() { return $this->task->getData(); }