forked from skylerkatz/hover
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap
70 lines (49 loc) · 1.96 KB
/
bootstrap
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
#!/usr/local/bin/php
<?php
use Illuminate\Support\Str;
ini_set('display_errors', '1');
error_reporting(E_ALL);
$appRoot = getenv('LAMBDA_TASK_ROOT');
$runtimePath = getenv('LAMBDA_TASK_ROOT').'/hover_runtime';
require $runtimePath.'/Hover.php';
require $appRoot.'/vendor/autoload.php';
require $runtimePath.'/Lambda.php';
require $runtimePath.'/EventProcessors/AbstractEventProcessor.php';
$manifest = json_decode(file_get_contents($runtimePath.'/manifest.json'), true);
$lambda = new Lambda();
$hover = new Hover($manifest);
$processor = null;
try {
$hover->createStorageDirectories();
$hover->populateEnvironmentVariables();
$app = $hover->getAppInstance($appRoot);
$hover->cacheLaravelStuff($app);
if (Str::endsWith($_ENV['AWS_LAMBDA_FUNCTION_NAME'], '-http')) {
require $runtimePath.'/FpmRequest.php';
require $runtimePath.'/FpmManager.php';
require $runtimePath.'/ApiGateway.php';
require $runtimePath.'/Warmer.php';
require $runtimePath.'/EventProcessors/HttpFpmEventProcessor.php';
$fpmManager = new FpmManager();
$fpmManager->start();
$processor = new HttpFpmEventProcessor(new ApiGateway(), $fpmManager, new Warmer());
}
if (Str::endsWith($_ENV['AWS_LAMBDA_FUNCTION_NAME'], '-cli')) {
require $runtimePath.'/EventProcessors/CliEventProcessor.php';
$processor = new CliEventProcessor();
}
if (Str::endsWith($_ENV['AWS_LAMBDA_FUNCTION_NAME'], '-queue')) {
require $runtimePath.'/Worker.php';
require $runtimePath.'/EventProcessors/QueueEventProcessor.php';
$processor = new QueueEventProcessor($app, $manifest);
}
} catch (\Throwable $e) {
$lambda->sendInitializationFailureResponseToLambda($e);
throw $e;
}
while (true) {
[$invocationBody, $invocationId, $invocationDeadline] = $lambda->getNextInvocation();
$lambda->processInvocation(
$invocationBody, $invocationId, $invocationDeadline, $processor
);
}