Data Structures | |
| struct | switch_scheduler_task |
Functions | |
| uint32_t | switch_scheduler_add_task (time_t task_runtime, switch_scheduler_func_t func, const char *desc, const char *group, uint32_t cmd_id, void *cmd_arg, switch_scheduler_flag_t flags) |
| Schedule a task in the future. | |
| uint32_t | switch_scheduler_del_task_id (uint32_t task_id) |
| Delete a scheduled task. | |
| uint32_t | switch_scheduler_del_task_group (const char *group) |
| Delete a scheduled task based on the group name. | |
| void | switch_scheduler_task_thread_start (void) |
| Start the scheduler system. | |
| void | switch_scheduler_task_thread_stop (void) |
| Stop the scheduler system. | |
|
||||||||||||||||||||||||||||||||
|
Schedule a task in the future.
00185 {
00186 switch_scheduler_task_container_t *container, *tp;
00187 switch_event_t *event;
00188
00189 switch_mutex_lock(globals.task_mutex);
00190 switch_zmalloc(container, sizeof(*container));
00191 switch_assert(func);
00192 container->func = func;
00193 container->task.created = switch_timestamp(NULL);
00194 container->task.runtime = task_runtime;
00195 container->task.group = strdup(group ? group : "none");
00196 container->task.cmd_id = cmd_id;
00197 container->task.cmd_arg = cmd_arg;
00198 container->flags = flags;
00199 container->desc = strdup(desc ? desc : "none");
00200
00201 for (tp = globals.task_list; tp && tp->next; tp = tp->next);
00202
00203 if (tp) {
00204 tp->next = container;
00205 } else {
00206 globals.task_list = container;
00207 }
00208
00209 for (container->task.task_id = 0; !container->task.task_id; container->task.task_id = ++globals.task_id);
00210
00211 switch_mutex_unlock(globals.task_mutex);
00212
00213 tp = container;
00214 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Added task %u %s (%s) to run at %" SWITCH_INT64_T_FMT "\n",
00215 tp->task.task_id, tp->desc, switch_str_nil(tp->task.group), tp->task.runtime);
00216
00217 if (switch_event_create(&event, SWITCH_EVENT_ADD_SCHEDULE) == SWITCH_STATUS_SUCCESS) {
00218 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id);
00219 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Desc", tp->desc);
00220 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Group", switch_str_nil(tp->task.group));
00221 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime);
00222 switch_event_fire(&event);
00223 }
00224 return container->task.task_id;
00225 }
|
Here is the call graph for this function:

|
|
Delete a scheduled task based on the group name.
00259 {
00260 switch_scheduler_task_container_t *tp;
00261 switch_event_t *event;
00262 uint32_t delcnt = 0;
00263
00264 switch_mutex_lock(globals.task_mutex);
00265 for (tp = globals.task_list; tp; tp = tp->next) {
00266 if (!switch_strlen_zero(group) && !strcmp(tp->task.group, group)) {
00267 if (switch_test_flag(tp, SSHF_NO_DEL)) {
00268 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeletable task #%u (group %s)\n",
00269 tp->task.task_id, group);
00270 continue;
00271 }
00272 if (switch_event_create(&event, SWITCH_EVENT_DEL_SCHEDULE) == SWITCH_STATUS_SUCCESS) {
00273 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id);
00274 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Desc", tp->desc);
00275 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Group", switch_str_nil(tp->task.group));
00276 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime);
00277 switch_event_fire(&event);
00278 }
00279 tp->destroyed++;
00280 delcnt++;
00281 }
00282 }
00283 switch_mutex_unlock(globals.task_mutex);
00284
00285 return delcnt;
00286 }
|
Here is the call graph for this function:

|
|
Delete a scheduled task.
00228 {
00229 switch_scheduler_task_container_t *tp;
00230 switch_event_t *event;
00231 uint32_t delcnt = 0;
00232
00233 switch_mutex_lock(globals.task_mutex);
00234 for (tp = globals.task_list; tp; tp = tp->next) {
00235 if (tp->task.task_id == task_id) {
00236 if (switch_test_flag(tp, SSHF_NO_DEL)) {
00237 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Attempt made to delete undeletable task #%u (group %s)\n",
00238 tp->task.task_id, tp->task.group);
00239 break;
00240 }
00241 tp->destroyed++;
00242 if (switch_event_create(&event, SWITCH_EVENT_DEL_SCHEDULE) == SWITCH_STATUS_SUCCESS) {
00243 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-ID", "%u", tp->task.task_id);
00244 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Desc", tp->desc);
00245 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Task-Group", switch_str_nil(tp->task.group));
00246 switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Task-Runtime", "%" SWITCH_INT64_T_FMT, tp->task.runtime);
00247 switch_event_fire(&event);
00248 }
00249 delcnt++;
00250 break;
00251 }
00252 }
00253 switch_mutex_unlock(globals.task_mutex);
00254
00255 return delcnt;
00256 }
|
Here is the call graph for this function:

|
|
Start the scheduler system.
00289 {
00290 switch_thread_t *thread;
00291 switch_threadattr_t *thd_attr;
00292
00293 switch_core_new_memory_pool(&globals.memory_pool);
00294 switch_threadattr_create(&thd_attr, globals.memory_pool);
00295 switch_mutex_init(&globals.task_mutex, SWITCH_MUTEX_NESTED, globals.memory_pool);
00296
00297 switch_threadattr_detach_set(thd_attr, 1);
00298 switch_thread_create(&thread, thd_attr, switch_scheduler_task_thread, NULL, globals.memory_pool);
00299 }
|
Here is the call graph for this function:

|
|
Stop the scheduler system.
00302 {
00303 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Stopping Task Thread\n");
00304 if (globals.task_thread_running == 1) {
00305 int sanity = 0;
00306
00307 globals.task_thread_running = -1;
00308
00309 while (globals.task_thread_running) {
00310 switch_yield(100000);
00311 if (++sanity > 10) {
00312 break;
00313 }
00314 }
00315 }
00316 }
|
Here is the call graph for this function:

1.3.9.1