IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2008, 11:35:39 AM (18 years ago)
Author:
eugene
Message:

split out client command from client response; allow response to return slowly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/StartJob.c

    r11388 r17475  
    11# include "pcontrol.h"
    22
     3// job and host are bound together (why pass in both?)
    34int StartJob (Job *job, Host *host) {
    45
    56  int  i, Nline, status;
    6   char *line, *p;
    7   IOBuffer buffer;
    8 
    9   InitIOBuffer (&buffer, 0x100);
     7  char *line;
    108
    119  /* job must have assigned host */
     
    2826  }
    2927
    30   status = PclientCommand (host, line, PCLIENT_PROMPT, &buffer);
     28  status = PclientCommand (host, line, PCLIENT_PROMPT, PCONTROL_RESP_START_JOB);
    3129  free (line);
    3230
     
    3432  switch (status) {
    3533    case PCLIENT_DOWN:
     34      // unlink host & job
    3635      if (VerboseMode()) gprint (GP_ERR, "host %s is down\n", host[0].hostname);
    37       goto failure;
    38 
    39     case PCLIENT_HUNG:
    40       // we need the job start to return a valid Job ID,
    41       // give up on jobs which don't get started.
    42       // XXX we are sensitive here to the time it takes pclient
    43       // to fork the job.  if this is slow, the client may appear to hang.
    44       gprint (GP_ERR, "host %s is not responding (StartJob)\n", host[0].hostname);
    45       if (VerboseMode()) gprint (GP_ERR, "host %s is not responding\n", host[0].hostname);
    46 
    47       // unlink host & job
    4836      job[0].host = NULL;
    4937      host[0].job = NULL;
    50       if (job[0].realhost) free (job[0].realhost);
    51       job[0].realhost = NULL;
    52       PutHost (host, PCONTROL_HOST_DONE, STACK_BOTTOM);
     38      HarvestHost (host[0].pid);
     39      PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
    5340      PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
    54       FreeIOBuffer (&buffer);
    5541      return (FALSE);
    5642
    5743    case PCLIENT_GOOD:
    58       if (VerboseMode()) gprint (GP_ERR, "message received (StartJob)\n"); 
    59       break;
     44      job[0].realhost = strcreate (host[0].hostname);
     45      job[0].pid = -1;
     46      gettimeofday (&job[0].start, (void *) NULL);
     47
     48      if (VerboseMode()) gprint (GP_ERR, "started job on host %s\n", host[0].hostname); 
     49      PutHost (host, PCONTROL_HOST_RESP, STACK_BOTTOM);
     50      PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
     51      return (TRUE);
    6052
    6153    default:
    6254      ABORT ("unknown status for pclient command"); 
    6355  }
     56}
     57
     58// message has been received from the host, interpret results
     59int StartJobResponse (Host *host) {
     60 
     61  int status;
     62  char *p;
     63  IOBuffer *buffer;
     64  Job *job;
     65
     66  /* job must have assigned host */
     67  ASSERT (host, "missing host");
     68  ASSERT (host[0].job, "missing job");
     69  buffer = &host[0].comms_buffer;
     70  job = (Job *) host[0].job;
    6471
    6572  /* check on result of pclient command */
    66   p = memstr (buffer.buffer, "STATUS", buffer.Nbuffer);
     73  p = memstr (buffer[0].buffer, "STATUS", buffer[0].Nbuffer);
    6774  ASSERT (p != NULL, "missing STATUS in pclient message");
    6875
     
    7178    case -1:
    7279      if (VerboseMode()) gprint (GP_ERR, "error in pclient child\n");
    73       goto failure;
     80      // unlink host & job
     81      job[0].host = NULL;
     82      host[0].job = NULL;
     83      HarvestHost (host[0].pid);
     84      PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
     85      PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
     86      return (FALSE);
    7487
    7588    case -2:
     
    8093
    8194    default:
    82       job[0].realhost = strcreate (host[0].hostname);
     95      if (VerboseMode()) gprint (GP_ERR, "message received (StartJobResponse)\n"); 
    8396      job[0].pid = status;
    8497      PutHost (host, PCONTROL_HOST_BUSY, STACK_BOTTOM);
    8598      PutJob (job, PCONTROL_JOB_BUSY, STACK_BOTTOM);
    86       FreeIOBuffer (&buffer);
    87       gettimeofday (&job[0].start, (void *) NULL);
     99      gettimeofday (&job[0].start, NULL);
    88100      return (TRUE);
    89101  }
     102
    90103  /* we should never reach here */
    91104  ABORT ("should not reach here (StartJob)");
    92 
    93 failure:
    94   // unlink host & job
    95   job[0].host = NULL;
    96   host[0].job = NULL;
    97   HarvestHost (host[0].pid);
    98   PutHost (host, PCONTROL_HOST_DOWN, STACK_BOTTOM);
    99   PutJob (job, PCONTROL_JOB_PENDING, STACK_BOTTOM);
    100   FreeIOBuffer (&buffer);
    101   return (FALSE);
    102105}
Note: See TracChangeset for help on using the changeset viewer.