Commit 09988fa6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Add a retry count to avoid trying to parse the same media forever

parent f1ec2e4b
......@@ -39,6 +39,7 @@ int64_t File::* const policy::FileTable::PrimaryKey = &File::m_id;
File::File( MediaLibraryPtr ml, sqlite::Row& row )
: m_ml( ml )
{
bool dummyNbRetries;
row >> m_id
>> m_mediaId
>> m_mrl
......@@ -46,6 +47,7 @@ File::File( MediaLibraryPtr ml, sqlite::Row& row )
>> m_lastModificationDate
>> m_size
>> m_parserSteps
>> dummyNbRetries
>> m_folderId
>> m_isPresent
>> m_isRemovable
......@@ -133,7 +135,8 @@ void File::markStepCompleted( ParserStep step )
bool File::saveParserStep()
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET parser_step = ? WHERE id_file = ?";
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET parser_step = ?, "
"parser_retries = 0 WHERE id_file = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_parserSteps, m_id ) == false )
return false;
return true;
......@@ -144,6 +147,13 @@ File::ParserStep File::parserStep() const
return m_parserSteps;
}
void File::startParserStep()
{
static const std::string req = "UPDATE " + policy::FileTable::Name + " SET "
"parser_retries = parser_retries + 1 WHERE id_file = ?";
sqlite::Tools::executeUpdate( m_ml->getConn(), req, m_id );
}
std::shared_ptr<Media> File::media() const
{
auto lock = m_media.lock();
......@@ -169,6 +179,7 @@ bool File::createTable( DBConnection dbConnection )
"last_modification_date UNSIGNED INT,"
"size UNSIGNED INT,"
"parser_step INTEGER NOT NULL DEFAULT 0,"
"parser_retries INTEGER NOT NULL DEFAULT 0,"
"folder_id UNSIGNED INTEGER,"
"is_present BOOLEAN NOT NULL DEFAULT 1,"
"is_removable BOOLEAN NOT NULL,"
......
......@@ -77,6 +77,10 @@ public:
void markStepCompleted( ParserStep step );
bool saveParserStep();
ParserStep parserStep() const;
/**
* @brief startParserStep Do some internal book keeping to avoid restarting a step too many time
*/
void startParserStep();
std::shared_ptr<Media> media() const;
bool destroy();
......
......@@ -102,7 +102,7 @@ void Parser::restore()
return;
static const std::string req = "SELECT * FROM " + policy::FileTable::Name
+ " WHERE parser_step != ? AND is_present = 1 AND folder_id IS NOT NULL";
+ " WHERE parser_step != ? AND is_present = 1 AND folder_id IS NOT NULL AND parser_retries < 3";
auto files = File::fetchAll<File>( m_ml, req, File::ParserStep::Completed );
LOG_INFO( "Resuming parsing on ", files.size(), " mrl" );
......
......@@ -154,6 +154,7 @@ void ParserService::mainloop()
try
{
LOG_INFO( "Executing ", serviceName, " task on ", task->file->mrl() );
task->file->startParserStep();
status = run( *task );
LOG_INFO( "Done executing ", serviceName, " task on ", task->file->mrl() );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment