49208fc971d214da618be9cc0108a2acb7340613
kent
  Thu Jan 9 21:53:17 2014 -0800
Moving pmSendStringWithRetries and pmHubSingleLineQuery from para application to library, so the edwAnalysisDaemon can use it too.
diff --git src/parasol/para/para.c src/parasol/para/para.c
index 0d87bf9..88369fa 100644
--- src/parasol/para/para.c
+++ src/parasol/para/para.c
@@ -688,72 +688,30 @@
     {
     line = skipLeadingSpaces(line);
     if (line[0] == '#' || line[0] == 0)
        continue;
     job = jobCommaIn(&line, NULL);
     slAddHead(&db->jobList, job);
     ++db->jobCount;
     }
 lineFileClose(&lf);
 slReverse(&db->jobList);
 verbose(1, "%d jobs in batch\n", db->jobCount);
 verbose(2, "readBatch time: %.2f seconds\n", (clock1000() - time) / 1000.0);
 return db;
 }
 
-
-boolean pmSendStringWithRetries(struct paraMessage *pm, struct rudp *ru, char *string)
-/* Send out given message strng.  Print warning message and return FALSE if
- * there is a problem. Try up to 5 times sleeping for 60 seconds in between.
- * This is an attempt to help automated processes. */
-{
-int tries = 0;
-#define PMSENDSLEEP 60
-#define PMSENDMAXTRIES 5
-boolean result = FALSE;
-while (TRUE)
-    {
-    result = pmSendString(pm, ru, string);
-    if (result)
-	break;
-    warn("pmSendString timed out!");
-    ++tries;
-    if (tries >= PMSENDMAXTRIES)
-	break;
-    warn("pmSendString: will sleep %d seconds and retry", PMSENDSLEEP);
-    sleep(PMSENDSLEEP);
-    }
-return result;
-}
-
-
-char *hubSingleLineQuery(char *query)
-/* Send message to hub and get single line response.
- * This should be freeMem'd when done. */
-{
-struct rudp *ru = rudpMustOpen();
-struct paraMessage pm;
-
-pmInitFromName(&pm, "localhost", paraHubPort);
-if (!pmSendStringWithRetries(&pm, ru, query))
-    noWarnAbort();
-if (!pmReceive(&pm, ru))
-    noWarnAbort();
-rudpClose(&ru);
-return cloneString(pm.data);
-}
-
 struct slRef *hubMultilineQuery(char *query)
 /* Send a command with a multiline response to hub,
  * and return response as a list of strings. */
 {
 struct slRef *list = NULL;
 struct rudp *ru = rudpMustOpen();
 struct paraMessage pm;
 struct paraMultiMessage pmm;
 char *row[256];
 int count = 0;
 pmInitFromName(&pm, "localhost", paraHubPort);
 /* ensure the multi-message response comes from the correct ip and has no duplicate msgs*/
 pmmInit(&pmm, &pm, pm.ipAddress.sin_addr);
 if (!pmSendStringWithRetries(&pm, ru, query))
     noWarnAbort();
@@ -818,30 +776,37 @@
 AllocVar(db);
 while (lineFileNext(lf, &line, NULL))
     {
     line = trimSpaces(line);
     if (line == NULL || line[0] == '#' || line[0] == 0)
         continue;
     ++db->jobCount;
     job = jobFromLine(lf, line);
     slAddHead(&db->jobList, job);
     }
 lineFileClose(&lf);
 slReverse(&db->jobList);
 return db;
 }
 
+char *hubSingleLineQuery(char *query)
+/* Send message to hub and get single line response.
+ * This should be freeMem'd when done. */
+{
+return pmHubSingleLineQuery(query, "localhost");
+}
+
 void sendSetPriorityMessage(int priority)
 /* Tell hub to change priority on batch */
 {
 struct dyString *dy = newDyString(1024);
 char *result;
 if ((priority < 1) || (priority > MAX_PRIORITY))
     errAbort("Priority %d out of range, should be 1 to %d",priority,MAX_PRIORITY);
 dyStringPrintf(dy, "setPriority %s %s %d", getUser(), resultsName, priority);
 result = hubSingleLineQuery(dy->string);
 dyStringFree(&dy);
 if (result == NULL || sameString(result, "0"))
     errAbort("Couldn't set priority for %s\n", batchDir);
 freez(&result);
 verbose(1, "Told hub to set priority %d\n",priority);
 }