src/hg/utils/refreshNamedSessionCustomTracks/refreshNamedSessionCustomTracks.c 1.11
1.11 2010/01/13 17:27:35 angie
Added option -atime=N: if a session's lastUsed is older than N days, don't refresh its custom tracks.
Index: src/hg/utils/refreshNamedSessionCustomTracks/refreshNamedSessionCustomTracks.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/utils/refreshNamedSessionCustomTracks/refreshNamedSessionCustomTracks.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -b -B -U 4 -r1.10 -r1.11
--- src/hg/utils/refreshNamedSessionCustomTracks/refreshNamedSessionCustomTracks.c 19 May 2009 23:54:31 -0000 1.10
+++ src/hg/utils/refreshNamedSessionCustomTracks/refreshNamedSessionCustomTracks.c 13 Jan 2010 17:27:35 -0000 1.11
@@ -22,8 +22,11 @@
" contents for custom tracks and touch any that are found, to prevent\n"
" them from being removed by the custom track cleanup process.\n"
"usage:\n"
" refreshNamedSessionCustomTracks hgcentral[test,beta]\n"
+ "options:\n"
+ " -atime=N If the session has not been accessed since N days ago,\n"
+ " don't refresh its custom tracks. Default: no limit.\n"
"This is intended to be run as a nightly cron job for each central db.\n"
"The ~/.hg.conf file (or $HGDB_CONF) must specify the same central db\n"
"as the command line. [The command line arg exists only to suppress this\n"
"message].\n"
@@ -33,8 +36,9 @@
}
/* Options: */
static struct optionSpec options[] = {
+ {"atime", OPTION_INT},
{"hardcore", OPTION_BOOLEAN}, /* Intentionally omitted from usage(). */
{NULL, 0},
};
@@ -157,26 +161,44 @@
actualDbName, centralDbName);
else
verbose(2, "Got connection to %s\n", centralDbName);
+long long threshold = 0;
+int atime = optionInt("atime", 0);
+if (atime > 0)
+ {
+ time_t now = time(NULL);
+ threshold = now - ((long long)atime * 24 * 60 * 60);
+ }
+
if (sqlTableExists(conn, savedSessionTable))
{
struct sessionInfo *sessionList = NULL, *si;
struct sqlResult *sr = NULL;
char **row = NULL;
char query[512];
safef(query, sizeof(query),
- "select userName,sessionName,contents from %s "
+ "select userName,sessionName,UNIX_TIMESTAMP(lastUse),contents from %s "
"order by userName,sessionName", savedSessionTable);
sr = sqlGetResult(conn, query);
// Slurp results into memory instead of processing row by row,
// reducing the chance of lost connection.
while ((row = sqlNextRow(sr)) != NULL)
{
+ if (atime > 0)
+ {
+ long long lastUse = atoll(row[2]);
+ if (lastUse < threshold)
+ {
+ verbose(2, "User %s session %s is older than %d days, skipping.\n",
+ row[0], row[1], atime);
+ continue;
+ }
+ }
AllocVar(si);
safecpy(si->userName, sizeof(si->userName), row[0]);
safecpy(si->sessionName, sizeof(si->sessionName), row[1]);
- si->contents = cloneString(row[2]);
+ si->contents = cloneString(row[3]);
slAddHead(&sessionList, si);
}
sqlFreeResult(&sr);
for (si = sessionList; si != NULL; si = si->next)