-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_cli.php
More file actions
36 lines (25 loc) · 818 Bytes
/
Copy pathmessage_cli.php
File metadata and controls
36 lines (25 loc) · 818 Bytes
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
<?php
require_once "vendor/autoload.php";
use App\Storage\RedisStorage;
try {
$options = getopt("m:d:");
$config = require "./config/config.php";
$message = $options['m'] ?? null;
$delay = $options['d'] ?? 0;
if ($delay < 0) {
throw new InvalidArgumentException("delay must be a positive number");
}
if (is_null($message)) {
throw new InvalidArgumentException("Missing message argument -m");
}
$storage = new RedisStorage($config['queue']['name'], $config['redis']['host'], $config['redis']['port']);
$time = (new DateTime())->add(new DateInterval("PT{$delay}S"));
$storage->push($message, $time);
echo 'Success!' . PHP_EOL;
return 0;
} catch (\Throwable $e) {
var_dump($e);
echo $e->getMessage();
echo PHP_EOL;
return 1;
}