zabbix-agent2/src/zabbix_proxy/taskmanager/taskmanager.c
/******************************************************************************
 *                                                                            *
 * Function: tm_process_tasks                                                 *
 *                                                                            *
 * Purpose: process task manager tasks depending on task type                 *
 *                                                                            *
 * Return value: The number of successfully processed tasks                   *
 *                                                                            *
 ******************************************************************************/
tm_process_tasks

Purpose: process task manager tasks depending on task type

Return value: The number of successfully processed tasks
tm_process_tasks Purpose : process task manager tasks depending on task type Return value : The number of successfully processed tasks
static int	tm_process_tasks(int now)
{
	DB_ROW			row;
	DB_RESULT		result;
	int			processed_num = 0, clock, ttl;
	zbx_uint64_t		taskid;
	unsigned char		type;
	zbx_vector_uint64_t	check_now_taskids;
	zbx_vector_uint64_create(&check_now_taskids);
	result = DBselect("select taskid,type,clock,ttl"
				" from task"
				" where status=%d"
					" and type in (%d, %d, %d)"
				" order by taskid",
			ZBX_TM_STATUS_NEW, ZBX_TM_TASK_REMOTE_COMMAND, ZBX_TM_TASK_CHECK_NOW, ZBX_TM_TASK_DATA);
	while (NULL != (row = DBfetch(result)))
	{
		ZBX_STR2UINT64(taskid, row[0]);
		ZBX_STR2UCHAR(type, row[1]);
		clock = atoi(row[2]);
		ttl = atoi(row[3]);
		switch (type)
		{
			case ZBX_TM_TASK_REMOTE_COMMAND:
				if (SUCCEED == tm_execute_remote_command(taskid, clock, ttl, now))
					processed_num++;
				break;
			case ZBX_TM_TASK_CHECK_NOW:
				zbx_vector_uint64_append(&check_now_taskids, taskid);
				break;
			case ZBX_TM_TASK_DATA:
				if (SUCCEED == tm_execute_data(taskid, clock, ttl, now))
					processed_num++;
				break;
			default:
				THIS_SHOULD_NEVER_HAPPEN;
				break;
		}
	}
	DBfree_result(result);
	if (0 < check_now_taskids.values_num)
		processed_num += tm_process_check_now(&check_now_taskids);
	zbx_vector_uint64_destroy(&check_now_taskids);
	return processed_num;
}
static int tm_process_tasks ( int now ) { DB_ROW row ; DB_RESULT result ; int processed_num = 0 , clock , ttl ; zbx_uint64_t taskid ; unsigned char type ; zbx_vector_uint64_t check_now_taskids ; zbx_vector_uint64_create ( & check_now_taskids ) ; result = DBselect ( " " " " " " " " " " , ZBX_TM_STATUS_NEW , ZBX_TM_TASK_REMOTE_COMMAND , ZBX_TM_TASK_CHECK_NOW , ZBX_TM_TASK_DATA ) ; while ( NULL != ( row = DBfetch ( result ) ) ) { ZBX_STR2UINT64 ( taskid , row [ 0 ] ) ; ZBX_STR2UCHAR ( type , row [ 1 ] ) ; clock = atoi ( row [ 2 ] ) ; ttl = atoi ( row [ 3 ] ) ; switch ( type ) { case ZBX_TM_TASK_REMOTE_COMMAND : if ( SUCCEED == tm_execute_remote_command ( taskid , clock , ttl , now ) ) processed_num ++ ; break ; case ZBX_TM_TASK_CHECK_NOW : zbx_vector_uint64_append ( & check_now_taskids , taskid ) ; break ; case ZBX_TM_TASK_DATA : if ( SUCCEED == tm_execute_data ( taskid , clock , ttl , now ) ) processed_num ++ ; break ; default : THIS_SHOULD_NEVER_HAPPEN ; break ; } } DBfree_result ( result ) ; if ( 0 < check_now_taskids . values_num ) processed_num += tm_process_check_now ( & check_now_taskids ) ; zbx_vector_uint64_destroy ( & check_now_taskids ) ; return processed_num ; }
Function: tm_process_tasks                                                 
                                                                            
 Purpose: process task manager tasks depending on task type                 
                                                                            
 Return value: The number of successfully processed tasks
Function : tm_process_tasks Purpose : process task manager tasks depending on task type Return value : The number of successfully processed tasks