GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (645780)
by milkmeowo
05:42
created

MnsFlushCommand   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 8
1
<?php
2
3
/*
4
 * Laravel-Mns -- 阿里云消息队列(MNS)的 Laravel 适配。
5
 *
6
 * This file is part of the milkmeowo/laravel-mns.
7
 *
8
 * (c) Milkmeowo <[email protected]>
9
 * @link: https://github.com/milkmeowo/laravel-queue-aliyun-mns
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace Milkmeowo\LaravelMns\Console;
16
17
use AliyunMNS\Client;
18
use AliyunMNS\Model\Message;
19
use Illuminate\Console\Command;
20
use AliyunMNS\Requests\BatchReceiveMessageRequest;
21
22
class MnsFlushCommand extends Command
23
{
24
    /**
25
     * The console command name.
26
     *
27
     * @var string
28
     */
29
    protected $signature = 'queue:mns:flush {queue?} {--c|connection=mns}';
30
    /**
31
     * The console command description.
32
     *
33
     * @var string
34
     */
35
    protected $description = 'Flush MNS Queue';
36
37
    /**
38
     * Execute the console command.
39
     *
40
     * @return void
41
     */
42
    public function handle()
43
    {
44
        $queue = $this->argument('queue');
45
        $connection = $this->option('connection');
46
        $config = config("queue.connections.{$connection}");
47
        if (!$queue) {
48
            $queue = $config['queue'];
49
        }
50
        $this->alert('队列:' . $queue);
51
        $client = new Client($config['endpoint'], $config['key'], $config['secret']);
52
        $queue = $client->getQueueRef($queue);
53
        $hasMessage = true;
54
        while ($hasMessage) {
55
            $this->info('拉取信息中...');
56
57
            try {
58
                $response = $queue->batchPeekMessage(15);
59
                if ($response->getMessages()) {
60
                    $hasMessage = true;
61
                } else {
62
                    $hasMessage = false;
63
                }
64
            } catch (\Exception $e) {
65
                $this->info('队列中没消息');
66
                break;
67
            }
68
            $response = $queue->batchReceiveMessage(new BatchReceiveMessageRequest(15, 30));
69
            $handles = [];
70
            /**
71
             * @var Message
72
             */
73
            foreach ($response->getMessages() as $message) {
74
                $handles[] = $message->getReceiptHandle();
75
            }
76
            $response = $queue->batchDeleteMessage($handles);
77
            if ($response->isSucceed()) {
78
                foreach ($handles as $handle) {
79
                    $this->info(sprintf('信息: %s 删除成功', $handle));
80
                }
81
            }
82
        }
83
    }
84
}
85