Permalink
Browse files

More cleanly handle cases when the database connection cannot be crea…

…ted.
  • Loading branch information...
Heikki Linnakangas authored and dpage committed Sep 29, 2011
1 parent b7b3579 commit 45fe6cd9c8faf50bbee575c5930c3d1f243d7d71
Showing with 22 additions and 5 deletions.
  1. +6 −4 job.cpp
  2. +16 −1 pgAgent.cpp
View
10 job.cpp
@@ -354,11 +354,13 @@ JobThread::JobThread(const wxString &jid)
jobid = jid;
DBconn *threadConn = DBconn::Get(DBconn::GetBasicConnectString(), serviceDBname);
- job = new Job(threadConn, jobid);
-
- if (job->Runnable())
- runnable = true;
+ if (threadConn)
+ {
+ job = new Job(threadConn, jobid);
+ if (job->Runnable())
+ runnable = true;
+ }
}
View
@@ -109,8 +109,23 @@ int MainRestartLoop(DBconn *serviceConn)
jt->Run();
foundJobToExecute = true;
}
+ else
+ {
+ // Failed to launch the thread. Insert an entry with
+ // "internal error" status in the joblog table, to leave
+ // a trace of fact that we tried to launch the job.
+ DBresult *res = serviceConn->Execute(
+ wxT("INSERT INTO pgagent.pga_joblog(jlgid, jlgjobid, jlgstatus) ")
+ wxT("VALUES (nextval('pgagent.pga_joblog_jlgid_seq'), ") + jobid + wxT(", 'i')"));
+ if (res)
+ delete res;
+
+ // A thread object that's started will destroy itself when
+ // it's finished, but one that never starts we'll have to
+ // destory ourselves.
+ delete jt;
+ }
res->MoveNext();
-
}
delete res;

0 comments on commit 45fe6cd

Please sign in to comment.