eventio / bbq Goto Github PK
View Code? Open in Web Editor NEWMessage Queue abstraction library for PHP
Message Queue abstraction library for PHP
There is a really small window where a stampede may cause
a PHP warning just before BBQ can throw its own Rename exception.
https://github.com/eventio/bbq/blob/master/src/Eventio/BBQ/Queue/DirectoryQueue.php#L42
When getting the real path (//1) and then rename (//3),
the file might already be snatched by another fetchjob().
$filePath = $file->getRealPath(); // 1
$runFilePath = $filePath . '.run'; // 2
// Renaming to lock the file
if (false === rename($filePath, $runFilePath)) { // 3
throw new \RuntimeException('Renaming from ' . $filePath . ' to ' . $runFilePath . ' failed.');
}
I am using a solution with a ".lockfile" per queue directory.
Since walking and fetching the directory for an open job is a fast iteration,
i am currently using a blocking lock. As an alternative the (currently unused) $timeout
can be used and then do a couple of .5 second retries until $timeout.
I can make a pull-request if you like?
$lockFile = $this->directory . '/' . '.lockfile';
$lockHandle = fopen($lockFile, 'c+b');
if ($lockHandle === false) {
throw new \RuntimeException('Cannot create the lockfile for task directory');
}
$lock = flock($lockHandle, LOCK_EX);
// ...
flock($lockHandle, LOCK_UN);
Note: the createIterator()
also has to be changed
and has to not only exclude isDot() but any dotfile
protected function createIterator()
{
$directoryIterator = new \DirectoryIterator($this->directory);
return new \CallbackFilterIterator($directoryIterator, function($fileInfo) {
return strpos($fileInfo->getFileName(), '.') !== 0;
});
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.