7dcf1302df1abed662c1eb4ef504e00b4a40dee1
braney
  Mon Dec 17 14:09:00 2012 -0800
re-try a hub with an error message after a hg.conf configurable amount of time has passed (#9666)
diff --git src/hg/lib/hubConnect.c src/hg/lib/hubConnect.c
index d683799..06c7a4c 100644
--- src/hg/lib/hubConnect.c
+++ src/hg/lib/hubConnect.c
@@ -136,57 +136,68 @@
 if (errCatch->gotError)
     {
     gotWarning = TRUE;
     *errorMessage = cloneString(errCatch->message->string);
     }
 errCatchFree(&errCatch);
 
 if (gotWarning)
     {
     return NULL;
     }
 
 return tHub;
 }
 
+static boolean
+hubTimeToCheck(struct hubConnectStatus *hub, char *notOkStatus)
+/* check to see if enough time has passed to re-check a hub that
+ * has an error status.  Default time to wait is 30 minutes, but this
+ * is configurable with the hub.timeToCheck conf variable */
+{
+char *checkTimeString = cfgOptionDefault(hgHubConnectTimeToCheck, "1800");
+time_t checkTime = sqlUnsigned(checkTimeString);
+return dateIsOlderBy(notOkStatus, "%F %T", checkTime);
+}
+
 /* Given a hub ID return associated status. Returns NULL if no such hub.  If hub
  * exists but has problems will return with errorMessage field filled in. */
 struct hubConnectStatus *hubConnectStatusForId(struct sqlConnection *conn, int id)
 {
 struct hubConnectStatus *hub = NULL;
 char query[1024];
 safef(query, sizeof(query), 
-    "select hubUrl,status, errorMessage from %s where id=%d", getHubStatusTableName(), id);
+    "select hubUrl,status, errorMessage,lastNotOkTime from %s where id=%d", getHubStatusTableName(), id);
 struct sqlResult *sr = sqlGetResult(conn, query);
 char **row = sqlNextRow(sr);
 if (row != NULL)
     {
     AllocVar(hub);
     hub->id = id;
     hub->hubUrl = cloneString(row[0]);
     hub->status = sqlUnsigned(row[1]);
     hub->errorMessage = cloneString(row[2]);
 
-    if (isEmpty(row[2]))
+    if (isEmpty(row[2]) || hubTimeToCheck(hub, row[3]))
 	{
 	char *errorMessage = NULL;
 	hub->trackHub = fetchHub( hub->hubUrl, &errorMessage);
-	if (errorMessage != NULL)
-	    {
 	    hub->errorMessage = cloneString(errorMessage);
-	    warn("%s", hub->errorMessage);
 	    hubUpdateStatus( hub->errorMessage, hub);
+	if (!isEmpty(hub->errorMessage))
+	    {
+	    warn("%s", hub->errorMessage);
 	    }
 	}
     }
 sqlFreeResult(&sr);
 return hub;
 }
 
 struct hubConnectStatus *hubConnectStatusListFromCartAll(struct cart *cart)
 /* Return list of all track hubs that are referenced by cart. */
 {
 struct hubConnectStatus *hubList = NULL, *hub;
 struct slPair *pair, *pairList = cartVarsWithPrefix(cart, hgHubConnectHubVarPrefix);
 struct sqlConnection *conn = hConnectCentral();
 for (pair = pairList; pair != NULL; pair = pair->next)
     {