forked from jmxamongusmodder/watrbx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcron.php
More file actions
81 lines (65 loc) · 2.47 KB
/
cron.php
File metadata and controls
81 lines (65 loc) · 2.47 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
// watrbx cron job
// for now it just does renders but likely will have more
use watrbx\thumbnails;
use watrbx\gameserver;
require('./init.php');
global $db;
$thumbnail = new thumbnails();
$gameserver = new gameserver();
$serverinfo = $gameserver->get_closest_server();
$url = $gameserver->get_server_url($serverinfo);
$Grid = new watrbx\Grid\Grid();
$Close = $Grid->Close($url);
$allofdem = $db->table('jobs')
->where(function($q) {
$q->whereNotNull('assetid')
->orWhereNotNull('userid');
})
->where("type", 2)
->get();
foreach ($allofdem as $job) {
sleep(5); // too many too quick overloads arbiter, especially with games running
$result = $thumbnail->render_asset($job);
if($result[0] == true){
try {
if(isset($result[1][0])){
$base64 = $result[1][0]->getValue();
$img = base64_decode($base64);
if($img){
$md5 = md5($img);
try {
global $s3_client;
$s3_client->putObject([
'Bucket' => $_ENV["R2_BUCKET"],
'Key' => $md5,
'Body' => $img,
'ContentType' => "image/png"
]);
$insert = [
"dimensions"=>$job->dimensions,
"file"=>$md5
];
if(isset($job->userid)){
$insert["userid"] = $job->userid;
$insert["mode"] = $job->jobtype;
}
if(isset($job->assetid)){
$insert["assetid"] = $job->assetid;
}
$insertid = $db->table("thumbnails")->insert($insert);
$db->table("jobs")->where("jobid", $job->jobid)->delete();
echo "\nJob $job->jobid done.";
} catch(Exception $e){
echo "\nSomething went wrong with $job->jobid! $e";
$db->table("jobs")->where("jobid", $job->jobid)->delete();
}
}
}
} catch(Error $e){
$db->table("jobs")->where("jobid", $job->jobid)->delete();
echo "\nSomething went wrong with $job->jobid!\n$e";
}
}
$Close->CloseJob($job->jobid);
}