Changeset - 716f6fbdba6f
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 16 years ago 2009-12-20 16:25:49
ohnobinki@ohnopublishing.net
fix comments and style, fix distrenjob_enqueue()
1 file changed with 51 insertions and 27 deletions:
0 comments (0 inline, 0 general)
src/server/distrend.c
Show inline comments
 
@@ -174,34 +174,38 @@ int mortition(struct general_info *genin
 
{
 
  short int isJobDone;
 
  int counter;
 
  char *path_and_number;
 
  struct stat buffer;
 

	
 
  isJobDone = 1; // set isJobDone to true
 
  isJobDone = 1;
 
  for(counter = 0; counter < job->total_frames; counter++)
 
    {
 
      _distren_asprintf(&path_and_number, "%s/stor/job%d/out/%d.%s",
 
			geninfo->config->datadir,
 
			job->jobnum,
 
			job->frameset[counter].num,
 
			job->output_format);
 
      if(stat(path_and_number, &buffer) == -1)
 
        {
 
	  /**
 
	     missing frame found
 
	   */
 
          job->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED;
 
          job->completed_frames--;
 
          geninfo->total_frames_rendered--;
 
	  /** if a missing frame is found, set isJobDone to false */
 
          isJobDone = 0;
 
        }
 
      free(path_and_number);
 
    }
 

	
 
  /** if all frames were accounted for */
 
  if(isJobDone)
 
    {
 
      /**
 
	 all frames were accounted for
 
      */
 
      distrenjob_remove(geninfo, job);
 
      distrenjob_free(&job);
 
      geninfo->jobs_in_queue --;
 
      update_xml_joblist(geninfo);
 
    }
 
  else
 
@@ -212,15 +216,17 @@ int mortition(struct general_info *genin
 

	
 
  update_general_info(geninfo);
 

	
 
  return 0;
 
}
 

	
 
/** scans the frames of a job to initialize a job after server */
 
/* returns 1 if the job is completely done and there are no missing frames */
 
/* returns 0 if a missing frame is found */
 
/**
 
   scans the frames of a job to initialize a job after server
 
   @return 0 if the job is completely done and there are no missing frames,
 
           1 if missing frames are found.
 
*/
 
int restoreJobState(struct distrenjob *job)
 
{
 
  short int isJobDone;
 
  int counter;
 
  char *path_and_number;
 
  struct stat buffer;
 
@@ -236,16 +242,19 @@ int restoreJobState(struct distrenjob *j
 
        }
 
      else
 
        isJobDone = 0;
 
      free(path_and_number);
 
    }
 

	
 
  return isJobDone;
 
  return !isJobDone;
 
}
 

	
 
/** creates a structure from starting data, then calls another function to actually add that struct to the queue */
 
/**
 
   creates a structure from starting data, then calls another
 
   function to actually add that struct to the queue.
 
*/
 
int prepare_distrenjob(struct general_info *geninfo, int type, char *name, char *submitter, char *email, int priority, int start_frame, int end_frame, int width, int height)
 
{
 
  int counter2;
 
  int counter;
 
  int tmp;
 
  char *path_with_num;
 
@@ -263,21 +272,22 @@ int prepare_distrenjob(struct general_in
 
  distrenjob->name = name;
 
  distrenjob->submitter = submitter;
 
  distrenjob->email = email;
 
  distrenjob->priority = priority;
 
  distrenjob->width = width;
 
  distrenjob->height = height;
 
  distrenjob->total_frames = (end_frame - start_frame + 1); /* sets the total number of frames in animation for status purposes */
 
  /** sets the total number of frames in animation for status purposes */
 
  distrenjob->total_frames = (end_frame - start_frame + 1);
 
  distrenjob->frameset = malloc(sizeof(struct frameset) * distrenjob->total_frames);
 
  if(!distrenjob->frameset)
 
    {
 
      distrenjob_free(&distrenjob);
 
      return 1;
 
    }
 

	
 
  /* prepares all the frames by setting that status to "unassigned" */
 
  /** prepares all the frames by setting that status to "unassigned" */
 
  counter2 = start_frame;
 
  for(counter = 0; counter < distrenjob->total_frames; counter++){
 
    distrenjob->frameset[counter].num = counter2;
 
    distrenjob->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED;
 

	
 
    counter2++;
 
@@ -286,13 +296,15 @@ int prepare_distrenjob(struct general_in
 
  _distren_asprintf(&path_with_num, "stor/job%d/out/", distrenjob->jobnum);
 
  fprintf(stderr, ">>NOT<< creating dir ``%s''\n", path_with_num); /*< @TODO recursively create job directory */
 
  serialfile = job_getserialfilename(geninfo, distrenjob->jobnum);
 

	
 
  free(path_with_num);
 

	
 
  /* add job to queue */
 
  /**
 
     add job to queue
 
  */
 
  fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_serialize()\n");
 
  distrenjob_serialize(distrenjob, serialfile);
 
  free(serialfile);
 

	
 
  fprintf(stderr, "\nprepare_distrenjob: attempting distrenjob_enqueue()\n");
 
  distrenjob_enqueue(geninfo, distrenjob);
 
@@ -306,40 +318,52 @@ int prepare_distrenjob(struct general_in
 
  updateJobStatsXML(distrenjob);
 

	
 
  return 0;
 
}
 

	
 

	
 
/** distrenjob_enqueue: This function adds the job to the queue based on its priority */
 
/**
 
   distrenjob_enqueue: This function adds the job to the queue based on its priority
 
*/
 
int distrenjob_enqueue(struct general_info *geninfo, struct distrenjob *job)
 
{
 
  struct distrenjob *prev_job;
 
  struct distrenjob *current_job;
 
  struct distrenjob *head;
 

	
 
  head = &geninfo->head;
 
  prev_job = head;
 

	
 
  // iterate through linked list of jobs
 
  for(current_job = head->next; 1; current_job = current_job->next)
 
  /**
 
     iterate through linked jobs
 
  */
 
  for(current_job = head->next; current_job; current_job = current_job->next)
 
  {
 
	fprintf(stderr, "enqueue loop iteration\n");
 
    if(current_job == NULL){ // if it has reached the end of the list, add job there
 
      prev_job->next = job;
 
      fprintf(stderr, "adding job at end of queue\n");
 
      break;
 
    }
 
    else if(job->priority < current_job->priority){ // if job's priority is less than current_job's priority, insert job
 
      prev_job->next = job;                        // keep in mind 1 is the highest priority given to jobs, head has a
 
      job->next = current_job;                     // priority of zero so it will always be before other jobs
 
      fprintf(stderr, "adding job before jobname: %s\n", current_job->name);
 
      break;
 
    }
 
    fprintf(stderr, "enqueue loop iteration\n");
 
    if(job->priority < current_job->priority)
 
      {
 
	/**
 
	   if job's priority is less than current_job's priority, insert job
 
	   keep in mind 1 is the highest priority given to jobs, head has a
 
	   priority of zero so it will always be before other jobs
 
	*/
 
	prev_job->next = job;
 
	job->next = current_job;
 
	fprintf(stderr, "adding job before jobname: %s\n", current_job->name);
 

	
 
	return 0;
 
      }
 

	
 
    prev_job = current_job;
 
  } /* for(current_job) */
 
  }
 

	
 
  /**
 
     if it has reached the end of the list, add job there
 
  */
 
  prev_job->next = job;
 
  fprintf(stderr, "adding job at end of queue\n");
 

	
 
  return 0;
 
}
 

	
 
/** Changes the priority of an existing (and maybe running) job. @arg head I may end up changing the head if job == head */
 
int change_job_priority(struct general_info *geninfo, struct distrenjob *job, int new_priority){
0 comments (0 inline, 0 general)