Skip to content
This repository has been archived by the owner on Oct 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from koolay/lumen
Browse files Browse the repository at this point in the history
支持Lumen5.3
  • Loading branch information
abrahamgreyson committed Apr 2, 2022
2 parents 9744e0c + c05e9fe commit dc7c21b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/Connectors/MnsConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
namespace LaravelMns\Connectors;

use AliyunMNS\Client as MnsClient;
use Config;
use Illuminate\Queue\Connectors\ConnectorInterface;
use LaravelMns\MnsAdapter;
use LaravelMns\MnsQueue;
Expand All @@ -36,7 +35,7 @@ class MnsConnector implements ConnectorInterface
*/
public function connect(array $config)
{
$config = Config::get('queue.connections.mns');
$config = config('queue.connections.mns');

return new MnsQueue(
new MnsAdapter(
Expand Down
15 changes: 7 additions & 8 deletions src/Jobs/MnsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,16 @@ public function __construct(

/**
* Fire the job.
*
* @return void
*/
public function fire()
{
$body = json_decode($this->getRawBody(), true);
if (!is_array($body)) {
throw new \InvalidArgumentException(
"Seems it's not a Laravel enqueued job. \r\n
[$body]"
);
if (method_exists($this, 'resolveAndFire')) {
$this->resolveAndFire(json_decode($this->getRawBody(), true));
return;
}
$this->resolveAndFire($body);
parent::fire();
}

/**
Expand Down Expand Up @@ -106,7 +105,7 @@ public function release($delay = 0)
// 默认情况下 Laravel 将以 delay 0 来更改可见性,其预期的是使用队列服务默认的
// 下次可消费时间,但 Aliyun MNS PHP SDK 的接口要求这个值必须大于 0,
// 指从现在起,多久后消息变为可消费。
$delay = 0 !== $delay
$delay = $delay > 0
? $delay
: $this->fromNowToNextVisibleTime($this->job->getNextVisibleTime());
parent::release($delay);
Expand Down
13 changes: 12 additions & 1 deletion src/MnsQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function pop($queue = null)
}
}

return;
return null;
}

/**
Expand Down Expand Up @@ -153,4 +153,15 @@ public function createJobsUsing(callable $callback)

return $this;
}

/**
* Get the size of the queue.
*
* @param string $queue
* @return int
*/
public function size($queue = null)
{
throw new NotImplementedException('size方法没有实现');
}
}
9 changes: 9 additions & 0 deletions src/NotImplementedException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace LaravelMns;


class NotImplementedException extends \Exception
{

}

0 comments on commit dc7c21b

Please sign in to comment.