| 41 | namespace lgraph { |
| 42 | #if LGRAPH_ENABLE_PYTHON_PLUGIN |
| 43 | PythonPluginManagerImpl::PythonPluginManagerImpl(LightningGraph* db, const std::string& graph_name, |
| 44 | const std::string& dir, int max_idle_seconds, |
| 45 | int max_plugin_lifetime_seconds) |
| 46 | : graph_name_(graph_name), |
| 47 | plugin_dir_(dir), |
| 48 | max_idle_seconds_(max_idle_seconds <= 0 ? std::numeric_limits<int>::max() |
| 49 | : max_idle_seconds), |
| 50 | max_plugin_lifetime_seconds_(max_plugin_lifetime_seconds) { |
| 51 | fma_common::FilePath p(db->GetConfig().dir); |
| 52 | db_dir_ = p.Dir(); |
| 53 | auto& scheduler = fma_common::TimedTaskScheduler::GetInstance(); |
| 54 | _kill_task = scheduler.ScheduleReccurringTask( |
| 55 | max_idle_seconds * 1000, [this](fma_common::TimedTask*) { |
| 56 | std::lock_guard<std::mutex> l(_mtx); |
| 57 | CleanUpIdleProcessesNoLock(); |
| 58 | auto it = _marked_processes.begin(); |
| 59 | while (it != _marked_processes.end()) { |
| 60 | if ((*it)->IsAlive()) { |
| 61 | (*it)->Kill(); |
| 62 | it++; |
| 63 | } else { |
| 64 | it = _marked_processes.erase(it); |
| 65 | } |
| 66 | } |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | PythonPluginManagerImpl::~PythonPluginManagerImpl() { |
| 71 | _kill_task->Cancel(); |