Browse Source

Put back the Scheduler

master
Timothée Jaussoin 4 weeks ago
parent
commit
e906033ceb
  1. 1
      CHANGELOG.md
  2. 3
      app/PresenceBufferSaver.php
  3. 43
      src/Movim/Scheduler.php
  4. 6
      src/Moxl/Xec/Action/Avatar/SetMetadata.php
  5. 4
      workers/linker.php

1
CHANGELOG.md

@ -41,7 +41,6 @@ v0.32 (master)
* Add a pusher worker that is handling all the WebPush notifications
* Improve the upload progress status, detect when the file is handled by the PHP and return the XMPP progress status
* Add an AvatarHandler worker that is taking care of requesting and saving the Avatar and Banner URLs and base64 avatars
* Remove the Scheduler
v0.31
---------------------------

3
app/PresenceBufferSaver.php

@ -9,6 +9,7 @@ use Moxl\Xec\Action\Vcard\Get;
use App\Presence;
use App\Info;
use App\Contact;
use Movim\Scheduler;
class PresenceBufferSaver
{
@ -111,10 +112,12 @@ class PresenceBufferSaver
$avatarHashes->each(function ($jid, $avatarhash) {
if ($jid != me()->id) {
Scheduler::getInstance()->append('avatar_' . $jid . '_' . $avatarhash, function () use ($jid, $avatarhash) {
$r = new Get;
$r->setAvatarhash($avatarhash)
->setTo($jid)
->request();
});
}
});
}

43
src/Movim/Scheduler.php

@ -0,0 +1,43 @@
<?php
/*
* SPDX-FileCopyrightText: 2023 Jaussoin Timothée
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Movim;
/**
* Spread the functions in time
*/
class Scheduler
{
protected static $instance;
private $_stack = [];
public static function getInstance()
{
if (!isset(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
public function start()
{
global $loop;
$loop->addPeriodicTimer(0.5, function () {
if (!empty($this->_stack)) {
$key = key($this->_stack);
call_user_func($this->_stack[$key]);
unset($this->_stack[$key]);
}
});
}
public function append(string $key, $function)
{
$this->_stack[$key] = $function;
}
}

6
src/Moxl/Xec/Action/Avatar/SetMetadata.php

@ -44,6 +44,12 @@ class SetMetadata extends Action
public function handle(?\SimpleXMLElement $stanza = null, ?\SimpleXMLElement $parent = null)
{
// And we re-request the server to refresh things just in case...
$get = new Get;
$get->setTo($this->_to)
->setNode($this->_node)
->request();
$this->pack(['to' => $this->_to, 'node' => $this->_node]);
$this->deliver();
}

4
workers/linker.php

@ -11,6 +11,7 @@ use React\Promise\Timer;
use App\PresenceBuffer;
use Movim\Widget\Wrapper;
use Movim\Scheduler;
$loop = React\EventLoop\Loop::get();
@ -24,6 +25,9 @@ $server = $config->nameservers ? reset($config->nameservers) : '8.8.8.8';
$factory = new React\Dns\Resolver\Factory();
$dns = $factory->create($server);
// Scheduler
Scheduler::getInstance()->start();
// TCP Connector
$connector = null;

Loading…
Cancel
Save