fix (be podcast): trying to retreive file and podcast data to update third party track references and celery tasks tables

This commit is contained in:
Marco Cavalli 2025-07-10 18:06:52 +02:00
parent bcf9b5c5a7
commit 222b1d2d7b
4 changed files with 58 additions and 21 deletions

View file

@ -2,8 +2,11 @@
namespace App\Console;
use App\Models\CeleryTask;
use Celery\Celery;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Log;
class Kernel extends ConsoleKernel
{
@ -15,6 +18,26 @@ class Kernel extends ConsoleKernel
// $schedule->command('inspire')->hourly();
$schedule->command('telescope:prune --hours=48')->daily();
$schedule->command('app:create-show-schedule')->everyMinute();
$schedule->call(function () {
$tasks = CeleryTask::where('status','=','PENDING')->with('aThirdPartyTrackReferences')->get();
if ($tasks->count() > 0) {
foreach ($tasks as $task) {
$queue = 'celeryresults.'.$task;
$c = new Celery(
config('rabbitmq.host'),
config('rabbitmq.user'),
config('rabbitmq.password'),
config('rabbitmq.vhost'),
'celeryresults',
$queue
);
$message = $c->getAsyncResultMessage($task->name, $task->task_id, ['x-expires' => 900000]);
Log::debug($queue);
Log::debug($task->task_id.': '.json_encode($message));
}
}
})->everySecond();
}
/**

View file

@ -10,6 +10,7 @@ use App\Models\TrackType;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
class FileController extends Controller
@ -57,7 +58,11 @@ class FileController extends Controller
throw new \Exception("You must be logged in");
}
//ToDo: check how to work in Legacy, getting user in this way is quite horrible
try {
$user = User::where('type','=','P')->orderBy('id','ASC')->first();
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
//Mime type list: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

View file

@ -47,18 +47,19 @@ class PodcastEpisodeController extends Controller
'episode_description' => htmlentities($request->episode['description']),
])->save();
$brokerTaskId = $this->downloadPodcastEpisode($request, $podcastEpisode);
$brokerTask = $this->downloadPodcastEpisode($request, $podcastEpisode);
$ref = new ThirdPartyTrackReference();
$ref->fill([
'service' => 'podcast',
'foreign_id' => $podcastEpisode->id,
'file_id' => null
])->save();
$task = new CeleryTask();
$timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
$task->fill([
'task_id' => $brokerTaskId,
'task_id' => $brokerTask->task_id,
'track_reference' => $ref->id,
'name' => 'podcast-download',
'dispatch_time' => new DateTime('now', $timezone),
@ -75,26 +76,30 @@ class PodcastEpisodeController extends Controller
public function test(Request $request) {
if(isset($request->file)) {
try {
$file = (new FileController())->store($request);
} catch (\Exception $e) {
Log::error($e->getMessage());
}
$file = json_decode($file);
$episode = PodcastEpisode::where('file_id','=',null)
->where('episode_title','=', $file->track_title)->firstOrFail();
$task = $episode->third_party_track_reference->celery_task;
$task->fill([
'status' => 'SUCCESS'
])->save();
$ref = $episode->third_party_track_reference;
$timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
$ref->fill([
'file_id' => $file->id,
'upload_time' => new DateTime('now', $timezone),
'status' => 'SUCCESS'
])->save();
$episode->fill(['file_id' => $file->id])->save();
// $episode = PodcastEpisode::where('file_id','=',null)
// ->where('episode_title','=', $file->track_title)->firstOrFail();
//
// $task = $episode->third_party_track_reference->celery_task;
// $task->fill([
// 'status' => 'SUCCESS'
// ])->save();
//
// $ref = $episode->third_party_track_reference;
// $timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
// $ref->fill([
// 'file_id' => $file->id,
// 'upload_time' => new DateTime('now', $timezone),
// 'status' => 'SUCCESS'
// ])->save();
//
// $episode->fill(['file_id' => $file->id])->save();
}

View file

@ -20,4 +20,8 @@ class CeleryTask extends Model
'dispatch_time',
'status'
];
public function aThirdPartyTrackReferences() {
return $this->hasOne(ThirdPartyTrackReference::class, 'id', 'track_reference');
}
}