Skip to content

Commit

Permalink
added count running jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Oct 30, 2020
1 parent 7b6fbc9 commit c6734bb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 5 deletions.
26 changes: 26 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,29 @@ void c_swap_jobs()
/* This will never be reached */
return;
}

void c_get_count_running() {
struct msg m;
int res;

/* Send the request */
m.type = COUNT_RUNNING;
send_msg(server_socket, &m);

/* Receive the answer */
res = recv_msg(server_socket, &m);
if (res != sizeof(m))
error("Error in get_state - line size");

switch(m.type)
{
case COUNT_RUNNING:
printf("%i\n", m.u.count_running);
return;
default:
warning("Wrong internal message in count_running");
}

/* This will never be reached */
return;
}
22 changes: 22 additions & 0 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ static void add_notify_errorlevel_to(struct Job *job, int jobid)
job->notify_errorlevel_to[job->notify_errorlevel_to_size - 1] = jobid;
}

void s_count_running_jobs(int s)
{
int count = 0;
struct Job *p;
struct msg m;

/* Show Queued or Running jobs */
p = firstjob;
while(p != 0)
{
if (p->state == RUNNING)
++count;

p = p->next;
}

/* Message */
m.type = COUNT_RUNNING;
m.u.count_running = count;
send_msg(s, &m);
}

void s_mark_job_running(int jobid)
{
struct Job *p;
Expand Down
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include <stdio.h>
#include <sys/time.h>

#include "main.h"

Expand Down Expand Up @@ -84,7 +82,7 @@ void parse_opts(int argc, char **argv)

/* Parse options */
while(1) {
c = getopt(argc, argv, ":VhKgClnfmBEr:t:c:o:p:w:k:u:s:U:i:N:L:dS:D:");
c = getopt(argc, argv, ":RVhKgClnfmBEr:t:c:o:p:w:k:u:s:U:i:N:L:dS:D:");

if (c == -1)
break;
Expand Down Expand Up @@ -207,6 +205,9 @@ void parse_opts(int argc, char **argv)
case 'E':
command_line.stderr_apart = 1;
break;
case 'R':
command_line.request = c_COUNT_RUNNING;
break;
case ':':
switch(optopt)
{
Expand Down Expand Up @@ -350,6 +351,7 @@ static void print_help(const char *cmd)
printf(" -K kill the task spooler server\n");
printf(" -C clear the list of finished jobs\n");
printf(" -l show the job list (default action)\n");
printf(" -R number of running jobs\n");
printf(" -S [num] get/set the number of max simultaneous jobs of the server.\n");
printf(" -t [id] \"tail -n 10 -f\" the output of the job. Last run if not specified.\n");
printf(" -c [id] like -t, but shows all the lines. Last run if not specified.\n");
Expand Down Expand Up @@ -524,6 +526,11 @@ int main(int argc, char **argv)
error("The command %i needs the server", command_line.request);
c_swap_jobs();
break;
case c_COUNT_RUNNING:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
c_get_count_running();
break;
case c_GET_STATE:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
Expand Down
9 changes: 7 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ enum msg_types
GET_MAX_SLOTS_OK,
GET_VERSION,
VERSION,
NEWJOB_NOK
NEWJOB_NOK,
COUNT_RUNNING
};

enum Request
Expand All @@ -64,7 +65,8 @@ enum Request
c_INFO,
c_SET_MAX_SLOTS,
c_GET_MAX_SLOTS,
c_KILL_JOB
c_KILL_JOB,
c_COUNT_RUNNING
};

struct Command_line {
Expand Down Expand Up @@ -153,6 +155,7 @@ struct msg
int last_errorlevel;
int max_slots;
int version;
int count_running;
} u;
};

Expand Down Expand Up @@ -221,6 +224,7 @@ char *build_command_string();
void c_send_max_slots(int max_slots);
void c_get_max_slots();
void c_check_version();
void c_get_count_running();

/* jobs.c */
void s_list(int s);
Expand All @@ -240,6 +244,7 @@ void s_wait_running_job(int s, int jobid);
void s_move_urgent(int s, int jobid);
void s_send_state(int s, int jobid);
void s_swap_jobs(int s, int jobid1, int jobid2);
void s_count_running_jobs(int s);
void dump_jobs_struct(FILE *out);
void dump_notifies_struct(FILE *out);
void joblist_dump(int fd);
Expand Down
3 changes: 3 additions & 0 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ static enum Break
case WAIT_RUNNING_JOB:
s_wait_running_job(s, m.u.jobid);
break;
case COUNT_RUNNING:
s_count_running_jobs(s);
break;
case URGENT:
s_move_urgent(s, m.u.jobid);
break;
Expand Down

0 comments on commit c6734bb

Please sign in to comment.