diff --git a/src/server/distrend.c b/src/server/distrend.c --- a/src/server/distrend.c +++ b/src/server/distrend.c @@ -79,6 +79,8 @@ int createQueueFromXML(struct distrenjob int reCreateQueueFromXML(struct distrenjob *head, xmlDocPtr doc, xmlNodePtr current); void updateGeneralInfo(); void importGeneralInfo(); +int updateJobStatsXML(struct distrenjob *job); + /* Global Vars, eliminate these */ jobnum_t jobnum = 0; // The next job number to create in the queue @@ -175,6 +177,7 @@ void finish_frame(struct distrenjob *hea } updateGeneralInfo(); + updateJobStatsXML(distrenjob); } /** "mortition" check to see if a job is actually done by scanning the folder of the job to make sure all frames are present*/ @@ -281,6 +284,7 @@ int prepare_distrenjob(struct distrenjob general_info.jobs_in_queue++; updateJobListXML(head); updateGeneralInfo(); + updateJobStatsXML(distrenjob); return 0; } @@ -334,6 +338,7 @@ void change_job_priority(struct distrenj } } updateJobListXML(head); + makeJobDataXML(distrenjob); // because priority is changed } /** @@ -366,6 +371,7 @@ int find_jobframe(struct distrenjob *hea distrenjob_ptr->frameset[frame_counter].start_time = clock(); distrenjob_ptr->assigned_frames++; distrenjob_ptr->prev_frame_index = frame_counter; + updateJobStatsXML(distrenjob_ptr); } if(!found) @@ -389,18 +395,24 @@ void frame_watchdog(struct distrenjob *d for(distrenjob_ptr = distrenjob_head->next; distrenjob_ptr; distrenjob_ptr = distrenjob_ptr->next) /* iterate through jobs */ - + { /* if the job has been started, checks by seeing if either to first or second frame has been started */ if(distrenjob_ptr->frameset[0].status != FRAMESETSTATUS_UNASSIGNED || distrenjob_ptr->frameset[1].status != FRAMESETSTATUS_UNASSIGNED) /* iterate through all frames for this job: */ for(counter = 0; counter < distrenjob_ptr->total_frames; counter ++) - /*watchdog_forgiveness = seconds of forgiveness before frame is re-assigned: */ + /*watchdog_forgiveness = seconds of forgiveness before frame is re-assigned: */ if((distrenjob_ptr->frameset[counter].start_time + distrenjob_ptr->watchdog_forgiveness) < clock()) - /* - If frame is not completed within the number of seconds specified by watchdog_forgiveness - Then change the frame status to unassigned - */ - distrenjob_ptr->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED; + { + /* + If frame is not completed within the number of seconds specified by watchdog_forgiveness + Then change the frame status to unassigned + */ + distrenjob_ptr->frameset[counter].status = FRAMESETSTATUS_UNASSIGNED; + distrenjob_ptr->assigned_frames--; + } + + updateJobStatsXML(distrenjob_ptr); + } } /** @@ -599,10 +611,6 @@ int makeJobDataXML(struct distrenjob *jo _distren_asprintf(&tmp, "%d", job->watchdog_forgiveness); xmlTextWriterWriteElement(writer, (xmlChar*)"wd_forgiveness", (xmlChar*)tmp); - // write total_render_time element - _distren_asprintf(&tmp, "%d", job->total_render_time); - xmlTextWriterWriteElement(writer, (xmlChar*)"total_render_time", (xmlChar*)tmp); - // end document xmlTextWriterEndDocument(writer); @@ -656,8 +664,15 @@ struct distrenjob *createJobFromXML(int cur = cur->next; distrenjob->watchdog_forgiveness = atoi((char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); - cur = cur->next; - distrenjob->total_render_time = (time_t)atol((char*)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1)); + xmlFreeDoc(doc); + + // load up stats.xml file to retrieve data + _distren_asprintf(&file_name, "stor/job%d/stats.xml", job_number); + + doc = xmlParseFile(file_name); + cur = xmlDocGetRootElement(doc); + + distrenjob->total_render_time = (time_t)atol((char*)xmlGetProp(cur, (xmlChar*)"total_render_time")); xmlFreeDoc(doc); @@ -665,6 +680,33 @@ struct distrenjob *createJobFromXML(int return distrenjob; } +int updateJobStatsXML(struct distrenjob *job) +{ + xmlTextWriterPtr writer; + char *tmp; // temporarily holds strings to be given to the xml writer + + _distren_asprintf(&tmp, "stor/job%d/stats.xml", job->jobnum); + + // create xml document at the location tmp with no compression + writer = xmlNewTextWriterFilename(tmp, 0); + xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL); + + xmlTextWriterStartElement(writer, (xmlChar*)"stats"); + _distren_asprintf(&tmp, "%d", job->assigned_frames); + xmlTextWriterWriteAttribute(writer, (xmlChar*)"assigned_frames", (xmlChar*)tmp); + _distren_asprintf(&tmp, "%d", job->completed_frames); + xmlTextWriterWriteAttribute(writer, (xmlChar*)"completed_frames", (xmlChar*)tmp); + _distren_asprintf(&tmp, "%d", job->total_render_time); + xmlTextWriterWriteAttribute(writer, (xmlChar*)"total_render_time", (xmlChar*)tmp); + + // end document + xmlTextWriterEndDocument(writer); + // free writer and save xml file to disk + xmlFreeTextWriter(writer); + + return 1; +} + // returns 1 if successful // updates job_list.xml which lists all the jobs in the queue int updateJobListXML(struct distrenjob *head)