You've already forked ugly-queue
Removing weird file deletion method.
This commit is contained in:
@@ -103,7 +103,7 @@ class UglyQueue
|
|||||||
{
|
{
|
||||||
if ($this->haveLock === true)
|
if ($this->haveLock === true)
|
||||||
{
|
{
|
||||||
@FileHelper::superUnlink($this->queueGroupDirPath.'queue.lock');
|
unlink($this->queueGroupDirPath.'queue.lock');
|
||||||
$this->haveLock = false;
|
$this->haveLock = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,8 +124,9 @@ class UglyQueue
|
|||||||
|
|
||||||
// If we have an invalid lock structure, THIS IS BAD.
|
// If we have an invalid lock structure, THIS IS BAD.
|
||||||
if (!isset($lock['ttl']) || !isset($lock['born']))
|
if (!isset($lock['ttl']) || !isset($lock['born']))
|
||||||
return true;
|
throw new \RuntimeException('UglyQueue::isLocked - Invalid "queue.lock" file structure seen at "'.$this->queueGroupDirPath.'queue.lock'.'"');
|
||||||
|
|
||||||
|
// Otherwise...
|
||||||
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
|
$lock_ttl = ((int)$lock['born'] + (int)$lock['ttl']);
|
||||||
|
|
||||||
// If we're within the TTL of the lock, assume another thread is already processing.
|
// If we're within the TTL of the lock, assume another thread is already processing.
|
||||||
@@ -134,7 +135,7 @@ class UglyQueue
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Else, remove lock file and assume we're good to go!
|
// Else, remove lock file and assume we're good to go!
|
||||||
@FileHelper::superUnlink($this->queueGroupDirPath.'queue.lock');
|
unlink($this->queueGroupDirPath.'queue.lock');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +240,7 @@ HTML;
|
|||||||
|
|
||||||
fclose($queue_file_handle);
|
fclose($queue_file_handle);
|
||||||
fclose($tmp);
|
fclose($tmp);
|
||||||
FileHelper::superUnlink($this->queueGroupDirPath.'queue.txt');
|
unlink($this->queueGroupDirPath.'queue.txt');
|
||||||
rename($this->queueGroupDirPath.'queue.tmp', $this->queueGroupDirPath.'queue.txt');
|
rename($this->queueGroupDirPath.'queue.tmp', $this->queueGroupDirPath.'queue.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +297,7 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose($queue_file_handle);
|
fclose($queue_file_handle);
|
||||||
FileHelper::superUnlink($this->queueGroupDirPath.'queue.txt');
|
unlink($this->queueGroupDirPath.'queue.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($this->_tmpHandle);
|
fclose($this->_tmpHandle);
|
||||||
@@ -305,6 +306,8 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This method will always return n+1, as there is always a final newline at the end of the file
|
||||||
|
*
|
||||||
* @return int|null
|
* @return int|null
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
@@ -313,7 +316,12 @@ HTML;
|
|||||||
if ($this->init === false)
|
if ($this->init === false)
|
||||||
throw new \RuntimeException('UglyQueue::getQueueItemCount - Must first initialize queue');
|
throw new \RuntimeException('UglyQueue::getQueueItemCount - Must first initialize queue');
|
||||||
|
|
||||||
return FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
$count = FileHelper::getLineCount($this->queueGroupDirPath.'queue.txt');
|
||||||
|
|
||||||
|
if ($count > 0)
|
||||||
|
return ($count - 1);
|
||||||
|
|
||||||
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -146,6 +146,18 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
$addToQueue = $uglyQueue->addToQueue('test', 'value');
|
$addToQueue = $uglyQueue->addToQueue('test', 'value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanConstructUglyQueueWithValidParameter
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testExceptionThrownWhenTryingToGetCountOfItemsInQueueBeforeInitialization(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$itemCount = $uglyQueue->getQueueItemCount();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::initialize
|
* @covers \DCarbone\UglyQueue::initialize
|
||||||
* @covers \DCarbone\UglyQueue::getInit
|
* @covers \DCarbone\UglyQueue::getInit
|
||||||
@@ -226,6 +238,18 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($isLocked);
|
$this->assertFalse($isLocked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::getQueueItemCount
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanInitializeNewUglyQueue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
*/
|
||||||
|
public function testGetQueueItemCountReturnsZeroAfterInitializingEmptyQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
$itemCount = $uglyQueue->getQueueItemCount();
|
||||||
|
$this->assertEquals(0, $itemCount);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \DCarbone\UglyQueue::initialize
|
* @covers \DCarbone\UglyQueue::initialize
|
||||||
* @covers \DCarbone\UglyQueue::__construct
|
* @covers \DCarbone\UglyQueue::__construct
|
||||||
@@ -411,4 +435,21 @@ class UglyQueueTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
return $uglyQueue;
|
return $uglyQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \DCarbone\UglyQueue::addToQueue
|
||||||
|
* @uses \DCarbone\UglyQueue
|
||||||
|
* @depends testCanLockQueueWithValidIntegerValue
|
||||||
|
* @param \DCarbone\UglyQueue $uglyQueue
|
||||||
|
* @return \DCarbone\UglyQueue
|
||||||
|
*/
|
||||||
|
public function testCanPopulateLockedQueue(\DCarbone\UglyQueue $uglyQueue)
|
||||||
|
{
|
||||||
|
foreach($this->tastySandwich as $k=>$v)
|
||||||
|
{
|
||||||
|
$added = $uglyQueue->addToQueue($k, $v);
|
||||||
|
$this->assertTrue($added);
|
||||||
|
}
|
||||||
|
return $uglyQueue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user