looqs/shared/filescanworker.cpp

37 líneas
793 B
C++
Original Vista normal Histórico

2022-04-14 14:58:07 +02:00
#include "filescanworker.h"
#include "logger.h"
2022-04-15 21:06:19 +02:00
FileScanWorker::FileScanWorker(SqliteDbService &db, ConcurrentQueue<QString> &queue, int batchsize,
std::atomic<bool> &stopToken)
2022-04-14 14:58:07 +02:00
{
this->dbService = &db;
this->queue = &queue;
this->batchsize = batchsize;
2022-04-15 21:06:19 +02:00
this->stopToken = &stopToken;
2022-04-14 14:58:07 +02:00
}
void FileScanWorker::run()
{
FileSaver saver{*this->dbService};
auto paths = queue->dequeue(batchsize);
for(QString &path : paths)
{
SaveFileResult sfr;
try
{
sfr = saver.addFile(path);
}
catch(std::exception &e)
2022-04-14 14:58:07 +02:00
{
Logger::error() << e.what();
sfr = PROCESSFAIL; // well...
}
emit result({path, sfr});
2022-04-15 21:06:19 +02:00
if(stopToken->load(std::memory_order_relaxed)) // TODO: relaxed should suffice here, but recheck
{
emit finished();
return;
}
2022-04-14 14:58:07 +02:00
}
emit finished();
}