add a RequestJobBase base class for requests jobs
This commit is contained in:
parent
5e45ad3417
commit
e600aebaae
|
@ -150,6 +150,11 @@ void Job::Add(long job_id, Request * request, pt::Space & job, size_t priority)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Job::RegisterRequestJob(long job_id, RequestJobBase & request_job)
|
||||||
|
{
|
||||||
|
request_jobs.insert(std::make_pair(job_id, &request_job));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t Job::Size(size_t priority) const
|
size_t Job::Size(size_t priority) const
|
||||||
{
|
{
|
||||||
|
@ -270,30 +275,7 @@ void Job::DoJob(JobTask & task, size_t priority)
|
||||||
|
|
||||||
if( task.job_type == JobTask::JOB_TYPE_REQUEST_CONTINUATION )
|
if( task.job_type == JobTask::JOB_TYPE_REQUEST_CONTINUATION )
|
||||||
{
|
{
|
||||||
if( task.request )
|
res = DoRequestJobs(task, task.job_id, priority);
|
||||||
{
|
|
||||||
Cur local_cur;
|
|
||||||
local_cur.request = task.request;
|
|
||||||
local_cur.request->run_state = Request::RunState::job_run;
|
|
||||||
local_cur.session = task.request->session;
|
|
||||||
local_cur.mount = task.request->mount;
|
|
||||||
|
|
||||||
res = plugin->Call(model_connector, &log, &local_cur, WINIX_JOB, &task.job, nullptr, task.job_type, task.job_id);
|
|
||||||
log << logsave;
|
|
||||||
|
|
||||||
{
|
|
||||||
Winix::Lock lock(synchro);
|
|
||||||
Cur old_cur = *cur;
|
|
||||||
*cur = local_cur;
|
|
||||||
DoRequestContinuationJob(task, priority);
|
|
||||||
*cur = old_cur;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log << log2 << "Job: request continuation task doesn't have a request set, skipping the job and request continuation" << logend;
|
|
||||||
log << log2 << "Job: this is an internal error, the request if exists in the queue will never be removed" << logend;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -314,6 +296,50 @@ void Job::DoJob(JobTask & task, size_t priority)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// second thread (objects not locked)
|
||||||
|
PluginRes Job::DoRequestJobs(JobTask & task, long job_id, size_t priority)
|
||||||
|
{
|
||||||
|
PluginRes res;
|
||||||
|
|
||||||
|
if( task.request )
|
||||||
|
{
|
||||||
|
auto jobs_iterator = request_jobs.lower_bound(job_id);
|
||||||
|
|
||||||
|
while( jobs_iterator != request_jobs.end() && jobs_iterator->first == job_id )
|
||||||
|
{
|
||||||
|
task.request->run_state = Request::RunState::job_run;
|
||||||
|
jobs_iterator->second->set_dependency(this);
|
||||||
|
jobs_iterator->second->set_request(task.request);
|
||||||
|
jobs_iterator->second->do_job();
|
||||||
|
jobs_iterator++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Cur local_cur;
|
||||||
|
local_cur.request = task.request;
|
||||||
|
local_cur.request->run_state = Request::RunState::job_run;
|
||||||
|
local_cur.session = task.request->session;
|
||||||
|
local_cur.mount = task.request->mount;
|
||||||
|
|
||||||
|
{
|
||||||
|
Winix::Lock lock(synchro);
|
||||||
|
log << logsave;
|
||||||
|
Cur old_cur = *cur;
|
||||||
|
*cur = local_cur;
|
||||||
|
DoRequestContinuationJob(task, priority);
|
||||||
|
*cur = old_cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
log << log2 << "Job: request continuation task doesn't have a request set, skipping the job and request continuation" << logend;
|
||||||
|
log << log2 << "Job: this is an internal error, the request if exists in the queue will never be removed" << logend;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// second thread (objects locked)
|
// second thread (objects locked)
|
||||||
// use main_log (after locking) for the logs to be in the correct order
|
// use main_log (after locking) for the logs to be in the correct order
|
||||||
void Job::DoRequestContinuationJob(JobTask & job_task, size_t priority)
|
void Job::DoRequestContinuationJob(JobTask & job_task, size_t priority)
|
||||||
|
@ -396,7 +422,6 @@ void Job::RemoveOldRequest(Request * request)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Winix
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012-2022, Tomasz Sowa
|
* Copyright (c) 2012-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
#include "cur.h"
|
#include "cur.h"
|
||||||
#include "loadavg.h"
|
#include "loadavg.h"
|
||||||
#include "mounts.h"
|
#include "mounts.h"
|
||||||
|
#include "requestjobs/requestjobbase.h"
|
||||||
|
|
||||||
|
|
||||||
namespace Winix
|
namespace Winix
|
||||||
|
@ -84,6 +84,11 @@ public:
|
||||||
void Add(long job_id, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
void Add(long job_id, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
||||||
void Add(long job_id, Request * request, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
void Add(long job_id, Request * request, pt::Space & job, size_t priority = PRIORITY_DEFAULT);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* register a new request job worker
|
||||||
|
*/
|
||||||
|
void RegisterRequestJob(long job_id, RequestJobBase & request_job);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
queue size, and size of all jobs in any priority
|
queue size, and size of all jobs in any priority
|
||||||
*/
|
*/
|
||||||
|
@ -107,9 +112,10 @@ private:
|
||||||
Mounts * mounts;
|
Mounts * mounts;
|
||||||
std::list<Request> * req_tab;
|
std::list<Request> * req_tab;
|
||||||
|
|
||||||
typedef std::queue<JobTask> JobsQueue;
|
typedef std::queue<JobTask> JobsQueue;
|
||||||
typedef std::vector<JobsQueue> JobsQueueTab;
|
typedef std::vector<JobsQueue> JobsQueueTab;
|
||||||
JobsQueueTab jobs_queue_tab;
|
JobsQueueTab jobs_queue_tab;
|
||||||
|
std::multimap<long, RequestJobBase*> request_jobs;
|
||||||
|
|
||||||
void CheckPriority(size_t & priority) const;
|
void CheckPriority(size_t & priority) const;
|
||||||
void SaveToFile();
|
void SaveToFile();
|
||||||
|
@ -132,6 +138,7 @@ private:
|
||||||
void DoRequestContinuationJob(JobTask & job_task, size_t priority);
|
void DoRequestContinuationJob(JobTask & job_task, size_t priority);
|
||||||
void DoWinixJob(pt::Space & job);
|
void DoWinixJob(pt::Space & job);
|
||||||
void RemoveOldRequest(Request * request);
|
void RemoveOldRequest(Request * request);
|
||||||
|
PluginRes DoRequestJobs(JobTask & task, long job_id, size_t priority);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -333,13 +333,6 @@ namespace Winix
|
||||||
// session is null
|
// session is null
|
||||||
// if you process the job then return 'true' from the processing method (from plugin call)
|
// if you process the job then return 'true' from the processing method (from plugin call)
|
||||||
// so this prevent to make a standard (system) job
|
// so this prevent to make a standard (system) job
|
||||||
// in l1 there is a job type (from JobTask structure), e.g. if you want to know whether
|
|
||||||
// the job is a request continuation you should compare l1 == JobTask::JOB_TYPE_REQUEST_CONTINUATION
|
|
||||||
// in l2 there is a job_id - the values passed to the Job::Add(long job_id, ...) method
|
|
||||||
// if you have called Add(...) without long job_id parameter then the default value JobTask::JOB_ID_DEFAULT is used
|
|
||||||
// if the job type is JobTask::JOB_TYPE_REQUEST_CONTINUATION then a pointer to Session can be set,
|
|
||||||
// such a Session has allow_to_delete flag set to false but of course you have to Lock/Unlock when
|
|
||||||
// you are using this structure
|
|
||||||
#define WINIX_JOB 31200
|
#define WINIX_JOB 31200
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "requestjobbase.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
RequestJobBase::RequestJobBase()
|
||||||
|
{
|
||||||
|
req = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RequestJobBase::~RequestJobBase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void RequestJobBase::set_request(Request * req)
|
||||||
|
{
|
||||||
|
this->req = req;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RequestJobBase::do_job()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* This file is a part of Winix
|
||||||
|
* and is distributed under the 2-Clause BSD licence.
|
||||||
|
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Tomasz Sowa
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||||
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef headerfile_winix_requestjobs_requestjobbase
|
||||||
|
#define headerfile_winix_requestjobs_requestjobbase
|
||||||
|
|
||||||
|
#include "core/winixmodeldeprecated.h"
|
||||||
|
#include "core/request.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Winix
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class RequestJobBase : public WinixModelDeprecated
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
RequestJobBase();
|
||||||
|
virtual ~RequestJobBase();
|
||||||
|
|
||||||
|
void set_request(Request * req);
|
||||||
|
virtual void do_job();
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
Request * req;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Winix
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue