-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
david7207
committed
Aug 18, 2019
1 parent
30af7a2
commit 2cfa3d2
Showing
7 changed files
with
89 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace app\Job; | ||
|
||
use app\common\Service\CompressService; | ||
use think\facade\App; | ||
use think\facade\Cache; | ||
|
||
class CompressJob extends JobBase { | ||
public function handle(): void { | ||
|
||
$root = App::getRootPath() . '/public/'; | ||
$redis = Cache::store('redis')->handler(); | ||
$redis->select(9); | ||
$data = $redis->lpop('imgCompress'); | ||
if ($data) { | ||
/** | ||
* @var string $data | ||
*/ | ||
$picInfo = json_decode($data, true); | ||
$source = $root . $picInfo['pathname']; | ||
$percent = 1; #原图压缩,不缩放,但体积大大降低 | ||
//echo $root . $source; | ||
(new CompressService($source, $percent))->compressImg($source); | ||
echo '处理-' . $picInfo['pathname'] . '完成' . PHP_EOL; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace app\Job; | ||
|
||
abstract class JobBase { | ||
protected $data; | ||
|
||
public function __construct(array $data) { | ||
$this->data = $data; | ||
} | ||
|
||
abstract public function handle(): void ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,8 @@ | |
// | Author: yunwuxin <[email protected]> | ||
// +---------------------------------------------------------------------- | ||
|
||
use app\command\Compress; | ||
use app\command\Queue; | ||
|
||
return [ | ||
'compress' => Compress::class | ||
'queue' => Queue::class | ||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace app\command; | ||
|
||
//use think\Cache; | ||
use app\Job\CompressJob; | ||
use app\Job\JobBase; | ||
use think\console\Command; | ||
use think\console\Input; | ||
use think\console\Output; | ||
|
||
class Queue extends Command { | ||
private function getQueueJob(): array { | ||
return [ | ||
[ | ||
'class' => CompressJob::class, | ||
'data' => [] | ||
] | ||
]; | ||
} | ||
|
||
protected function configure() { | ||
// 指令配置 | ||
$this->setName('queue'); | ||
// 设置参数 | ||
|
||
} | ||
|
||
protected function execute(Input $input, Output $output) { | ||
// 指令输出 | ||
//$output->writeln('compress'); | ||
while (true) { | ||
foreach ($this->getQueueJob() as $job) { | ||
$class = new $job['class']($job['data']); | ||
/** | ||
* @var JobBase $class | ||
*/ | ||
$class->handle(); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters