Added exception handling around Beanstalk

This commit is contained in:
Matt Hill
2014-07-02 19:25:07 -04:00
parent e0377c1d4d
commit 1608886cba

View File

@@ -274,7 +274,8 @@ void streamRecognitionThread(void* arg)
bool writeToQueue(std::string jsonResult)
{
try
{
Beanstalk::Client client(BEANSTALK_QUEUE_HOST, BEANSTALK_PORT);
client.use(BEANSTALK_TUBE_NAME);
@@ -288,6 +289,11 @@ bool writeToQueue(std::string jsonResult)
LOG4CPLUS_INFO(logger, "put job id: " << id );
}
catch (const std::runtime_error& error)
{
LOG4CPLUS_WARN(logger, "Error writing to Beanstalk. Result has not been saved.");
}
return true;
}
@@ -302,12 +308,18 @@ void dataUploadThread(void* arg)
UploadThreadData* udata = (UploadThreadData*) arg;
Beanstalk::Client client(BEANSTALK_QUEUE_HOST, BEANSTALK_PORT);
while(daemon_active)
{
try
{
Beanstalk::Client client(BEANSTALK_QUEUE_HOST, BEANSTALK_PORT);
client.watch(BEANSTALK_TUBE_NAME);
while(daemon_active)
while (daemon_active)
{
Beanstalk::Job job;
@@ -328,9 +340,19 @@ void dataUploadThread(void* arg)
}
}
// Wait 10ms
usleep(10000);
}
}
catch (const std::runtime_error& error)
{
LOG4CPLUS_WARN(logger, "Error connecting to Beanstalk. Will retry." );
}
// wait 5 seconds
usleep(5000000);
}
curl_global_cleanup();
}