From 0d8a22e75c54ff28ffdc82a00852a2697d023a9b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 20 Feb 2014 13:44:56 -0800 Subject: [PATCH] Server: add optional size_class parameter to count_unsent_results(). This lets you write work generators that maintain min levels of unsent jobs for each size class. --- sched/sched_util.cpp | 19 ++++++++++--------- sched/sched_util.h | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/sched/sched_util.cpp b/sched/sched_util.cpp index fe403f81cb..502e88ad87 100644 --- a/sched/sched_util.cpp +++ b/sched/sched_util.cpp @@ -273,17 +273,18 @@ int count_workunits(int& n, const char* query) { return workunit.count(n, query); } -int count_unsent_results(int& n, int appid) { - char buf[256]; +int count_unsent_results(int& n, int appid, int size_class) { + char query[1024], buf[256]; + sprintf(query, "where server_state<=%d", RESULT_SERVER_STATE_UNSENT); if (appid) { - sprintf(buf, "where server_state<=%d and appid=%d ", - RESULT_SERVER_STATE_UNSENT, appid - ); - } else { - sprintf(buf, "where server_state<=%d", RESULT_SERVER_STATE_UNSENT); + sprintf(buf, " and appid=%d", appid); + strcat(query, buf); } - return count_results(buf, n); - + if (size_class >= 0) { + sprintf(buf, " and size_class=%d", size_class); + strcat(query, buf); + } + return count_results(query, n); } bool is_arg(const char* x, const char* y) { diff --git a/sched/sched_util.h b/sched/sched_util.h index 2fc3fdd714..49e25ff0f6 100644 --- a/sched/sched_util.h +++ b/sched/sched_util.h @@ -72,7 +72,7 @@ struct PERF_INFO { extern int mylockf(int fd); extern int count_workunits(int&, const char* query); -extern int count_unsent_results(int&, int appid); +extern int count_unsent_results(int&, int appid, int size_class=-1); // Return a value for host_app_version.app_version_id. // if the app version is anonymous platform,