X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;ds=sidebyside;f=src%2Fdb%2Fpsql.cpp;h=cdbce22393a253c00734008feb4e75dde5742c8a;hb=89ac41e5e9719c782b17ecfd81d9c7a276552312;hp=8ddc7f1c449b0b2f584f524b7bb0ad8c5c7c39c5;hpb=3e192fd092ecbc8725a02afc9b6fb90934b258fb;p=cassiopeia.git diff --git a/src/db/psql.cpp b/src/db/psql.cpp index 8ddc7f1..cdbce22 100644 --- a/src/db/psql.cpp +++ b/src/db/psql.cpp @@ -24,7 +24,7 @@ PostgresJobProvider::PostgresJobProvider( const std::string& server, const std:: std::shared_ptr PostgresJobProvider::fetchJob() { - std::string q = "SELECT id, \"targetId\", task, \"executeFrom\", \"executeTo\", warning FROM jobs WHERE state='open' AND warning < 3"; + std::string q = "SELECT id, \"targetId\", task, \"executeFrom\", \"executeTo\", attempt FROM jobs WHERE state='open' AND attempt < 3"; pqxx::work txn( c ); pqxx::result result = txn.exec( q ); @@ -40,10 +40,9 @@ std::shared_ptr PostgresJobProvider::fetchJob() { job->task = result[0]["task"].as(); job->from = result[0]["\"executeFrom\""].as( "" ); job->to = result[0]["\"executeTo\""].as( "" ); - job->warning = result[0]["warning"].as(); - - logger::notef( "Got a job: (id=%s, target=%s, task=%s, from=%s, to=%s, warnings=%s)", job->id, job->target, job->task, job->from, job->to, job->warning ); + job->attempt = result[0]["attempt"].as(); + logger::notef( "Got a job: (id=%s, target=%s, task=%s, from=%s, to=%s, attempts=%s)", job->id, job->target, job->task, job->from, job->to, job->attempt ); return job; } @@ -57,19 +56,25 @@ void PostgresJobProvider::finishJob( std::shared_ptr job ) { throw std::runtime_error( "No database entry found." ); } + c.prepare( "insertLog", "INSERT INTO \"jobLog\"(\"jobid\", \"attempt\", \"content\") VALUES($1,$2,$3)" ); + txn.prepared( "insertCrt" )( job->id )( job->attempt )( job->log.str() ).exec(); + txn.commit(); } void PostgresJobProvider::failJob( std::shared_ptr job ) { pqxx::work txn( c ); - std::string q = "UPDATE jobs SET warning = warning + 1 WHERE id=" + txn.quote( job->id ); + std::string q = "UPDATE jobs SET attempt = attempt + 1 WHERE id=" + txn.quote( job->id ); pqxx::result r = txn.exec( q ); if( r.affected_rows() != 1 ) { throw std::runtime_error( "No database entry found." ); } + c.prepare( "insertLog", "INSERT INTO \"jobLog\"(\"jobid\", \"attempt\", \"content\") VALUES($1,$2,$3)" ); + txn.prepared( "insertCrt" )( job->id )( job->attempt )( job->log.str() ).exec(); + txn.commit(); }