mirror of
https://github.com/YGGverse/HLState.git
synced 2026-03-31 09:05:44 +00:00
remove crontab dependency (use inline queue with caching proxy)
This commit is contained in:
parent
815d112387
commit
e79364ffc7
4 changed files with 27 additions and 88 deletions
40
README.md
40
README.md
|
|
@ -31,46 +31,6 @@ Project initially written to explore [Yggdrasil](https://github.com/yggdrasil-ne
|
|||
|
||||
* `chown -R www-data:www-data var`
|
||||
* `cp .env .env.local`
|
||||
* `crontab -e` > `* * * * * /usr/bin/curl --silent http://localhost/crontab/index &> /dev/null`
|
||||
|
||||
#### Nginx
|
||||
|
||||
```
|
||||
map $request_uri $loggable {
|
||||
~^/crontab/index 0;
|
||||
default 1;
|
||||
}
|
||||
|
||||
server {
|
||||
listen [::]:27080;
|
||||
|
||||
server_name hl.ygg ygg.hl.srv;
|
||||
|
||||
access_log /var/log/nginx/hl.access.log combined if=$loggable;
|
||||
error_log /var/log/nginx/hl.error.log warn;
|
||||
|
||||
root /var/www/hlstate/HLState/public;
|
||||
|
||||
index index.php index.html;
|
||||
|
||||
location / {
|
||||
try_files $uri /index.php$is_args$args;
|
||||
}
|
||||
location ~ ^/index\.php(/|$) {
|
||||
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
|
||||
fastcgi_split_path_info ^(.+\.php)(/.*)$;
|
||||
include fastcgi_params;
|
||||
|
||||
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
|
||||
fastcgi_param DOCUMENT_ROOT $realpath_root;
|
||||
|
||||
internal;
|
||||
}
|
||||
location ~ \.php$ {
|
||||
return 404;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Update
|
||||
|
||||
|
|
|
|||
8
composer.lock
generated
8
composer.lock
generated
|
|
@ -8070,12 +8070,12 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/YGGverse/hl-php.git",
|
||||
"reference": "795f3047895a875c35f426c5f9d8649967f7b3db"
|
||||
"reference": "9f4e92459283f6775127f0bba8fad0ed1ce88dbf"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/YGGverse/hl-php/zipball/795f3047895a875c35f426c5f9d8649967f7b3db",
|
||||
"reference": "795f3047895a875c35f426c5f9d8649967f7b3db",
|
||||
"url": "https://api.github.com/repos/YGGverse/hl-php/zipball/9f4e92459283f6775127f0bba8fad0ed1ce88dbf",
|
||||
"reference": "9f4e92459283f6775127f0bba8fad0ed1ce88dbf",
|
||||
"shasum": ""
|
||||
},
|
||||
"default-branch": true,
|
||||
|
|
@ -8108,7 +8108,7 @@
|
|||
"issues": "https://github.com/YGGverse/hl-php/issues",
|
||||
"source": "https://github.com/YGGverse/hl-php/tree/main"
|
||||
},
|
||||
"time": "2026-03-04T23:08:13+00:00"
|
||||
"time": "2026-03-04T23:11:24+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\Online;
|
||||
use App\Entity\Player;
|
||||
use App\Entity\Server;
|
||||
|
||||
use App\Service\CrawlerService;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
|
|
@ -9,10 +15,6 @@ use Symfony\Component\Routing\Annotation\Route;
|
|||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
use App\Entity\Online;
|
||||
use App\Entity\Player;
|
||||
use App\Entity\Server;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class MainController extends AbstractController
|
||||
|
|
@ -27,6 +29,7 @@ class MainController extends AbstractController
|
|||
)]
|
||||
public function index(
|
||||
?Request $request,
|
||||
CrawlerService $crawlerService,
|
||||
TranslatorInterface $translatorInterface,
|
||||
EntityManagerInterface $entityManagerInterface
|
||||
): Response
|
||||
|
|
@ -39,6 +42,12 @@ class MainController extends AbstractController
|
|||
$this->getParameter('app.memcached.timeout') + time(),
|
||||
);
|
||||
|
||||
// Run crawler queue
|
||||
$crawlerService->crawl(
|
||||
(array) explode(',', $this->getParameter('app.masters')),
|
||||
$entityManagerInterface
|
||||
);
|
||||
|
||||
// Collect servers info
|
||||
$servers = [];
|
||||
|
||||
|
|
|
|||
|
|
@ -1,52 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Online;
|
||||
use App\Entity\Player;
|
||||
use App\Entity\Server;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Yggverse\HL\Xash3d\Master;
|
||||
|
||||
class CrontabController extends AbstractController
|
||||
class CrawlerService
|
||||
{
|
||||
#[Route(
|
||||
'/crontab/index',
|
||||
name: 'crontab_index',
|
||||
methods:
|
||||
[
|
||||
'GET'
|
||||
]
|
||||
)]
|
||||
public function index(
|
||||
?Request $request,
|
||||
TranslatorInterface $translatorInterface,
|
||||
EntityManagerInterface $entityManagerInterface
|
||||
): Response
|
||||
public function __construct(
|
||||
|
||||
) {}
|
||||
|
||||
public function crawl(array $masters, EntityManagerInterface $entityManagerInterface): void
|
||||
{
|
||||
// Prevent multi-thread execution
|
||||
$semaphore = sem_get(
|
||||
crc32(
|
||||
__DIR__ . '.controller.crontab.index',
|
||||
), 1
|
||||
);
|
||||
|
||||
if (false === sem_acquire($semaphore, true))
|
||||
{
|
||||
return new Response(
|
||||
$translatorInterface->trans('Process locked by another thread')
|
||||
);
|
||||
}
|
||||
|
||||
// Get new servers from masters
|
||||
foreach ((array) explode(',', $this->getParameter('app.masters')) as $master)
|
||||
foreach ($masters as $master)
|
||||
{
|
||||
$master_url = "udp://" . ltrim($master, "udp://"); // @TODO IPv6 https://bugs.php.net/bug.php?id=72811
|
||||
|
||||
|
|
@ -347,8 +320,5 @@ class CrontabController extends AbstractController
|
|||
$node->Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
// Render response
|
||||
return new Response(); // @TODO
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue