Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
iamfarhad committed Jan 8, 2023
1 parent e248447 commit c7c37a2
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
run:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: true
fail-fast: false
matrix:
php: ['8.1']
php: ['8.1', '8.2']
stability: [prefer-stable]

services:
Expand Down
6 changes: 3 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
<ruleset name="PHP_CodeSniffer">
<description>The coding standard for our project.</description>
<file>src</file>

<rule ref="PSR12"/>

<file>src</file>
<file>tests</file>


<!-- Show progression -->
<arg value="p"/>
<arg name="extensions" value="php"/>

<rule ref="PSR12">
<exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
Expand Down
7 changes: 3 additions & 4 deletions src/Connectors/RabbitMQConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class RabbitMQConnector implements ConnectorInterface
{
public function __construct(private readonly Dispatcher $dispatcher)
{
}//end __construct()

}

public function connect(array $config = []): Queue
{
Expand Down Expand Up @@ -48,5 +47,5 @@ public function connect(array $config = []): Queue
$this->dispatcher->listen(WorkerStopping::class, fn() => $rabbitQueue->close());

return $rabbitQueue;
}//end connect()
}//end class
}
}
7 changes: 3 additions & 4 deletions src/Console/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public function handle(): void
$consumer->setPrefetchCount((int) $this->option('prefetch-count'));

parent::handle();
}//end handle()

}

private function consumerTag(): string
{
Expand All @@ -69,5 +68,5 @@ private function consumerTag(): string
);

return Str::substr($consumerTag, 0, 255);
}//end consumerTag()
}//end class
}
}
23 changes: 10 additions & 13 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,29 @@ class Consumer extends Worker
public function setContainer(Container $container): void
{
$this->container = $container;
}//end setContainer()

}

public function setConsumerTag(string $value): void
{
$this->consumerTag = $value;
}//end setConsumerTag()

}

public function setMaxPriority(int $value): void
{
$this->maxPriority = $value;
}//end setMaxPriority()
}


public function setPrefetchSize(int $value): void
{
$this->prefetchSize = $value;
}//end setPrefetchSize()
}


public function setPrefetchCount(int $value): void
{
$this->prefetchCount = $value;
}//end setPrefetchCount()
}


/**
Expand Down Expand Up @@ -175,9 +173,8 @@ function (AMQPMessage $amqpMessage) use ($connection, $workerOptions, $connectio
}

$this->currentJob = null;
}//end while
}//end daemon()

}
}

/**
* Determine if the daemon should process on this iteration.
Expand All @@ -188,7 +185,7 @@ function (AMQPMessage $amqpMessage) use ($connection, $workerOptions, $connectio
protected function daemonShouldRun(WorkerOptions $workerOptions, $connectionName, $queue): bool
{
return !(($this->isDownForMaintenance)() && ! $workerOptions->force) && !$this->paused;
}//end daemonShouldRun()
}


public function stop($status = 0, $options = []): int
Expand All @@ -198,5 +195,5 @@ public function stop($status = 0, $options = []): int
$this->amqpChannel->basic_cancel($this->consumerTag, false, true);

return parent::stop($status);
}//end stop()
}//end class
}
}
33 changes: 12 additions & 21 deletions src/Jobs/RabbitMQJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,23 @@ public function __construct(
$this->connectionName = $connectionName;
$this->queue = $queue;
$this->decoded = $this->payload();
}//end __construct()

}

/**
* {@inheritdoc}
*/
public function getJobId()
{
return $this->decoded['id'] ?? null;
}//end getJobId()

}

/**
* {@inheritdoc}
*/
public function getRawBody(): string
{
return $this->amqpMessage->getBody();
}//end getRawBody()

}

/**
* {@inheritdoc}
Expand All @@ -62,7 +59,7 @@ public function attempts(): int
$laravelAttempts = (int) Arr::get($rabbitMQMessageHeaders, 'laravel.attempts', 0);

return ($laravelAttempts + 1);
}//end attempts()
}


private function convertMessageToFailed(): void
Expand All @@ -71,8 +68,7 @@ private function convertMessageToFailed(): void
$this->rabbitQueue->declareQueue('failed_messages');
$this->rabbitQueue->pushRaw($this->amqpMessage->getBody(), 'failed_messages');
}
}//end convertMessageToFailed()

}

/**
* {@inheritdoc}
Expand All @@ -87,8 +83,7 @@ public function markAsFailed(): void
$this->rabbitQueue->reject($this);

$this->convertMessageToFailed();
}//end markAsFailed()

}

/**
* {@inheritdoc}
Expand All @@ -102,8 +97,7 @@ public function delete(): void
if (! $this->failed) {
$this->rabbitQueue->ack($this);
}
}//end delete()

}

/**
* Release the job back into the queue.
Expand All @@ -123,20 +117,17 @@ public function release($delay = 0): void
// Because this Job message is always recreated and pushed as new message, this Job message is correctly handled.
// We must tell rabbitMQ this job message can be removed by acknowledging the message.
$this->rabbitQueue->ack($this);
}//end release()

}

public function getRabbitMQ(): RabbitQueue
{
return $this->rabbitQueue;
}//end getRabbitMQ()

}

public function getRabbitMQMessage(): AMQPMessage
{
return $this->amqpMessage;
}//end getRabbitMQMessage()

}

private function getRabbitMQMessageHeaders(): ?array
{
Expand All @@ -148,5 +139,5 @@ private function getRabbitMQMessageHeaders(): ?array
}

return $headers->getNativeData();
}//end getRabbitMQMessageHeaders()
}//end class
}
}
7 changes: 3 additions & 4 deletions src/LaravelRabbitQueueServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ function (): \iamfarhad\LaravelRabbitMQ\Consumer {
]
);
}//end if
}//end register()

}

public function boot(): void
{
Expand All @@ -57,5 +56,5 @@ public function boot(): void
$queue = $this->app['queue'];

$queue->addConnector('rabbitmq', fn(): \iamfarhad\LaravelRabbitMQ\Connectors\RabbitMQConnector => new RabbitMQConnector($this->app['events']));
}//end boot()
}//end class
}
}
2 changes: 1 addition & 1 deletion src/RabbitQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function pop($queue = null)
);
}
} catch (AMQPProtocolChannelException $amqpProtocolChannelException) {
// If there is not exchange or queue AMQP will throw exception with code 404
// If there is no exchange or queue AMQP will throw exception with code 404
// We need to catch it and return null
if ($amqpProtocolChannelException->amqp_reply_code === 404) {
// Because of the channel exception the channel was closed and removed.
Expand Down

0 comments on commit c7c37a2

Please sign in to comment.