some thoughts about scheduling
This commit is contained in:
parent
26114aad5f
commit
544db92b6e
11 changed files with 123 additions and 23 deletions
|
@ -5,7 +5,13 @@
|
|||
|
||||
#include "handler/poll.h"
|
||||
|
||||
Session::Session(unsigned int id, const std::string& access, const std::string& renew):
|
||||
Session::Session(
|
||||
std::weak_ptr<TM::Scheduler> scheduler,
|
||||
unsigned int id,
|
||||
const std::string& access,
|
||||
const std::string& renew
|
||||
):
|
||||
scheduler(scheduler),
|
||||
id(id),
|
||||
access(access),
|
||||
renew(renew),
|
||||
|
@ -22,13 +28,17 @@ std::string Session::getRenewToken() const {
|
|||
|
||||
void Session::accept(std::unique_ptr<Request> request) {
|
||||
if (polling) {
|
||||
Response& res = request->createResponse(Response::Status::ok);
|
||||
nlohmann::json body = nlohmann::json::object();
|
||||
body["result"] = Handler::Poll::Result::replace;
|
||||
|
||||
res.setBody(body);
|
||||
res.send();
|
||||
Handler::Poll::error(*request.get(), Handler::Poll::Result::replace, Response::Status::ok);
|
||||
//TODO unschedule
|
||||
}
|
||||
|
||||
std::shared_ptr<TM::Scheduler> sch = scheduler.lock();
|
||||
if (!sch) {
|
||||
std::cerr << "Was unable to schedule polling timeout, replying with an error" << std::endl;
|
||||
Handler::Poll::error(*request.get(), Handler::Poll::Result::unknownError, Response::Status::internalError);
|
||||
return;
|
||||
}
|
||||
sch->schedule(std::bind(&Session::onTimeout, this), TM::Scheduler::Delay(5000));
|
||||
|
||||
polling = std::move(request);
|
||||
}
|
||||
|
|
|
@ -6,10 +6,16 @@
|
|||
#include <string>
|
||||
|
||||
#include "request/accepting.h"
|
||||
#include "taskmanager/scheduler.h"
|
||||
|
||||
class Session : public Accepting {
|
||||
public:
|
||||
Session(unsigned int id, const std::string& access, const std::string& renew);
|
||||
Session(
|
||||
std::weak_ptr<TM::Scheduler> scheduler,
|
||||
unsigned int id,
|
||||
const std::string& access,
|
||||
const std::string& renew
|
||||
);
|
||||
Session(const Session&) = delete;
|
||||
Session(Session&& other);
|
||||
Session& operator = (const Session&) = delete;
|
||||
|
@ -20,6 +26,10 @@ public:
|
|||
void accept(std::unique_ptr<Request> request) override;
|
||||
|
||||
private:
|
||||
void onTimeout();
|
||||
|
||||
private:
|
||||
std::weak_ptr<TM::Scheduler> scheduler;
|
||||
unsigned int id;
|
||||
std::string access;
|
||||
std::string renew;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue