diff --git a/PROTOCOL b/PROTOCOL index 2ad08f7df..4f34f531d 100644 --- a/PROTOCOL +++ b/PROTOCOL @@ -557,6 +557,26 @@ status Arguments: - None. +prioritystatus + + This sends back a list of all registered functions. Next to each + function is the number of queued jobs that are not running, broken down + by priority, and the number of capable workers. The columns are tab + separated, and the list is terminated with a line containing + a single '.' (period). The format is: + + FUNCTION\tHIGH-QUEUED\tNORMAL-QUEUED\tLOW-QUEUED\tAVAILABLE_WORKERS + + Columns: + - Function name. + - Number of queued high priority jobs. + - Number of queued normal priority jobs. + - Number of queued low priority jobs. + - Available workers registered for this function. + + Arguments: + - None. + maxqueue This sets the maximum queue size for a function. If no size is diff --git a/bin/gearadmin.cc b/bin/gearadmin.cc index db4661f9f..983cefaba 100644 --- a/bin/gearadmin.cc +++ b/bin/gearadmin.cc @@ -143,6 +143,7 @@ int main(int args, char *argv[]) ("show-jobs", "Show all jobs on the server.") ("getpid", "Get Process ID for the server.") ("status", "Status for the server.") + ("priority-status", "Queued jobs status by priority.") ("workers", "Workers for the server.") ("ssl,S", "Enable SSL connections.") ; @@ -183,6 +184,7 @@ int main(int args, char *argv[]) vm.count("show-jobs") == 0 and vm.count("getpid") == 0 and vm.count("status") == 0 and + vm.count("priority-status") == 0 and vm.count("workers") == 0) { std::cout << "No option execution operation given." << std::endl << std::endl; @@ -196,6 +198,11 @@ int main(int args, char *argv[]) instance.push(new util::Operation(util_literal_param("status\r\n"))); } + if (vm.count("priority-status")) + { + instance.push(new util::Operation(util_literal_param("prioritystatus\r\n"))); + } + if (vm.count("workers")) { instance.push(new util::Operation(util_literal_param("workers\r\n"))); diff --git a/libgearman-server/text.cc b/libgearman-server/text.cc index 1273fa047..dd479bbbc 100644 --- a/libgearman-server/text.cc +++ b/libgearman-server/text.cc @@ -119,6 +119,39 @@ gearmand_error_t server_run_text(gearman_server_con_st *server_con, data.vec_append_printf(".\n"); } + else if (strcasecmp("prioritystatus", (char *)(packet->arg[0])) == 0) + { + uint32_t job_queued[GEARMAN_JOB_PRIORITY_MAX]; + + for (uint32_t function_key= 0; + function_key < GEARMAND_DEFAULT_HASH_SIZE; + function_key++) + { + for (gearman_server_function_st *function= Server->function_hash[function_key]; + function != NULL; + function= function->next) + { + for (size_t priority = 0; priority < GEARMAN_JOB_PRIORITY_MAX; priority++) + { + job_queued[priority] = 0; + for (gearman_server_job_st *server_job= function->job_list[priority]; + server_job != NULL; + server_job= server_job->next) + { + job_queued[priority]++; + } + } + + data.vec_append_printf("%.*s\t%u\t%u\t%u\t%u\n", + int(function->function_name_size), function->function_name, + job_queued[GEARMAN_JOB_PRIORITY_HIGH], + job_queued[GEARMAN_JOB_PRIORITY_NORMAL], + job_queued[GEARMAN_JOB_PRIORITY_LOW], + function->worker_count); + } + } + data.vec_append_printf(".\n"); + } else if (strcasecmp("status", (char *)(packet->arg[0])) == 0) { for (uint32_t function_key= 0; @@ -135,7 +168,6 @@ gearmand_error_t server_run_text(gearman_server_con_st *server_con, function->job_running, function->worker_count); } } - data.vec_append_printf(".\n"); } else if (packet->argc >= 3 diff --git a/tests/cli.cc b/tests/cli.cc index 82c1d70d1..782e3900a 100644 --- a/tests/cli.cc +++ b/tests/cli.cc @@ -261,6 +261,18 @@ static test_return_t gearadmin_status_with_jobs_TEST(void* object) return TEST_SUCCESS; } +static test_return_t gearadmin_priority_status_TEST(void* object) +{ + cli::Context *context= (cli::Context*)object; + + char buffer[1024]; + snprintf(buffer, sizeof(buffer), "--port=%d", int(context->port())); + const char *args[]= { buffer, "--priority-status", 0 }; + + ASSERT_EQ(EXIT_SUCCESS, exec_cmdline("bin/gearadmin", args, true)); + return TEST_SUCCESS; +} + static test_return_t gearadmin_show_unique_jobs_TEST(void* object) { cli::Context *context= (cli::Context*)object; @@ -430,6 +442,7 @@ test_st gearadmin_tests[] ={ {"--show-jobs", 0, gearadmin_show_jobs_TEST}, {"--show-unique-jobs", 0, gearadmin_show_unique_jobs_TEST}, {"--status", 0, gearadmin_status_TEST}, + {"--priority-status", 0, gearadmin_priority_status_TEST}, {"gearman_client_do_background(100) --status", 0, gearadmin_status_with_jobs_TEST}, {"--getpid", 0, gearadmin_getpid_test}, {"--workers", 0, gearadmin_workers_test},