MySQL 9.3.0
Source Code Documentation
mysql_task_monitor.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
28
29#include <list>
30#include <memory>
31#include <string>
32#include <thread>
37
38namespace mrs {
39namespace database {
40
42 public:
44
46
47 void call_async(
48 CachedSession session, std::list<std::string> preamble,
49 std::string script, std::list<std::string> postamble,
50 std::function<std::list<std::string>(const std::exception &)> on_error,
51 const std::string &task_id);
52
53 public:
54 void start();
55 void stop();
56 void reset();
57
58 private:
59 struct Task {
61 std::list<std::string> preamble;
62 std::string script;
63 std::list<std::string> postamble;
64 std::list<std::string> error;
65 std::function<std::list<std::string>(const std::exception &)> on_error;
66
67 std::string task_id;
68 bool failed = false;
69 };
70
72
73 std::thread thread_;
75
76 std::mutex tasks_mutex_;
77 std::list<Task> tasks_;
78
79 void run();
80
81 bool update_task(Task &task);
82};
83
84} // namespace database
85} // namespace mrs
86
87#endif // ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_DATABASE_MYSQL_TASK_MONITOR_H_
Definition: wait_variable.h:34
Definition: cache_manager.h:41
MySqlCacheManager::CachedObject CachedObject
Definition: mysql_cache_manager.h:92
Definition: mysql_task_monitor.h:41
void reset()
Definition: mysql_task_monitor.cc:56
std::list< Task > tasks_
Definition: mysql_task_monitor.h:77
void start()
Definition: mysql_task_monitor.cc:40
void run()
Definition: mysql_task_monitor.cc:61
~MysqlTaskMonitor()
Definition: mysql_task_monitor.cc:38
std::mutex tasks_mutex_
Definition: mysql_task_monitor.h:76
State
Definition: mysql_task_monitor.h:71
@ k_check_tasks
Definition: mysql_task_monitor.h:71
@ k_initializing
Definition: mysql_task_monitor.h:71
@ k_running
Definition: mysql_task_monitor.h:71
@ k_stopped
Definition: mysql_task_monitor.h:71
WaitableVariable< State > state_
Definition: mysql_task_monitor.h:74
void stop()
Definition: mysql_task_monitor.cc:47
void call_async(CachedSession session, std::list< std::string > preamble, std::string script, std::list< std::string > postamble, std::function< std::list< std::string >(const std::exception &)> on_error, const std::string &task_id)
Definition: mysql_task_monitor.cc:95
bool update_task(Task &task)
Definition: mysql_task_monitor.cc:111
std::thread thread_
Definition: mysql_task_monitor.h:73
Definition: authorize_manager.h:48
Definition: mysql_task_monitor.h:59
std::function< std::list< std::string >(const std::exception &)> on_error
Definition: mysql_task_monitor.h:65
std::string task_id
Definition: mysql_task_monitor.h:67
bool failed
Definition: mysql_task_monitor.h:68
std::string script
Definition: mysql_task_monitor.h:62
CachedSession session
Definition: mysql_task_monitor.h:60
std::list< std::string > preamble
Definition: mysql_task_monitor.h:61
std::list< std::string > error
Definition: mysql_task_monitor.h:64
std::list< std::string > postamble
Definition: mysql_task_monitor.h:63