gengx
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Docker 内短剧接力进程。
|
||||
*
|
||||
* H3 的下一镜头必须等上一镜头落盘并提取尾帧后才能提交,因此由这个进程
|
||||
* 持续触发同一套状态接口。页面关闭后,长视频仍会按顺序继续生成。
|
||||
*/
|
||||
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$app = new think\App();
|
||||
$app->initialize();
|
||||
|
||||
use app\model\VideoProject;
|
||||
use app\service\JwtService;
|
||||
|
||||
set_time_limit(0);
|
||||
|
||||
$internalBaseUrl = rtrim((string) (getenv('SHORT_DRAMA_INTERNAL_URL') ?: 'http://web'), '/');
|
||||
if (!preg_match('#^https?://#i', $internalBaseUrl)) {
|
||||
fwrite(STDERR, "[short-drama-worker] SHORT_DRAMA_INTERNAL_URL 必须使用 http 或 https\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
$projects = VideoProject::where('status', 'generating')
|
||||
->order('updated_at')
|
||||
->limit(30)
|
||||
->select();
|
||||
|
||||
foreach ($projects as $project) {
|
||||
$token = JwtService::generateToken(['user_id' => (int) $project->user_id]);
|
||||
$url = $internalBaseUrl . '/api/short-drama/projects/' . (int) $project->id . '/status';
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_HTTPGET => true,
|
||||
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . $token],
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_TIMEOUT => 25,
|
||||
CURLOPT_CONNECTTIMEOUT => 3,
|
||||
]);
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
} catch (Throwable $error) {
|
||||
fwrite(STDERR, '[short-drama-worker] ' . $error->getMessage() . "\n");
|
||||
}
|
||||
|
||||
sleep(8);
|
||||
}
|
||||
Reference in New Issue
Block a user