GithubHelp home page GithubHelp logo

bbq's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bbq's Issues

DirectoryQueue stampede

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;
  });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.