This repository was archived by the owner on Jan 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathrender_v1_executor.cpp
More file actions
104 lines (80 loc) · 2.82 KB
/
render_v1_executor.cpp
File metadata and controls
104 lines (80 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <libgen.h>
#include <iostream>
#include <vector>
#include <boost/regex.hpp>
#include <curl/curl.h>
#include <stout/os.hpp>
#include "rendler_helper.hpp"
#include "rendler_v1_executor.hpp"
using std::cout;
using std::endl;
using std::vector;
using mesos::vectorToString;
static string renderJSPath;
static string workDirPath;
class RenderV1Executor : public RendlerV1Executor
{
public:
RenderV1Executor(const FrameworkID& _frameworkId,
const ExecutorID& _executorId)
: RendlerV1Executor("RenderV1Executor", _frameworkId, _executorId) {}
virtual ~RenderV1Executor() {}
protected:
void runTask(const TaskInfo& task) override
{
string url = task.data();
cout << "Running render task (" << task.task_id().value() << "): " << url;
string filename = workDirPath + task.task_id().value() + ".png";
vector<string> result;
result.push_back(task.task_id().value());
result.push_back(url);
result.push_back(filename);
string cmd = "QT_QPA_PLATFORM=offscreen phantomjs " + renderJSPath + " " + url + " " + filename;
assert(system(cmd.c_str()) != -1);
sendFrameworkMessage(vectorToString(result));
sendStatusUpdate(task, TASK_FINISHED);
}
};
int main(int argc, char** argv)
{
FrameworkID frameworkId;
ExecutorID executorId;
Option<string> value;
value = os::getenv("MESOS_FRAMEWORK_ID");
if (value.isNone()) {
EXIT(EXIT_FAILURE)
<< "Expecting 'MESOS_FRAMEWORK_ID' to be set in the environment";
}
frameworkId.set_value(value.get());
value = os::getenv("MESOS_EXECUTOR_ID");
if (value.isNone()) {
EXIT(EXIT_FAILURE)
<< "Expecting 'MESOS_EXECUTOR_ID' to be set in the environment";
}
executorId.set_value(value.get());
std::string path = os::realpath(::dirname(argv[0])).get();
renderJSPath = path + "/render.js";
workDirPath = path + "/rendler-work-dir/";
process::Owned<RenderV1Executor> renderer(
new RenderV1Executor(frameworkId, executorId));
process::spawn(renderer.get());
process::wait(renderer.get());
return 0;
}