Skip to content

Instantly share code, notes, and snippets.

@zeromodule
Last active July 25, 2016 13:04
Show Gist options
  • Save zeromodule/89336537cd42ccb3c7d31597ae079ebe to your computer and use it in GitHub Desktop.
Save zeromodule/89336537cd42ccb3c7d31597ae079ebe to your computer and use it in GitHub Desktop.
public function actionRecreateMultires($panorama_id)
{
/** @var PanoramaService $panoramaService */
$panoramaService = \Yii::app()->panorama;
/** @var Panorama $panorama */
$panorama = \Panorama::model()->findByPk($panorama_id);
$s3 = new S3(Yii::app()->s3->aKey, Yii::app()->s3->sKey);
if ($panorama) {
$saveTo = (new LocalStorageManager())->getAbsoluteUploadDirPath() . $panorama->filename;
echo "Trying to get original from S3 and save it to $saveTo\n";
$s3result = $s3->getObject(Yii::app()->assetManager->bucket, 'upload/'.$panorama->filename, $saveTo);
if ($s3result && empty($s3result->error)) {
echo "All systems OK, we are ready to send task\n";
$panoramaService->convertPanoramaMultires($panorama, PanoramaService::TILE_SIZE);
echo "Task sended\n";
$key = (new PanoramaJobStatus($panorama->panorama_id, Panorama::MULTIRES_VERSION))->getKey();
echo "Using redis key $key to check results...\n";
$completed = false;
while (!$completed) {
sleep(1);
$redisData = $panoramaService->getRedisClient()->hGetAll($key);
$status = ($redisData && !empty($redisData['panorama_id'])) ? PanoramaJobStatus::fromArray($redisData) : null;
if (!$status) {
echo "No data in Redis...retrying\n";
}else{
echo "Found data in Redis... ";
if ($status->getStatus() == PanoramaJobStatus::STATUS_UNPROCESSED) {
echo "status UNPROCESSED (work in progress)...\n";
}elseif ($status->getStatus() == PanoramaJobStatus::STATUS_COMPLETED){
$panoramaService->completePanoramaJob($status);
echo "status COMPLETED (work done).\n";
exit;
}elseif ($status->getStatus() == -1){
echo "status FAILED (error occured, see Celery logs for details).\n";
exit;
}
}
}
}elseif(!$s3result || $s3result->error){
var_dump($s3result);
}
} else {
echo "Panorama with ID $panorama_id doesn't exists\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment