mirror of
https://github.com/ohwgiles/laminar.git
synced 2024-10-27 20:34:20 +00:00
refactor: remove run page json type hack
this hack tried to avoid sending unnecessary data to the frontend, but it was more trouble than it's worth
This commit is contained in:
parent
39ca7e86cf
commit
ba472711be
10
src/http.cpp
10
src/http.cpp
@ -278,16 +278,10 @@ kj::Promise<void> Http::startServer(kj::Timer& timer, kj::Own<kj::ConnectionRece
|
||||
return server->listenHttp(*listener).attach(cleanupPeers(timer)).attach(kj::mv(listener)).attach(kj::mv(server));
|
||||
}
|
||||
|
||||
void Http::notifyEvent(const char *type, const char *data, std::string job, uint run)
|
||||
void Http::notifyEvent(const char *data, std::string job)
|
||||
{
|
||||
for(EventPeer* c : eventPeers) {
|
||||
if(c->scope.wantsStatus(job, run)
|
||||
// The run page also should know that another job has started
|
||||
// (so maybe it can show a previously hidden "next" button).
|
||||
// Hence this small hack:
|
||||
// TODO obviate
|
||||
|| (std::string(type)=="job_started" && c->scope.type == MonitorScope::Type::RUN && c->scope.job == job))
|
||||
{
|
||||
if(c->scope.wantsStatus(job)) {
|
||||
c->pendingOutput.push_back("data: " + std::string(data) + "\n\n");
|
||||
c->fulfiller->fulfill();
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public:
|
||||
|
||||
kj::Promise<void> startServer(kj::Timer &timer, kj::Own<kj::ConnectionReceiver> &&listener);
|
||||
|
||||
void notifyEvent(const char* type, const char* data, std::string job = nullptr, uint run = 0);
|
||||
void notifyEvent(const char* data, std::string job = nullptr);
|
||||
void notifyLog(std::string job, uint run, std::string log_chunk, bool eot);
|
||||
|
||||
private:
|
||||
|
@ -574,7 +574,7 @@ std::shared_ptr<Run> Laminar::queueJob(std::string name, ParamMap params) {
|
||||
.startObject("data")
|
||||
.set("name", name)
|
||||
.EndObject();
|
||||
http->notifyEvent("job_queued", j.str(), name.c_str());
|
||||
http->notifyEvent(j.str(), name.c_str());
|
||||
|
||||
assignNewJobs();
|
||||
return run;
|
||||
@ -666,7 +666,7 @@ bool Laminar::tryStartRun(std::shared_ptr<Run> run, int queueIndex) {
|
||||
}
|
||||
j.EndArray();
|
||||
j.EndObject();
|
||||
http->notifyEvent("job_started", j.str(), run->name.c_str(), run->build);
|
||||
http->notifyEvent(j.str(), run->name.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -755,7 +755,7 @@ void Laminar::runFinished(Run * r) {
|
||||
populateArtifacts(j, r->name, r->build);
|
||||
j.EndArray();
|
||||
j.EndObject();
|
||||
http->notifyEvent("job_completed", j.str(), r->name, r->build);
|
||||
http->notifyEvent(j.str(), r->name);
|
||||
http->notifyLog(r->name, r->build, "", true);
|
||||
// erase reference to run from activeJobs. Since runFinished is called in a
|
||||
// lambda whose context contains a shared_ptr<Run>, the run won't be deleted
|
||||
@ -797,7 +797,7 @@ bool Laminar::handleBadgeRequest(std::string job, std::string &badge) {
|
||||
db->stmt("SELECT result FROM builds WHERE name = ? ORDER BY number DESC LIMIT 1")
|
||||
.bind(job)
|
||||
.fetch<int>([&](int result){
|
||||
rs = (RunState) result;
|
||||
rs = RunState(result);
|
||||
});
|
||||
if(rs == RunState::UNKNOWN)
|
||||
return false;
|
||||
|
@ -41,19 +41,20 @@ struct MonitorScope {
|
||||
order_desc(true)
|
||||
{}
|
||||
|
||||
// whether this scope wants status information about the given job or run
|
||||
// whether this scope wants status information for the specified job
|
||||
bool wantsStatus(std::string ajob, uint anum = 0) const {
|
||||
if(type == HOME || type == ALL) return true;
|
||||
if(type == JOB) return ajob == job;
|
||||
if(type == RUN) return ajob == job && anum == num;
|
||||
return false;
|
||||
else return ajob == job;
|
||||
// we could have checked that the run number matches, but actually the
|
||||
// run page needs to know about a non-matching run number in order to
|
||||
// know whether to display the "next" arrow.
|
||||
}
|
||||
|
||||
Type type;
|
||||
std::string job;
|
||||
uint num = 0;
|
||||
uint num ;
|
||||
// sorting
|
||||
uint page = 0;
|
||||
uint page;
|
||||
std::string field;
|
||||
bool order_desc;
|
||||
};
|
||||
|
@ -73,3 +73,31 @@ TEST_F(LaminarFixture, JobNotifyHomePage) {
|
||||
EXPECT_STREQ("foo", job_completed["data"]["name"].GetString());
|
||||
}
|
||||
|
||||
TEST_F(LaminarFixture, OnlyRelevantNotifications) {
|
||||
defineJob("job1", "true");
|
||||
defineJob("job2", "true");
|
||||
|
||||
auto esHome = eventSource("/");
|
||||
auto esJobs = eventSource("/jobs");
|
||||
auto es1Job = eventSource("/jobs/job1");
|
||||
auto es2Job = eventSource("/jobs/job2");
|
||||
auto es1Run = eventSource("/jobs/job1/1");
|
||||
auto es2Run = eventSource("/jobs/job2/1");
|
||||
|
||||
auto req1 = client().runRequest();
|
||||
req1.setJobName("job1");
|
||||
ASSERT_EQ(LaminarCi::JobResult::SUCCESS, req1.send().wait(ioContext.waitScope).getResult());
|
||||
auto req2 = client().runRequest();
|
||||
req2.setJobName("job2");
|
||||
ASSERT_EQ(LaminarCi::JobResult::SUCCESS, req2.send().wait(ioContext.waitScope).getResult());
|
||||
ioContext.waitScope.poll();
|
||||
|
||||
EXPECT_EQ(7, esHome->messages().size());
|
||||
EXPECT_EQ(7, esJobs->messages().size());
|
||||
|
||||
EXPECT_EQ(4, es1Job->messages().size());
|
||||
EXPECT_EQ(4, es2Job->messages().size());
|
||||
|
||||
EXPECT_EQ(4, es1Run->messages().size());
|
||||
EXPECT_EQ(4, es2Run->messages().size());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user