Warning
This is a design page. It was used to design and discuss the initial implementation of the change. However, the state of this document does not necessarily correspond to the current state of the implementation since we do not keep this document up to date with further changes and bug fixes.
Periodic task API
Related ticket(s):
Problem Statement
SSSD contains several periodic tasks that implements custom periodic API. These APIs are more or less sophisticated but it does the same thing.
Current periodic tasks are:
Enumeration
Dynamic DNS updates
SUDO - full and smart refresh
Refresh of expired NSS entries
We want to replace these individual implementation with one back end wise API.
Implementation details
New error code:
- ERR_STOP_PERIODIC_TASK
struct be_ptask;
typedef struct tevent_req *
(*be_ptask_send_t)(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
struct be_ptask *be_ptask,
void *pvt);
typedef errno_t
(*be_ptask_recv_t)(struct tevent_req *req);
enum be_ptask_offline {
BE_PTASK_OFFLINE_SKIP,
BE_PTASK_OFFLINE_DISABLE,
BE_PTASK_OFFLINE_EXECUTE
};
errno_t be_ptask_create(TALLOC_CTX *mem_ctx,
struct be_ctx *be_ctx,
time_t period,
time_t first_delay,
time_t enabled_delay,
time_t timeout,
enum be_ptask_offline offline,
be_ptask_send_t send,
be_ptask_recv_t recv,
void *pvt,
const char *name,
struct be_ptask **_task);
void be_ptask_enable(struct be_ptask *task);
void be_ptask_disable(struct be_ptask *task);
void be_ptask_destroy(struct be_ptask **task);
Terminology
task: object of type be_ptask
request: tevent request that is fired periodically and is managed by task
API
struct be_ptask_task is encapsulated.
be_ptask_create() creates and starts new periodic task
be_ptask_enable(task) enable task and schedule next execution enabled_delay from now
be_ptask_disable(task) disable task, cancel current timer and wait until it is enabled again
be_ptask_destroy(task) destroys task and sets it to NULL
Schedule rules
the first execution is scheduled first_delay seconds after the task is created
if request returns EOK, it will be scheduled again to ‘last_execution_time + period’
if request returns ERR_STOP_PERIODIC_TASK, the task will be terminated
if request returns other error code (i.e. non fatal failure), it will be rescheduled to ‘now + period’
if request does not complete in timeout seconds, it will be cancelled and rescheduled to ‘now + period’
if the task is reenabled, it will be scheduled again to ‘now + enabled_delay’
When offline
Offline behaviour is controlled by offline parameter.
If offline is BE_PTASK_OFFLINE_EXECUTE and back end is offline, current request will be executed as planned.
If offline is BE_PTASK_OFFLINE_SKIP and back end is offline, current request will be skipped and rescheduled to ‘now + period’.
If offline is BE_PTASK_OFFLINE_DISABLE, an offline and online callback is registered. The task is disabled immediately when back end goes offline and then enabled again when back end goes back online.
Debugging
Task will provide enough debugging information so we can know exactly when a task is created and destroy, when it is executed and finished and when it will be executed in the future.
Author(s)
Pavel Březina <pbrezina@redhat.com>