mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-23 06:13:54 +01:00
Misc fixes
This commit is contained in:
parent
07d3929166
commit
581d00c80a
@ -20,11 +20,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace danog\MadelineProto;
|
namespace danog\MadelineProto;
|
||||||
|
|
||||||
|
use Amp\DeferredFuture;
|
||||||
use Amp\Future;
|
use Amp\Future;
|
||||||
use Amp\Sync\LocalMutex;
|
use Amp\Sync\LocalMutex;
|
||||||
use danog\MadelineProto\Db\DbPropertiesTrait;
|
use danog\MadelineProto\Db\DbPropertiesTrait;
|
||||||
use Generator;
|
use Generator;
|
||||||
|
|
||||||
|
use function Amp\delay;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Event handler.
|
* Event handler.
|
||||||
*/
|
*/
|
||||||
@ -89,6 +92,7 @@ abstract class EventHandler extends InternalDoc
|
|||||||
$this->{$namespace} = $this->exportNamespace($namespace);
|
$this->{$namespace} = $this->exportNamespace($namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private ?Future $startFuture = null;
|
||||||
/**
|
/**
|
||||||
* Start method handler.
|
* Start method handler.
|
||||||
*
|
*
|
||||||
@ -97,6 +101,8 @@ abstract class EventHandler extends InternalDoc
|
|||||||
public function startInternal(): void
|
public function startInternal(): void
|
||||||
{
|
{
|
||||||
$this->startMutex ??= new LocalMutex;
|
$this->startMutex ??= new LocalMutex;
|
||||||
|
$startDeferred = new DeferredFuture;
|
||||||
|
$this->startFuture = $startDeferred->getFuture();
|
||||||
$lock = $this->startMutex->acquire();
|
$lock = $this->startMutex->acquire();
|
||||||
try {
|
try {
|
||||||
if ($this->startedInternal) {
|
if ($this->startedInternal) {
|
||||||
@ -116,9 +122,17 @@ abstract class EventHandler extends InternalDoc
|
|||||||
}
|
}
|
||||||
$this->startedInternal = true;
|
$this->startedInternal = true;
|
||||||
} finally {
|
} finally {
|
||||||
|
$this->startFuture = null;
|
||||||
|
$startDeferred->complete();
|
||||||
$lock->release();
|
$lock->release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function waitForStartInternal(): void {
|
||||||
|
$this->startFuture?->await();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Get peers where to send error reports.
|
* Get peers where to send error reports.
|
||||||
*
|
*
|
||||||
|
@ -123,6 +123,11 @@ final class GarbageCollector
|
|||||||
$memory = \round(\memory_get_usage()/1024/1024, 1);
|
$memory = \round(\memory_get_usage()/1024/1024, 1);
|
||||||
if (!Magic::$suspendPeriodicLogging) {
|
if (!Magic::$suspendPeriodicLogging) {
|
||||||
Logger::log("Memory consumption: $memory Mb", Logger::ULTRA_VERBOSE);
|
Logger::log("Memory consumption: $memory Mb", Logger::ULTRA_VERBOSE);
|
||||||
|
/*try {
|
||||||
|
$maps = \substr_count(\file_get_contents('/proc/self/maps'), "\n");
|
||||||
|
Logger::log("mmap'ed regions: $maps", Logger::ULTRA_VERBOSE);
|
||||||
|
} catch (\Throwable) {
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
return (int) $memory;
|
return (int) $memory;
|
||||||
}
|
}
|
||||||
|
@ -424,12 +424,15 @@ class OutgoingMessage extends Message
|
|||||||
*/
|
*/
|
||||||
public function __toString(): string
|
public function __toString(): string
|
||||||
{
|
{
|
||||||
$state = match ($this->state) {
|
if ($this->state & self::STATE_REPLIED) {
|
||||||
self::STATE_PENDING => 'pending',
|
$state = 'acked (by reply)';
|
||||||
self::STATE_SENT => "sent ".(\time() - $this->sent)." seconds ago",
|
} elseif ($this->state & self::STATE_ACKED) {
|
||||||
self::STATE_ACKED => 'acked',
|
$state = 'acked';
|
||||||
self::STATE_REPLIED => 'acked (by reply)',
|
} elseif ($this->state & self::STATE_SENT) {
|
||||||
};
|
$state = 'sent '.(\time() - $this->sent).' seconds ago';
|
||||||
|
} else {
|
||||||
|
$state = 'pending';
|
||||||
|
}
|
||||||
if ($this->msgId) {
|
if ($this->msgId) {
|
||||||
$msgId = MsgIdHandler::toString($this->msgId);
|
$msgId = MsgIdHandler::toString($this->msgId);
|
||||||
return "{$this->constructor} with message ID $msgId $state";
|
return "{$this->constructor} with message ID $msgId $state";
|
||||||
|
@ -105,6 +105,7 @@ trait UpdateHandler
|
|||||||
if (!isset($this->eventHandlerMethods[$update['_']])) {
|
if (!isset($this->eventHandlerMethods[$update['_']])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
$this->event_handler_instance->waitForStartInternal();
|
||||||
$r = $this->eventHandlerMethods[$update['_']]($update);
|
$r = $this->eventHandlerMethods[$update['_']]($update);
|
||||||
if ($r instanceof Generator) {
|
if ($r instanceof Generator) {
|
||||||
Tools::consumeGenerator($r);
|
Tools::consumeGenerator($r);
|
||||||
@ -121,7 +122,7 @@ trait UpdateHandler
|
|||||||
$payload = \json_encode($update);
|
$payload = \json_encode($update);
|
||||||
Assert::notEmpty($payload);
|
Assert::notEmpty($payload);
|
||||||
Assert::notNull($this->webhookUrl);
|
Assert::notNull($this->webhookUrl);
|
||||||
$request = new Request($this->hook_url, 'POST');
|
$request = new Request($this->webhookUrl, 'POST');
|
||||||
$request->setHeader('content-type', 'application/json');
|
$request->setHeader('content-type', 'application/json');
|
||||||
$request->setBody($payload);
|
$request->setBody($payload);
|
||||||
$result = ($this->datacenter->getHTTPClient()->request($request))->getBody()->buffer();
|
$result = ($this->datacenter->getHTTPClient()->request($request))->getBody()->buffer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user