FOSSology
4.4.0
Open Source License Compliance by Open Source Software
|
Job handling operations. More...
#include <libfossrepo.h>
#include <agent.h>
#include <database.h>
#include <job.h>
#include <scheduler.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <glib.h>
#include <gio/gio.h>
Go to the source code of this file.
Macros | |
#define | TEST_NULV(j) if(!j) { errno = EINVAL; ERROR("job passed is NULL, cannot proceed"); return; } |
#define | TEST_NULL(j, ret) if(!j) { errno = EINVAL; ERROR("job passed is NULL, cannot proceed"); return ret; } |
#define | MAX_SQL 512;JOB_STATUS_TYPES |
#define | SELECT_STRING(passed) MK_STRING_LIT(JOB_##passed), |
Functions | |
static int | is_active (int *job_id, job_t *job, int *counter) |
Tests if a job is active. More... | |
static int | job_sstatus (int *job_id, job_t *job, GOutputStream *ostr) |
Prints the jobs status to the output stream. More... | |
static void | job_transition (scheduler_t *scheduler, job_t *job, job_status new_status) |
static gint | job_compare (gconstpointer a, gconstpointer b, gpointer user_data) |
Used to compare two different jobs in the priority queue. More... | |
job_t * | job_init (GTree *job_list, GSequence *job_queue, char *type, char *host, int id, int parent_id, int user_id, int group_id, int priority, char *jq_cmd_args) |
Create a new job. More... | |
void | job_destroy (job_t *job) |
void | job_verbose_event (scheduler_t *scheduler, job_t *job) |
void | job_status_event (scheduler_t *scheduler, arg_int *params) |
Event to get the status of the scheduler or a specific job. More... | |
void | job_pause_event (scheduler_t *scheduler, arg_int *params) |
Event to pause a job. More... | |
void | job_restart_event (scheduler_t *scheduler, arg_int *params) |
void | job_priority_event (scheduler_t *scheduler, arg_int *params) |
void | job_fail_event (scheduler_t *scheduler, job_t *job) |
Events that causes a job to be marked a failed. More... | |
void | job_add_agent (job_t *job, void *agent) |
Adds a new agent to the jobs list of agents. More... | |
void | job_remove_agent (job_t *job, GTree *job_list, void *agent) |
void | job_finish_agent (job_t *job, void *agent) |
void | job_fail_agent (job_t *job, void *agent) |
void | job_set_data (scheduler_t *scheduler, job_t *job, char *data, int sql) |
void | job_update (scheduler_t *scheduler, job_t *job) |
int | job_is_open (scheduler_t *scheduler, job_t *job) |
Tests to see if there is still data available for this job. More... | |
char * | job_next (job_t *job) |
log_t * | job_log (job_t *job) |
job_t * | next_job (GSequence *job_queue) |
Gets the next job from the job queue. More... | |
job_t * | peek_job (GSequence *job_queue) |
Gets the job that is at the top of the queue if there is one. More... | |
uint32_t | active_jobs (GTree *job_list) |
Gets the number of jobs that are not paused. More... | |
Variables | |
const char * | job_status_strings [] = { JOB_STATUS_TYPES(SELECT_STRING) } |
Job handling operations.
Definition in file job.c.
#define SELECT_STRING | ( | passed | ) | MK_STRING_LIT(JOB_##passed), |
uint32_t active_jobs | ( | GTree * | job_list | ) |
|
static |
Tests if a job is active.
If the job is active, the integer pointed to by counter will be incremented by 1. This is used when determining if the scheduler can shutdown and will be called from within a g_tree_foreach().
job_id | The id number used as the key in the Gtree |
job | The job that is being tested for activity |
counter | The count of the number of active jobs |
void job_add_agent | ( | job_t * | job, |
void * | agent | ||
) |
Adds a new agent to the jobs list of agents.
When a job is created it doesn't contain any agents that can process its data. When an agent is ready, it will add itself to the job using this function and begin processing the jobs data.
job | the job that the agent will be added to |
agent | the agent to add to the job |
|
static |
Used to compare two different jobs in the priority queue.
This simply compares their priorities so that jobs with a high priority are scheduler before low priority jobs.
a | The first job |
b | The second job |
user_data | unused |
void job_destroy | ( | job_t * | job | ) |
void job_fail_agent | ( | job_t * | job, |
void * | agent | ||
) |
void job_fail_event | ( | scheduler_t * | scheduler, |
job_t * | job | ||
) |
void job_finish_agent | ( | job_t * | job, |
void * | agent | ||
) |
job_t* job_init | ( | GTree * | job_list, |
GSequence * | job_queue, | ||
char * | type, | ||
char * | host, | ||
int | id, | ||
int | parent_id, | ||
int | user_id, | ||
int | group_id, | ||
int | priority, | ||
char * | jq_cmd_args | ||
) |
Create a new job.
Every different task will create a new job and as a result the job will only deal with one type of agent. This is important because if an agent fails when processing data from a job, that job might need to create a new agent to deal with the data.
job_list | The list of all jobs, the job will be added to this list |
job_queue | The job queue, the job must be added to this for scheduling |
type | The type of agent that will be created for this job |
host | The name of the host that this job will execute on |
id | The id number for the job in the database |
parent_id | The parent id for the job in the database (queue) |
user_id | The id of the user that created the job |
group_id | The id of the group that created the job |
priority | The priority of the job, this is just a Linux process priority |
jq_cmd_args | Command line arguments |
int job_is_open | ( | scheduler_t * | scheduler, |
job_t * | job | ||
) |
char* job_next | ( | job_t * | job | ) |
void job_pause_event | ( | scheduler_t * | scheduler, |
arg_int * | params | ||
) |
void job_priority_event | ( | scheduler_t * | scheduler, |
arg_int * | params | ||
) |
void job_remove_agent | ( | job_t * | job, |
GTree * | job_list, | ||
void * | agent | ||
) |
Removes an agent from a jobs list of agents, if a job no longer has any agents in any of it lists, this will then remove the job from the system.
job | the job to remove the agent from |
job_list | the list of all available jobs |
agent | the agent to remove from the job |
void job_restart_event | ( | scheduler_t * | scheduler, |
arg_int * | params | ||
) |
void job_set_data | ( | scheduler_t * | scheduler, |
job_t * | job, | ||
char * | data, | ||
int | sql | ||
) |
Sets the data that a job should be working on. Currently runonpfile is not implemented, so sql will always be true.
scheduler | Scheduler containing database connection, used for runonpfile |
job | the job to set the data for |
data | the data that the job should be processing |
sql | currently, always false |
|
static |
Prints the jobs status to the output stream.
The output will be in this format: job:<id> status:<status> type:<agent type> priority:<priority> running:<# running> finished:<#finished> failed:<# failed>
job_id | the id number that the job was created with |
job | the job itself |
ostr | the output stream to write everything to |
void job_status_event | ( | scheduler_t * | scheduler, |
arg_int * | params | ||
) |
Event to get the status of the scheduler or a specific job.
This is only generated by the interface receiving a status command. The parameter for this function is a little odd since the function needs 2 parameters, but is an event, so can only be passed 1. Because of this, the parameter is a pair, the first is always the g_output_stream to write the status to. The second is either 0 (scheduler status) or the jq_pk of the job that the status was requested for (job status).
scheduler | the scheduler this event is called on |
params | the g_output_stream and possibly the jq_pk of the job |
|
static |
void job_update | ( | scheduler_t * | scheduler, |
job_t * | job | ||
) |
void job_verbose_event | ( | scheduler_t * | scheduler, |
job_t * | job | ||
) |
job_t* next_job | ( | GSequence * | job_queue | ) |