Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call reset on the logger in order to clean buffers #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ services:
arguments:
- 'text/html'

Psr\Log\LoggerInterface:
class: \Monolog\Logger
Psr\Log\LoggerInterface: '@webgriffe_esb_logger'

Webgriffe\Esb\LoggerResettableInterface: '@webgriffe_esb_logger'

webgriffe_esb_logger:
class: \Webgriffe\Esb\Logger\LoggerResettable
arguments: [ 'esb', ['@Monolog\Handler\StreamHandler', '@Monolog\Handler\ErrorLogHandler', '@Monolog\Handler\NativeMailerHandler'] ]
public: true

Expand Down
11 changes: 11 additions & 0 deletions src/Logger/LoggerResettable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Webgriffe\Esb\Logger;

use Monolog\Logger;

final class LoggerResettable extends Logger implements LoggerResettableInterface
{
}
12 changes: 12 additions & 0 deletions src/Logger/LoggerResettableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Webgriffe\Esb\Logger;

use Monolog\ResettableInterface;
use Psr\Log\LoggerInterface;

interface LoggerResettableInterface extends LoggerInterface, ResettableInterface
{
}
8 changes: 5 additions & 3 deletions src/ProducerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use function Amp\call;
use Amp\Loop;
use Amp\Promise;
use Psr\Log\LoggerInterface;
use Webgriffe\Esb\Logger\LoggerResettableInterface;
use Webgriffe\Esb\Model\FlowConfig;
use Webgriffe\Esb\Model\Job;
use Webgriffe\Esb\Model\ProducedJobEvent;
Expand All @@ -31,7 +31,7 @@ final class ProducerInstance implements ProducerInstanceInterface
private $producer;

/**
* @var LoggerInterface
* @var LoggerResettableInterface
*/
private $logger;

Expand All @@ -54,7 +54,7 @@ public function __construct(
FlowConfig $flowConfig,
ProducerInterface $producer,
?BeanstalkClient $beanstalkClient,
LoggerInterface $logger,
LoggerResettableInterface $logger,
HttpProducersServer $httpProducersServer,
CronProducersServer $cronProducersServer,
?ElasticSearch $elasticSearch,
Expand Down Expand Up @@ -195,6 +195,8 @@ public function produceAndQueueJobs($data = null): Promise
'test' => $test
]
);
} finally {
$this->logger->reset();
}
return $jobsCount;
});
Expand Down
12 changes: 9 additions & 3 deletions src/WorkerInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use function Amp\call;
use function Amp\delay;
use Amp\Promise;
use Psr\Log\LoggerInterface;
use Webgriffe\Esb\Exception\FatalQueueException;
use Webgriffe\Esb\Logger\LoggerResettableInterface;
use Webgriffe\Esb\Model\ErroredJobEvent;
use Webgriffe\Esb\Model\FlowConfig;
use Webgriffe\Esb\Model\JobInterface;
Expand Down Expand Up @@ -37,7 +37,7 @@ final class WorkerInstance implements WorkerInstanceInterface
private $worker;

/**
* @var LoggerInterface
* @var LoggerResettableInterface
*/
private $logger;

Expand All @@ -56,7 +56,7 @@ public function __construct(
int $instanceId,
WorkerInterface $worker,
?BeanstalkClient $beanstalkClient,
LoggerInterface $logger,
LoggerResettableInterface $logger,
?ElasticSearch $elasticSearch,
WorkerQueueManagerInterface $queueManager = null
) {
Expand Down Expand Up @@ -146,13 +146,16 @@ public function boot(): Promise
try {
/** @var JobInterface $job */
if (!($job = yield $this->queueManager->getNextJob())) {
$this->logger->reset(); // todo: necessary?
break;
}
} catch (FatalQueueException $ex) {
//Let this pass to stop the loop
$this->logger->reset(); // todo: necessary?
throw $ex;
} catch (\Exception $ex) {
$this->logger->critical($ex->getMessage(), $globalLogContext);
$this->logger->reset();
continue;
}

Expand Down Expand Up @@ -207,6 +210,7 @@ public function boot(): Promise
)
);
unset(self::$workCounts[$jobUuid]);
$this->logger->reset();
continue;
}

Expand All @@ -215,6 +219,8 @@ public function boot(): Promise
'Worker released a Job',
array_merge($logContext, ['release_delay' => $this->flowConfig->getWorkerReleaseDelay()])
);
} finally {
$this->logger->reset();
}
}
});
Expand Down