MySQL 8.4.0
Source Code Documentation
s_mysql_mysql_scheduler Struct Reference

The Scheduler queueing interface. More...

#include <mysql_scheduler.h>

Public Attributes

mysql_service_status_t(* create )(mysql_scheduler_runnable_handle *out_handle, mysql_scheduler_runnable_function runnable, void *arg, const char *name, const char *comment, int interval_secs)
 Schedule a runnable task. More...
 
mysql_service_status_t(* destroy )(mysql_scheduler_runnable_handle handle)
 End a scheduled task/subtask. More...
 

Detailed Description

The Scheduler queueing interface.

This is a service that will allow registering a callback to be called every X seconds.

Each callback has a name. And a comment for the DBA to check.

A caller registers a callback together with its argument and gets a handle back. The callback will be put in rotation immediately and will be called after the defined interval. And it will keep being called until it's unregisterered using the handle.

Passing an argument is useful if you are to reuse the callback function to operate on many different states through registering it in multiple scheduled events. Having the argument passed down from the registering code to the callback saves the need of the callback to consult a global structure in a multi- thread safe fashion.

Warning
Keep the runnable function SHORT! Or design a way for it to be graciously shut down through a flag inside the argument.

To use it one would do something like this:

bool sheduled_callback(mysql_scheduler_runnable_handle handle, void *arg) {
int *ctr = reinterpret_cast<std::atomic<int> *>(arg);
*ctr++;
}
REQUIRES_SERVICE(mysql_scheduler);
int caller() {
std::atomic<int> data= 0;
mysql_service_mysql_scheduler->create(
&handle, sheduled_callback,
(void *)&data,
"gizmo", "This is a sheduled task to call gizmo",
10);
....
mysql_service_mysql_scheduler->destroy(handle);
handle = nullptr;
}
#define REQUIRES_SERVICE(service)
Adds a Service requirement with a pointer to placeholder to the list of components.
Definition: component_implementation.h:305
struct mysql_scheduler_runnable_handle_imp * mysql_scheduler_runnable_handle
The hande to the runnable, to use in deregistration.
Definition: mysql_scheduler_bits.h:30
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:64
See also
mysql_scheduler_runnable_handle, mysql_scheduler_runnable_function

Member Data Documentation

◆ create

mysql_service_status_t(* s_mysql_mysql_scheduler::create) (mysql_scheduler_runnable_handle *out_handle, mysql_scheduler_runnable_function runnable, void *arg, const char *name, const char *comment, int interval_secs)

Schedule a runnable task.

Parameters
[out]out_handleThe context of the newly scheduled task. To be kept as an interaction vector with the running task.
runnableThe function to call
argAn argument to pass to the runnable. Must be valid until unregistered.
nameThe name of the runnable in UTF8.
commentA free form comment in UTF8. No more than 1024 bytes.
interval_secsHow frequently to schedule the task (in seconds). Must be greater than 1 since this is the resolution.
Return values
falsesuccess
truefailure

◆ destroy

mysql_service_status_t(* s_mysql_mysql_scheduler::destroy) (mysql_scheduler_runnable_handle handle)

End a scheduled task/subtask.

This will: unschedule the task wait for the scheduled task runnable to end, if running currently

Parameters
handleThe context of the task to end
Return values
falsesuccess
truefailure

The documentation for this struct was generated from the following file: