Lines Matching defs:task
44 static void be_ptask_schedule(struct be_ptask *task,
50 struct be_ptask *task;
52 task = talloc_get_type(pvt, struct be_ptask);
53 if (task == NULL) {
54 DEBUG(SSSDBG_FATAL_FAILURE, "BUG: task is NULL\n");
58 DEBUG(SSSDBG_TRACE_FUNC, "Terminating periodic task [%s]\n", task->name);
65 struct be_ptask *task = NULL;
67 task = talloc_get_type(pvt, struct be_ptask);
68 if (task == NULL) {
69 DEBUG(SSSDBG_FATAL_FAILURE, "BUG: task is NULL\n");
74 be_ptask_enable(task);
79 struct be_ptask *task = NULL;
80 task = talloc_get_type(pvt, struct be_ptask);
83 be_ptask_disable(task);
91 struct be_ptask *task = NULL;
92 task = talloc_get_type(pvt, struct be_ptask);
94 DEBUG(SSSDBG_OP_FAILURE, "Task [%s]: timed out\n", task->name);
96 talloc_zfree(task->req);
97 be_ptask_schedule(task, BE_PTASK_PERIOD, BE_PTASK_SCHEDULE_FROM_NOW);
107 struct be_ptask *task = NULL;
110 task = talloc_get_type(pvt, struct be_ptask);
111 task->timer = NULL; /* timer is freed by tevent */
113 if (be_is_offline(task->be_ctx)) {
115 switch (task->offline) {
117 be_ptask_schedule(task, BE_PTASK_PERIOD,
124 be_ptask_disable(task);
132 DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: executing task, timeout %lu "
133 "seconds\n", task->name, task->timeout);
135 task->last_execution = tv.tv_sec;
137 task->req = task->send_fn(task, task->ev, task->be_ctx, task, task->pvt);
138 if (task->req == NULL) {
140 DEBUG(SSSDBG_OP_FAILURE, "Task [%s]: failed to execute task, "
141 "will try again later\n", task->name);
143 be_ptask_schedule(task, BE_PTASK_PERIOD, BE_PTASK_SCHEDULE_FROM_NOW);
147 tevent_req_set_callback(task->req, be_ptask_done, task);
150 if (task->timeout > 0) {
151 tv = tevent_timeval_current_ofs(task->timeout, 0);
152 timeout = tevent_add_timer(task->ev, task->req, tv,
153 be_ptask_timeout, task);
157 talloc_zfree(task->req);
160 "the task will be rescheduled\n", task->name);
162 be_ptask_schedule(task, BE_PTASK_PERIOD,
172 struct be_ptask *task = NULL;
175 task = tevent_req_callback_data(req, struct be_ptask);
177 ret = task->recv_fn(req);
179 task->req = NULL;
183 task->name);
185 be_ptask_schedule(task, BE_PTASK_PERIOD, BE_PTASK_SCHEDULE_FROM_LAST);
189 task->name, ret, sss_strerror(ret));
191 be_ptask_schedule(task, BE_PTASK_PERIOD, BE_PTASK_SCHEDULE_FROM_NOW);
196 static void be_ptask_schedule(struct be_ptask *task,
203 if (!task->enabled) {
204 DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: disabled\n", task->name);
210 delay = task->first_delay;
213 delay = task->enabled_delay;
216 delay = task->period;
218 if (backoff_allowed(task) && task->period * 2 <= task->max_backoff) {
220 task->period *= 2;
226 if (task->random_offset != 0) {
227 delay = delay + (rand_r(&task->ro_seed) % task->random_offset);
234 DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: scheduling task %lu seconds "
235 "from now [%lu]\n", task->name, delay, tv.tv_sec);
238 tv = tevent_timeval_set(task->last_execution + delay, 0);
240 DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: scheduling task %lu seconds "
242 task->name, delay, tv.tv_sec);
246 if (task->timer != NULL) {
248 "active?\n", task->name);
249 talloc_zfree(task->timer);
252 task->timer = tevent_add_timer(task->ev, task, tv, be_ptask_execute, task);
253 if (task->timer == NULL) {
255 DEBUG(SSSDBG_CRIT_FAILURE, "FATAL: Unable to schedule task [%s]\n",
256 task->name);
257 be_ptask_disable(task);
260 task->next_execution = tv.tv_sec;
278 struct be_ptask *task = NULL;
286 task = talloc_zero(mem_ctx, struct be_ptask);
287 if (task == NULL) {
292 task->ev = be_ctx->ev;
293 task->be_ctx = be_ctx;
294 task->period = period;
295 task->orig_period = period;
296 task->first_delay = first_delay;
297 task->enabled_delay = enabled_delay;
298 task->random_offset = random_offset;
299 task->ro_seed = time(NULL) * getpid();
300 task->max_backoff = max_backoff;
301 task->timeout = timeout;
302 task->offline = offline;
303 task->send_fn = send_fn;
304 task->recv_fn = recv_fn;
305 task->pvt = pvt;
306 task->name = talloc_strdup(task, name);
307 if (task->name == NULL) {
312 task->enabled = true;
314 talloc_set_destructor((TALLOC_CTX*)task, be_ptask_destructor);
318 ret = be_add_online_cb(task, be_ctx, be_ptask_online_cb, task, NULL);
326 ret = be_add_offline_cb(task, be_ctx, be_ptask_offline_cb, task, NULL);
335 DEBUG(SSSDBG_TRACE_FUNC, "Periodic task [%s] was created\n", task->name);
337 be_ptask_schedule(task, BE_PTASK_FIRST_DELAY, BE_PTASK_SCHEDULE_FROM_NOW);
340 *_task = task;
347 talloc_free(task);
353 void be_ptask_enable(struct be_ptask *task)
355 if (task->enabled) {
357 task->name);
361 DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: enabling task\n", task->name);
363 task->enabled = true;
364 be_ptask_schedule(task, BE_PTASK_ENABLED_DELAY, BE_PTASK_SCHEDULE_FROM_NOW);
367 /* Disable the task, but if a request already in progress, let it finish. */
368 void be_ptask_disable(struct be_ptask *task)
370 DEBUG(SSSDBG_TRACE_FUNC, "Task [%s]: disabling task\n", task->name);
372 talloc_zfree(task->timer);
373 task->enabled = false;
374 task->period = task->orig_period;
377 void be_ptask_destroy(struct be_ptask **task)
379 talloc_zfree(*task);
382 time_t be_ptask_get_period(struct be_ptask *task)
384 return task->period;
387 time_t be_ptask_get_timeout(struct be_ptask *task)
389 return task->timeout;