allow a request to be processed in a job

Now we allow a request to be passed into a job queue,
and after the job finishes the request is passed into
a controller again. In order to achieve this we have
a requests queue in System, when we put a request
to the job this Request structure is preserved in the
queue and for a new request a new Request is added to
the queue.

while here:
- remove App::Lock()/Unlock(), use scoped locking
- fix: Plugin now has a Call method which takes ModelConnector
  and a logger (used in multithreaded environment)
- BaseThread has a main_model_connector pointer
  to the main (from the main thread) model connector
- the FastCGI structure fcgi_request moved from App to Request
- some methods for handling requests moved from App to Request
- small refactoring in main.cpp
- add Http class (a http client)
This commit is contained in:
2022-07-25 14:21:21 +02:00
parent b2d92b85a0
commit 979ef907fe
65 changed files with 7018 additions and 4437 deletions

View File

@@ -5,7 +5,7 @@
*/
/*
* Copyright (c) 2010-2021, Tomasz Sowa
* Copyright (c) 2010-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -137,7 +137,6 @@ bool System::Init()
mounts.SkipStaticDirs(config->dont_use_static_dirs);
mounts.SetDirs(&dirs);
mounts.SetDb(db);
mounts.SetCur(cur); // only one method is using cur, can be passed as a parameter to the method
mounts.CreateMounts();
mounts.ReadMounts();
@@ -168,6 +167,12 @@ bool System::Init()
if( !thread_manager.Add(&image, L"image") )
return false;
job.SetCur(cur);
job.SetFunctions(functions);
job.SetLoadAvg(&load_avg);
job.SetMounts(&mounts);
job.SetReqTab(&req_tab);
// SetSynchro will be called by ThreadManager itself
// job.ReadFromFile();
if( !thread_manager.Add(&job, L"job") )
@@ -1440,7 +1445,7 @@ bool System::FollowAllLinks(const std::wstring & link_to,
log << log3 << "System: current directory changed and the new file loaded" << logend;
}
mounts.CalcCurMount();
mounts.CalcCurMount(cur->request);
}
else
{
@@ -1522,5 +1527,28 @@ bool System::AddCommonFileToVar(const wchar_t * file_path, const wchar_t * url,
void System::DeleteOldRequests(bool leave_one_object)
{
std::list<Request>::iterator i = req_tab.begin();
while( i != req_tab.end() )
{
// leave at least one object (even if it is finished)
if( i->run_state == Request::RunState::finished && (!leave_one_object || req_tab.size() > 1) )
{
log << log3 << "System: removing finished request " << cur->request << logend;
std::list<Request>::iterator old_i = i;
++i;
req_tab.erase(old_i);
}
else
{
++i;
}
}
}
} // namespace Winix