RStudio Launcher Plugin SDK  1.1.3
A software development kit for creating plugins that work the the RStudio Launcher.
LocalJobRunner.hpp
1 /*
2  * LocalJobRunner.hpp
3  *
4  * Copyright (C) 2020 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant to the terms of a commercial license agreement
7  * with RStudio, then this program is licensed to you under the following terms:
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
10  * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
11  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
15  * Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #ifndef LAUNCHER_PLUGINS_LOCAL_JOB_RUNNER_HPP
25 #define LAUNCHER_PLUGINS_LOCAL_JOB_RUNNER_HPP
26 
27 #include <memory>
28 
29 #include <api/Job.hpp>
30 #include <api/Response.hpp>
31 #include <jobs/JobStatusNotifier.hpp>
32 
33 #include <LocalSecureCookie.hpp>
34 
35 namespace rstudio {
36 namespace launcher_plugins {
37 
38 class Error;
39 
40 namespace system {
41 
42 class AsyncDeadlineEvent;
43 
44 } // namespace system
45 
46 namespace local {
47 
48 class LocalJobRepository;
49 
50 } // namespace local
51 } // namespace launcher_plugins
52 } // namespace rstudio
53 
54 namespace rstudio {
55 namespace launcher_plugins {
56 namespace local {
57 
61 class LocalJobRunner : public std::enable_shared_from_this<LocalJobRunner>
62 {
63 public:
72  const std::string& in_hostname,
73  jobs::JobStatusNotifierPtr in_notifier,
74  std::shared_ptr<LocalJobRepository> in_jobRepository);
75 
81  Error initialize();
82 
91  Error runJob(api::JobPtr& io_job, bool& out_wasInvalidJob);
92 
93 private:
94  // Convenience typedefs.
95  typedef std::weak_ptr<LocalJobRunner> WeakLocalJobRunner;
96  typedef std::map<std::string, std::shared_ptr<system::AsyncDeadlineEvent> > ProcessWatchEvents;
97 
98  static void onJobErrorCallback(api::JobPtr in_job, const std::string& in_errorStr);
99 
107  static void onJobExitCallback(WeakLocalJobRunner in_weakThis, int in_exitCode, api::JobPtr io_job);
108 
116  static void onProcessWatchDeadline(WeakLocalJobRunner in_weakThis, int in_count, api::JobPtr io_job);
117 
124  void addProcessWatchEvent(
125  const std::string& in_id,
126  const std::shared_ptr<system::AsyncDeadlineEvent>& in_processWatchEvent);
127 
133  void removeWatchEvent(const std::string& in_id);
134 
136  const std::string& m_hostname;
137 
139  std::shared_ptr<LocalJobRepository> m_jobRepo;
140 
142  std::mutex m_mutex;
143 
145  jobs::JobStatusNotifierPtr m_notifier;
146 
148  ProcessWatchEvents m_processWatchEvents;
149 
151  LocalSecureCookie m_secureCookie;
152 };
153 
154 } // namespace local
155 } // namespace launcher_plugins
156 } // namespace rstudio
157 
158 #endif
rstudio::launcher_plugins::local::LocalJobRunner::initialize
Error initialize()
Initializes the job runner.
rstudio::launcher_plugins::local::LocalJobRunner::runJob
Error runJob(api::JobPtr &io_job, bool &out_wasInvalidJob)
Runs the specified job.
rstudio::launcher_plugins::local::LocalJobRunner::LocalJobRunner
LocalJobRunner(const std::string &in_hostname, jobs::JobStatusNotifierPtr in_notifier, std::shared_ptr< LocalJobRepository > in_jobRepository)
Constructor.
rstudio::launcher_plugins::Error
Class which represents an error.
Definition: Error.hpp:174
rstudio::launcher_plugins::local::LocalSecureCookie
Reads and makes available the secure-cookie-key-file specified in the launcher.local....
Definition: LocalSecureCookie.hpp:45
rstudio::launcher_plugins::local::LocalJobRunner
Runs jobs on the local machine.
Definition: LocalJobRunner.hpp:61