MySQL 8.0.39
Source Code Documentation
mysql_scheduler.h
Go to the documentation of this file.
1/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_SCHEDULER_H
25#define MYSQL_SCHEDULER_H
26
29
30/**
31 @ingroup group_components_services_inventory
32
33 The Scheduler queueing interface.
34
35 This is a service that will allow registering a callback to be called
36 every X seconds.
37
38 Each callback has a name. And a comment for the DBA to check.
39
40 A caller registers a callback together with its argument and gets a handle
41 back. The callback will be put in rotation immediately and will be called
42 after the defined interval. And it will keep being called until it's
43 unregisterered using the handle.
44
45 Passing an argument is useful if you are to reuse the callback function
46 to operate on many different states through registering it in multiple
47 scheduled events.
48 Having the argument passed down from the registering code to the callback
49 saves the need of the callback to consult a global structure in a multi-
50 thread safe fashion.
51
52 @warning Keep the runnable function *SHORT*! Or design a way for it to be
53 graciously shut down through a flag inside the argument.
54
55 To use it one would do something like this:
56
57 @code
58 bool sheduled_callback(mysql_scheduler_runnable_handle handle, void *arg) {
59 int *ctr = reinterpret_cast<std::atomic<int> *>(arg);
60 *ctr++;
61 }
62
63 REQUIRES_SERVICE(mysql_scheduler);
64
65 int caller() {
66 std::atomic<int> data= 0;
67 mysql_scheduler_runnable_handle handle = nullptr;
68 mysql_service_mysql_scheduler->create(
69 &handle, sheduled_callback,
70 (void *)&data,
71 "gizmo", "This is a sheduled task to call gizmo",
72 10);
73
74 ....
75
76 mysql_service_mysql_scheduler->destroy(handle);
77 handle = nullptr;
78 }
79 @endcode
80
81 @sa @ref mysql_scheduler_runnable_handle,
82 @ref mysql_scheduler_runnable_function
83
84*/
86
87/**
88 Schedule a runnable task
89
90 @param[out] out_handle The context of the newly scheduled task. To be kept
91 as an interaction vector with the running task.
92 @param runnable The function to call
93 @param arg An argument to pass to the runnable.
94 Must be valid until unregistered.
95 @param name The name of the runnable in UTF8.
96 @param comment A free form comment in UTF8. No more than 1024 bytes.
97 @param interval_secs How frequently to schedule the task (in seconds).
98 Must be greater than 1 since this is the resolution.
99 @retval false success
100 @retval true failure
101*/
104 mysql_scheduler_runnable_function runnable, void *arg,
105 const char *name, const char *comment, int interval_secs));
106
107/**
108 End a scheduled task/subtask
109
110 This will:
111 * unschedule the task
112 * wait for the scheduled task runnable to end, if running currently
113
114 @param handle The context of the task to end
115 @retval false success
116 @retval true failure
117*/
119
121
122/**
123 @ingroup group_components_services_inventory
124 Notification service for the scheduler customers.
125 The scheduler will broadcast this at important events of its operation
126 that may be of interest to customers.
127 Currently only supports STARTED event:
128 When the scheduler starts some of its "customers" may be already
129 loaded and have allowed delayed initialization.
130 To avoid polling for scheduler implementations, the scheduler
131 will broadcast to all implementations of this service at its startup so
132 they can register their scheduled tasks.
133 This is useful for e.g. customers loading prior to the scheduler and
134 willing to register their tasks when the scheduler is present.
135*/
136BEGIN_SERVICE_DEFINITION(mysql_scheduler_notify)
137/**
138 @retval true failure
139 @retval false success
140 @param what Notification kind. One of:
141 * STARTED : the sheduler is open for service. Clients
142 should re-try registering their tasks.
143*/
144DECLARE_BOOL_METHOD(emit, (const char *what));
145END_SERVICE_DEFINITION(mysql_scheduler_notify)
146
147#endif /* MYSQL_SCHEDULER_H */
static char * emit(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, unsigned char *null_value, unsigned char *error)
UDF function itself.
Definition: audit_api_message_emit.cc:429
#define comment
Definition: lexyy.cc:959
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
bool(* mysql_scheduler_runnable_function)(mysql_scheduler_runnable_handle handle, void *arg)
the callback function pointer signature
Definition: mysql_scheduler_bits.h:33
static int destroy(mysql_cond_t *that, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:54
static mysql_service_status_t create(const char *service_names[], reference_caching_channel *out_channel) noexcept
Definition: component.cc:36
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
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112
case opt name
Definition: sslopt-case.h:33