Esempio n. 1
0
void update_jobs_status()
{
	int status, pid;
	list_node_t *n, *p;
	for(;;)
	{
		/* check all background jobs status to delete from list */
		pid = waitpid(-1, &status, WUNTRACED|WNOHANG);
		/* update job status here */
		if( set_job_status(pid, status) < 0) {
			break; /* no background jobs */
		}
	}
	/* delete all jobs terminated */
	for (n = jobs->first; n; n = n->next)
	{
		if (n && n->value) {
			if(n->value->status == 1) {
				printf("Process %d terminated\n", n->value->pid);
				p = n->previous;
				del_node(jobs, n);
				n = p;
				if(!n) {
					break;
				}
			}
		}
	}
}
Esempio n. 2
0
void update_job_status(job *jobs) {
	int status;
	pid_t pid;
	do {
		pid = waitpid(-1, &status, WUNTRACED|WNOHANG);
		if(pid>0) {
			int jid = pid_to_jid(jobs, pid);
			if(jid != -1) set_job_status(&jobs[jid], status);
		}
	} while(pid > 0);
}
                    /**
                     * Allows to compile the end job result, e.g. based on the task results,
                     * come up with the job's result code and the translated text.
                     * @param resp_data [out] the object to store the translation job response data to be sent
                     */
                    inline void collect_job_results(trans_job_resp_out & resp_data) {
                        LOG_DEBUG1 << "Combining the job " << this << " result!" << END_LOG;

                        //Set the translation job id
                        resp_data.set_job_id(m_job_id);

                        //Begin the sentence data section
                        resp_data.begin_sent_data_arr();

                        //Get the sentence data object through which we can build the JSON
                        trans_sent_data_out & sent_data = resp_data.get_sent_data_writer();

                        //Iterate through the translation tasks and combine the results
                        for (tasks_iter_type it = m_tasks.begin(); it != m_tasks.end(); ++it) {
                            //Get the task pointer for future use
                            trans_task_ptr task = *it;

                            LOG_DEBUG1 << "Adding a new sentence result data" << END_LOG;

                            //Begin the sentence data
                            sent_data.begin_sent_data_ent();

                            //Set the target sentence
                            sent_data.set_trans_text(task->get_target_text());

                            //Set the sentence status
                            sent_data.set_status(task->get_status_code(), task->get_status_msg());

                            //Append the task translation info if needed and the translation was finished
                            if (m_is_trans_info && (task->get_status_code() == status_code::RESULT_OK)) {
                                LOG_DEBUG1 << "Getting the translation info data" << END_LOG;
                                //Get the translation task info
                                task->get_trans_info(sent_data);
                            }

                            //End the sentence data section
                            sent_data.end_sent_data_ent();

                            LOG_DEBUG1 << "The target text of task: " << *task << " has been retrieved!" << END_LOG;
                        }

                        //End the sentence data section
                        resp_data.end_sent_data_arr();

                        //Decide on the status code and message
                        set_job_status(resp_data);

                        LOG_DEBUG1 << "The translation job " << this << " result is ready!" << END_LOG;
                    }