-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.php
More file actions
81 lines (73 loc) · 2.49 KB
/
run.php
File metadata and controls
81 lines (73 loc) · 2.49 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
<?php
declare(strict_types=1);
use Keboola\GoogleSheetsWriter\Application;
use Keboola\GoogleSheetsWriter\Exception\ApplicationException;
use Keboola\GoogleSheetsWriter\Exception\UserException;
use Keboola\GoogleSheetsWriter\Logger\HandlerFactory;
use Monolog\Logger;
require_once(dirname(__FILE__) . '/bootstrap.php');
const APP_NAME = 'wr-google-drive';
// initialize logger
$logger = new Logger(APP_NAME, HandlerFactory::getGelfHandlers());
try {
// verify that logger is functional
$logger->debug('Starting up');
} catch (Throwable $e) {
// fallback to stderr logger
$logger->setHandlers(HandlerFactory::getStderrHandlers());
$logger->debug('Starting up');
$logger->error($e->getMessage(), ['exception' => $e]);
}
// initialize application
try {
$arguments = getopt('d::', ['data::']);
if (!isset($arguments['data'])) {
throw new UserException('Data folder not set.');
}
$config = json_decode(file_get_contents($arguments['data'] . '/config.json'), true);
$config['parameters']['data_dir'] = $arguments['data'];
$config['app_name'] = APP_NAME;
$app = new Application($config, $logger);
$result = $app->run();
if (isset($config['action']) && $config['action'] !== 'run') {
echo json_encode($result);
exit(0);
}
} catch (UserException $e) {
if (isset($config['action']) && $config['action'] !== 'run') {
echo json_encode([
'status' => 'error',
'error' => 'User Error',
'message' => $e->getMessage(),
]);
} else {
$logger->error($e->getMessage(), (array) $e->getData());
}
exit(1);
} catch (ApplicationException $e) {
$logger->critical(
get_class($e) . ':' . $e->getMessage(),
[
'errFile' => $e->getFile(),
'errLine' => $e->getLine(),
'errCode' => $e->getCode(),
'errTrace' => $e->getTraceAsString(),
'errPrevious' => $e->getPrevious() ? get_class($e->getPrevious()) : '',
],
);
exit($e->getCode() > 1 ? $e->getCode(): 2);
} catch (Throwable $e) {
$logger->critical(
get_class($e) . ':' . $e->getMessage(),
[
'errFile' => $e->getFile(),
'errLine' => $e->getLine(),
'errCode' => $e->getCode(),
'errTrace' => $e->getTraceAsString(),
'errPrevious' => $e->getPrevious() ? get_class($e->getPrevious()) : '',
],
);
exit(2);
}
$logger->log('info', 'Writer finished successfully.');
exit(0);