Add TaskManager task to fail pending imports over an hour old
This commit is contained in:
parent
8978c3692d
commit
ada7212823
2 changed files with 72 additions and 0 deletions
|
@ -5,6 +5,15 @@ require_once("FileIO.php");
|
|||
|
||||
class Application_Service_MediaService
|
||||
{
|
||||
|
||||
const PENDING_FILE_TIMEOUT_SECONDS = 3600;
|
||||
|
||||
/**
|
||||
* @var array store an internal array of the pending files so we don't have
|
||||
* to go to the database twice
|
||||
*/
|
||||
private static $_pendingFiles;
|
||||
|
||||
/** Move (or copy) a file to the stor/organize directory and send it off to the
|
||||
analyzer to be processed.
|
||||
* @param $callbackUrl
|
||||
|
@ -111,5 +120,31 @@ class Application_Service_MediaService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there are any files that have been stuck
|
||||
* in Pending status for over an hour
|
||||
*
|
||||
* @return bool true if there are any files stuck pending,
|
||||
* otherwise false
|
||||
*/
|
||||
public static function areFilesStuckInPending() {
|
||||
$oneHourAgo = gmdate(DEFAULT_TIMESTAMP_FORMAT, (microtime(true) - self::PENDING_FILE_TIMEOUT_SECONDS));
|
||||
self::$_pendingFiles = CcFilesQuery::create()
|
||||
->filterByDbImportStatus(CcFiles::IMPORT_STATUS_PENDING)
|
||||
->filterByDbUtime($oneHourAgo, Criteria::LESS_EQUAL)
|
||||
->find();
|
||||
return !empty(self::$_pendingFiles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up stuck imports by changing their import status to Failed
|
||||
*/
|
||||
public static function clearStuckPendingImports() {
|
||||
foreach(self::$_pendingFiles as $file) {
|
||||
/** @var $file CcFiles */
|
||||
$file->setDbImportStatus(CcFiles::IMPORT_STATUS_FAILED)->save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue