Skip to content

Commit

Permalink
added get last queued job id
Browse files Browse the repository at this point in the history
  • Loading branch information
justanhduc committed Nov 10, 2020
1 parent 87dc535 commit 65581c7
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
20 changes: 20 additions & 0 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,26 @@ void c_show_info()
}
}

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

m.type = LAST_ID;
send_msg(server_socket, &m);

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

switch(m.type) {
case LAST_ID:
printf("%d\n", m.u.jobid);
default:
warning("Wrong internal message in get_output_file line size");
}
}

void c_send_runjob_ok(const char *ofname, int pid)
{
struct msg m;
Expand Down
8 changes: 8 additions & 0 deletions jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,14 @@ void s_job_info(int s, int jobid)
}
}

void s_send_last_id(int s) {
struct msg m;

m.type = LAST_ID;
m.u.jobid = jobids - 1;
send_msg(s, &m);
}

void s_send_output(int s, int jobid)
{
struct Job *p = 0;
Expand Down
11 changes: 10 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void parse_opts(int argc, char **argv)

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

if (c == -1)
break;
Expand Down Expand Up @@ -150,6 +150,9 @@ void parse_opts(int argc, char **argv)
command_line.request = c_INFO;
command_line.jobid = atoi(optarg);
break;
case 'q':
command_line.request = c_LAST_ID;
break;
case 'a':
command_line.request = c_GET_LABEL;
command_line.jobid = atoi(optarg);
Expand Down Expand Up @@ -370,6 +373,7 @@ static void print_help(const char *cmd)
printf(" -i [id] show job information. Of last job run, if not specified.\n");
printf(" -s [id] show the job state. Of the last added, if not specified.\n");
printf(" -a [id] show the job label. Of the last added, if not specified.\n");
printf(" -q show the job ID of the last added.\n");
printf(" -r [id] remove a job. The last added, if not specified.\n");
printf(" -w [id] wait for a job. The last added, if not specified.\n");
printf(" -k [id] send SIGTERM to the job process group. The last run, if not specified.\n");
Expand Down Expand Up @@ -511,6 +515,11 @@ int main(int argc, char **argv)
error("The command %i needs the server", command_line.request);
c_show_info();
break;
case c_LAST_ID:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
c_show_last_id();
break;
case c_GET_LABEL:
if (!command_line.need_server)
error("The command %i needs the server", command_line.request);
Expand Down
8 changes: 6 additions & 2 deletions main.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ enum msg_types
VERSION,
NEWJOB_NOK,
COUNT_RUNNING,
GET_LABEL
GET_LABEL,
LAST_ID
};

enum Request
Expand All @@ -68,7 +69,8 @@ enum Request
c_GET_MAX_SLOTS,
c_KILL_JOB,
c_COUNT_RUNNING,
c_GET_LABEL
c_GET_LABEL,
c_LAST_ID
};

struct Command_line {
Expand Down Expand Up @@ -223,6 +225,7 @@ int c_wait_newjob_ok();
void c_get_state();
void c_swap_jobs();
void c_show_info();
void c_show_last_id();
char *build_command_string();
void c_send_max_slots(int max_slots);
void c_get_max_slots();
Expand Down Expand Up @@ -254,6 +257,7 @@ void dump_notifies_struct(FILE *out);
void joblist_dump(int fd);
const char * jstate2string(enum Jobstate s);
void s_job_info(int s, int jobid);
void s_send_last_id(int s);
void s_send_runjob(int s, int jobid);
void s_set_max_slots(int new_max_slots);
void s_get_max_slots(int s);
Expand Down
3 changes: 3 additions & 0 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ static enum Break
close(s);
remove_connection(index);
break;
case LAST_ID:
s_send_last_id(s);
break;
case GET_LABEL:
s_get_label(s, m.u.jobid);
break;
Expand Down

0 comments on commit 65581c7

Please sign in to comment.