Skip to content

Commit 30c786e

Browse files
committed
Avoid issues with limited execution time
1 parent e70de92 commit 30c786e

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

‎src/Broadcast/Broadcast.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
namespace danog\MadelineProto\Broadcast;
2222

23-
use Amp\Cancellation;
2423
use danog\MadelineProto\Broadcast\Action\ActionForward;
2524
use danog\MadelineProto\Broadcast\Action\ActionSend;
2625
use Webmozart\Assert\Assert;
@@ -54,9 +53,8 @@ trait Broadcast
5453
* @param array $messages The messages to send: an array of arrays, containing parameters to pass to messages.sendMessage.
5554
* @param bool $pin Whether to also pin the last sent message.
5655
* @param float|null $delay Number of seconds to wait between each peer.
57-
* @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable.
5856
*/
59-
public function broadcastMessages(array $messages, ?Filter $filter = null, bool $pin = false, ?float $delay = null, ?Cancellation $cancellation = null): int
57+
public function broadcastMessages(array $messages, ?Filter $filter = null, bool $pin = false, ?float $delay = null): int
6058
{
6159
foreach ($messages as &$message) {
6260
if (isset($message['media']['_']) &&
@@ -69,11 +67,11 @@ public function broadcastMessages(array $messages, ?Filter $filter = null, bool
6967
) {
7068
$message['media'] = $this->methodCallAsyncRead(
7169
'messages.uploadMedia',
72-
['peer' => 'me', 'media' => $message['media'], 'cancellation' => $cancellation]
70+
['peer' => 'me', 'media' => $message['media']]
7371
);
7472
}
7573
} unset($message);
76-
return $this->broadcastCustom(new ActionSend($this, $messages, $pin), $filter, $delay, $cancellation);
74+
return $this->broadcastCustom(new ActionSend($this, $messages, $pin), $filter, $delay);
7775
}
7876
/**
7977
* Forwards a list of messages to all peers (users, chats, channels) of the bot.
@@ -92,11 +90,10 @@ public function broadcastMessages(array $messages, ?Filter $filter = null, bool
9290
* @param bool $drop_author If true, will forward messages without quoting the original author.
9391
* @param bool $pin Whether to also pin the last sent message.
9492
* @param float|null $delay Number of seconds to wait between each peer.
95-
* @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable.
9693
*/
97-
public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?Filter $filter = null, bool $pin = false, ?float $delay = null, ?Cancellation $cancellation = null): int
94+
public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?Filter $filter = null, bool $pin = false, ?float $delay = null): int
9895
{
99-
return $this->broadcastCustom(new ActionForward($this, $this->getID($from_peer), $message_ids, $drop_author, $pin), $filter, $delay, $cancellation);
96+
return $this->broadcastCustom(new ActionForward($this, $this->getID($from_peer), $message_ids, $drop_author, $pin), $filter, $delay);
10097
}
10198

10299
/**
@@ -113,16 +110,14 @@ public function broadcastForwardMessages(mixed $from_peer, array $message_ids, b
113110
*
114111
* @param Action $action A custom, serializable Action class that will be called once for every peer.
115112
* @param float|null $delay Number of seconds to wait between each peer.
116-
* @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable.
117113
*/
118-
public function broadcastCustom(Action $action, ?Filter $filter = null, ?float $delay = null, ?Cancellation $cancellation = null): int
114+
public function broadcastCustom(Action $action, ?Filter $filter = null, ?float $delay = null): int
119115
{
120116
// Ensure it can be serialized
121117
Assert::eq(unserialize(serialize($action))::class, $action::class);
122118

123119
$id = $this->broadcastId--;
124120
$this->broadcasts[$id] = new InternalState($id, $this, $action, $filter ?? Filter::default(), $delay);
125-
$cancellation?->subscribe(fn () => $this->cancelBroadcast($id));
126121
return $id;
127122
}
128123
/**

‎src/InternalDoc.php

+6-9
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,10 @@ final public function botLogin(string $token): ?array
250250
*
251251
* @param Action $action A custom, serializable Action class that will be called once for every peer.
252252
* @param float|null $delay Number of seconds to wait between each peer.
253-
* @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable.
254253
*/
255-
final public function broadcastCustom(\danog\MadelineProto\Broadcast\Action $action, ?\danog\MadelineProto\Broadcast\Filter $filter = null, ?float $delay = null, ?\Amp\Cancellation $cancellation = null): int
254+
final public function broadcastCustom(\danog\MadelineProto\Broadcast\Action $action, ?\danog\MadelineProto\Broadcast\Filter $filter = null, ?float $delay = null): int
256255
{
257-
return $this->wrapper->getAPI()->broadcastCustom($action, $filter, $delay, $cancellation);
256+
return $this->wrapper->getAPI()->broadcastCustom($action, $filter, $delay);
258257
}
259258
/**
260259
* Forwards a list of messages to all peers (users, chats, channels) of the bot.
@@ -273,11 +272,10 @@ final public function broadcastCustom(\danog\MadelineProto\Broadcast\Action $act
273272
* @param bool $drop_author If true, will forward messages without quoting the original author.
274273
* @param bool $pin Whether to also pin the last sent message.
275274
* @param float|null $delay Number of seconds to wait between each peer.
276-
* @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable.
277275
*/
278-
final public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null, ?\Amp\Cancellation $cancellation = null): int
276+
final public function broadcastForwardMessages(mixed $from_peer, array $message_ids, bool $drop_author = false, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null): int
279277
{
280-
return $this->wrapper->getAPI()->broadcastForwardMessages($from_peer, $message_ids, $drop_author, $filter, $pin, $delay, $cancellation);
278+
return $this->wrapper->getAPI()->broadcastForwardMessages($from_peer, $message_ids, $drop_author, $filter, $pin, $delay);
281279
}
282280
/**
283281
* Sends a list of messages to all peers (users, chats, channels) of the bot.
@@ -296,11 +294,10 @@ final public function broadcastForwardMessages(mixed $from_peer, array $message_
296294
* @param array $messages The messages to send: an array of arrays, containing parameters to pass to messages.sendMessage.
297295
* @param bool $pin Whether to also pin the last sent message.
298296
* @param float|null $delay Number of seconds to wait between each peer.
299-
* @param ?Cancellation $cancellation Cancellation. Note: you may also use cancelBroadcast with the returned broadcast ID. Be aware that when running via web with limited execution time, the broadcast will continue correctly after a restart and cancelBroadcast will still be usable, but the cancellation that is passed here will not be usable.
300297
*/
301-
final public function broadcastMessages(array $messages, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null, ?\Amp\Cancellation $cancellation = null): int
298+
final public function broadcastMessages(array $messages, ?\danog\MadelineProto\Broadcast\Filter $filter = null, bool $pin = false, ?float $delay = null): int
302299
{
303-
return $this->wrapper->getAPI()->broadcastMessages($messages, $filter, $pin, $delay, $cancellation);
300+
return $this->wrapper->getAPI()->broadcastMessages($messages, $filter, $pin, $delay);
304301
}
305302
/**
306303
* Fork a new green thread and execute the passed function in the background.

0 commit comments

Comments
 (0)