Skip to content

Commit

Permalink
Improve importer stability(?)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawngee committed Nov 5, 2018
1 parent 8fb441d commit f1fd408
Show file tree
Hide file tree
Showing 13 changed files with 552 additions and 241 deletions.
18 changes: 11 additions & 7 deletions classes/CLI/Rekognition/RekognitionCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace ILAB\MediaCloud\CLI\Rekognition;

use ILAB\MediaCloud\CLI\Command;
use ILAB\MediaCloud\Tasks\BatchManager;
use ILAB\MediaCloud\Tools\Rekognition\RekognitionTool;
use ILAB\MediaCloud\Tools\ToolsManager;

Expand Down Expand Up @@ -70,10 +71,13 @@ public function process($args, $assoc_args) {

$postCount = count($posts);
if($postCount > 0) {
update_option('ilab_rekognizer_status', true);
update_option('ilab_rekognizer_total_count', $postCount);
update_option('ilab_rekognizer_current', 1);
update_option('ilab_rekognizer_should_cancel', false);
BatchManager::instance()->reset('rekognizer');


BatchManager::instance()->setStatus('rekognizer', true);
BatchManager::instance()->setTotalCount('rekognizer', $postCount);
BatchManager::instance()->setCurrent('rekognizer', 1);
BatchManager::instance()->setShouldCancel('rekognizer', false);

Command::Info("Total posts found: %Y{$postCount}.", true);

Expand All @@ -82,8 +86,8 @@ public function process($args, $assoc_args) {
$upload_file = get_attached_file($postId);
$fileName = basename($upload_file);

update_option('ilab_rekognizer_current_file', $fileName);
update_option('ilab_rekognizer_current', $i);
BatchManager::instance()->setCurrentFile('rekognizer', $fileName);
BatchManager::instance()->setCurrent('rekognizer', $i);

Command::Info("%w[%C{$i}%w of %C{$postCount}%w] %NProcessing %Y$fileName%N %w(%N$postId%w)%N ... ");

Expand All @@ -104,7 +108,7 @@ public function process($args, $assoc_args) {
Command::Info("%YDone%N.", true);
}

delete_option('ilab_rekognizer_status');
BatchManager::instance()->reset('rekognizer');
}
}

Expand Down
32 changes: 20 additions & 12 deletions classes/CLI/Storage/StorageCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use ILAB\MediaCloud\CLI\Command;
use ILAB\MediaCloud\Cloud\Storage\StorageSettings;
use ILAB\MediaCloud\Tasks\BatchManager;
use ILAB\MediaCloud\Tools\Storage\DefaultProgressDelegate;
use ILAB\MediaCloud\Tools\Storage\ImportProgressDelegate;
use ILAB\MediaCloud\Tools\Storage\StorageTool;
Expand Down Expand Up @@ -69,10 +70,12 @@ public function import($args, $assoc_args) {
$query = new \WP_Query($postArgs);

if($query->post_count > 0) {
update_option('ilab_s3_import_status', true);
update_option('ilab_s3_import_total_count', $query->post_count);
update_option('ilab_s3_import_current', 1);
update_option('ilab_s3_import_should_cancel', false);
BatchManager::instance()->reset('storage');

BatchManager::instance()->setStatus('storage', true);
BatchManager::instance()->setTotalCount('storage', $query->post_count);
BatchManager::instance()->setCurrent('storage', 1);
BatchManager::instance()->setShouldCancel('storage', false);

Command::Info("Total posts found: %Y{$query->post_count}.", true);

Expand All @@ -83,14 +86,17 @@ public function import($args, $assoc_args) {
$upload_file = get_attached_file($postId);
$fileName = basename($upload_file);

BatchManager::instance()->setCurrentFile('storage', $fileName);
BatchManager::instance()->setCurrent('storage', $i);

Command::Info("%w[%C{$i}%w of %C{$query->post_count}%w] %NImporting %Y$fileName%N %w(Post ID %N$postId%w)%N ... ", $this->debugMode);
$storageTool->processImport($i - 1, $postId, $pd);
if (!$this->debugMode) {
Command::Info("%YDone%N.", true);
}
}

delete_option('ilab_s3_import_status');
BatchManager::instance()->reset('storage');
}
}

Expand Down Expand Up @@ -122,10 +128,12 @@ public function regenerate($args, $assoc_args) {
$query = new \WP_Query($postArgs);

if($query->post_count > 0) {
update_option('ilab_cloud_regenerate_status', true);
update_option('ilab_cloud_regenerate_total_count', $query->post_count);
update_option('ilab_cloud_regenerate_current', 1);
update_option('ilab_cloud_regenerate_should_cancel', false);
BatchManager::instance()->reset('thumbnails');

BatchManager::instance()->setStatus('thumbnails', true);
BatchManager::instance()->setTotalCount('thumbnails', $query->post_count);
BatchManager::instance()->setCurrent('thumbnails', 1);
BatchManager::instance()->setShouldCancel('thumbnails', false);

Command::Info("Total posts found: %Y{$query->post_count}.", true);

Expand All @@ -136,15 +144,15 @@ public function regenerate($args, $assoc_args) {
$upload_file = get_attached_file($postId);
$fileName = basename($upload_file);

update_option('ilab_cloud_regenerate_current_file', $fileName);
update_option('ilab_cloud_regenerate_current', $i);
BatchManager::instance()->setCurrentFile('thumbnails', $fileName);
BatchManager::instance()->setCurrent('thumbnails', $i);

Command::Info("%w[%C{$i}%w of %C{$query->post_count}%w] %NRegenerating thumbnails for %Y$fileName%N %w(%N$postId%w)%N ... ");
$storageTool->regenerateFile($postId);
Command::Info("%YDone%N.", true);
}

delete_option('ilab_cloud_regenerate_status');
BatchManager::instance()->reset('thumbnails');
}

}
Expand Down
Loading

0 comments on commit f1fd408

Please sign in to comment.