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:
parent
bcf9b5c5a7
commit
222b1d2d7b
4 changed files with 58 additions and 21 deletions
|
@ -2,8 +2,11 @@
|
||||||
|
|
||||||
namespace App\Console;
|
namespace App\Console;
|
||||||
|
|
||||||
|
use App\Models\CeleryTask;
|
||||||
|
use Celery\Celery;
|
||||||
use Illuminate\Console\Scheduling\Schedule;
|
use Illuminate\Console\Scheduling\Schedule;
|
||||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class Kernel extends ConsoleKernel
|
class Kernel extends ConsoleKernel
|
||||||
{
|
{
|
||||||
|
@ -15,6 +18,26 @@ class Kernel extends ConsoleKernel
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('inspire')->hourly();
|
||||||
$schedule->command('telescope:prune --hours=48')->daily();
|
$schedule->command('telescope:prune --hours=48')->daily();
|
||||||
$schedule->command('app:create-show-schedule')->everyMinute();
|
$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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,6 +10,7 @@ use App\Models\TrackType;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class FileController extends Controller
|
class FileController extends Controller
|
||||||
|
@ -57,7 +58,11 @@ class FileController extends Controller
|
||||||
throw new \Exception("You must be logged in");
|
throw new \Exception("You must be logged in");
|
||||||
}
|
}
|
||||||
//ToDo: check how to work in Legacy, getting user in this way is quite horrible
|
//ToDo: check how to work in Legacy, getting user in this way is quite horrible
|
||||||
$user = User::where('type','=','P')->orderBy('id','ASC')->first();
|
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
|
//Mime type list: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
|
||||||
|
|
|
@ -47,18 +47,19 @@ class PodcastEpisodeController extends Controller
|
||||||
'episode_description' => htmlentities($request->episode['description']),
|
'episode_description' => htmlentities($request->episode['description']),
|
||||||
])->save();
|
])->save();
|
||||||
|
|
||||||
$brokerTaskId = $this->downloadPodcastEpisode($request, $podcastEpisode);
|
$brokerTask = $this->downloadPodcastEpisode($request, $podcastEpisode);
|
||||||
|
|
||||||
$ref = new ThirdPartyTrackReference();
|
$ref = new ThirdPartyTrackReference();
|
||||||
$ref->fill([
|
$ref->fill([
|
||||||
'service' => 'podcast',
|
'service' => 'podcast',
|
||||||
'foreign_id' => $podcastEpisode->id,
|
'foreign_id' => $podcastEpisode->id,
|
||||||
|
'file_id' => null
|
||||||
])->save();
|
])->save();
|
||||||
|
|
||||||
$task = new CeleryTask();
|
$task = new CeleryTask();
|
||||||
$timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
|
$timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
|
||||||
$task->fill([
|
$task->fill([
|
||||||
'task_id' => $brokerTaskId,
|
'task_id' => $brokerTask->task_id,
|
||||||
'track_reference' => $ref->id,
|
'track_reference' => $ref->id,
|
||||||
'name' => 'podcast-download',
|
'name' => 'podcast-download',
|
||||||
'dispatch_time' => new DateTime('now', $timezone),
|
'dispatch_time' => new DateTime('now', $timezone),
|
||||||
|
@ -75,26 +76,30 @@ class PodcastEpisodeController extends Controller
|
||||||
public function test(Request $request) {
|
public function test(Request $request) {
|
||||||
|
|
||||||
if(isset($request->file)) {
|
if(isset($request->file)) {
|
||||||
$file = (new FileController())->store($request);
|
try {
|
||||||
|
$file = (new FileController())->store($request);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
}
|
||||||
$file = json_decode($file);
|
$file = json_decode($file);
|
||||||
|
|
||||||
$episode = PodcastEpisode::where('file_id','=',null)
|
// $episode = PodcastEpisode::where('file_id','=',null)
|
||||||
->where('episode_title','=', $file->track_title)->firstOrFail();
|
// ->where('episode_title','=', $file->track_title)->firstOrFail();
|
||||||
|
//
|
||||||
$task = $episode->third_party_track_reference->celery_task;
|
// $task = $episode->third_party_track_reference->celery_task;
|
||||||
$task->fill([
|
// $task->fill([
|
||||||
'status' => 'SUCCESS'
|
// 'status' => 'SUCCESS'
|
||||||
])->save();
|
// ])->save();
|
||||||
|
//
|
||||||
$ref = $episode->third_party_track_reference;
|
// $ref = $episode->third_party_track_reference;
|
||||||
$timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
|
// $timezone = new DateTimeZone(getenv('APP_TIMEZONE'));
|
||||||
$ref->fill([
|
// $ref->fill([
|
||||||
'file_id' => $file->id,
|
// 'file_id' => $file->id,
|
||||||
'upload_time' => new DateTime('now', $timezone),
|
// 'upload_time' => new DateTime('now', $timezone),
|
||||||
'status' => 'SUCCESS'
|
// 'status' => 'SUCCESS'
|
||||||
])->save();
|
// ])->save();
|
||||||
|
//
|
||||||
$episode->fill(['file_id' => $file->id])->save();
|
// $episode->fill(['file_id' => $file->id])->save();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,4 +20,8 @@ class CeleryTask extends Model
|
||||||
'dispatch_time',
|
'dispatch_time',
|
||||||
'status'
|
'status'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function aThirdPartyTrackReferences() {
|
||||||
|
return $this->hasOne(ThirdPartyTrackReference::class, 'id', 'track_reference');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue