Commit d8e1d403 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat(import): run podcast imports' processes asynchronously using tasks

- use codeigniter4/tasks project to handle cron tasks
- use yassinedoghri/podcast-feed project to parse feeds for imports
parent 85505d4b
Loading
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -43,23 +43,24 @@ class Autoload extends AutoloadConfig
     */
    public $psr4 = [
        APP_NAMESPACE             => APPPATH,
        'Config'                  => APPPATH . 'Config/',
        'Modules'                 => ROOTPATH . 'modules/',
        'Modules\Admin'           => ROOTPATH . 'modules/Admin/',
        'Modules\Auth'            => ROOTPATH . 'modules/Auth/',
        'Modules\Analytics'       => ROOTPATH . 'modules/Analytics/',
        'Modules\Install'         => ROOTPATH . 'modules/Install/',
        'Modules\Update'          => ROOTPATH . 'modules/Update/',
        'Modules\Api\Rest\V1'     => ROOTPATH . 'modules/Api/Rest/V1',
        'Modules\Auth'            => ROOTPATH . 'modules/Auth/',
        'Modules\Fediverse'       => ROOTPATH . 'modules/Fediverse/',
        'Modules\Install'         => ROOTPATH . 'modules/Install/',
        'Modules\Media'           => ROOTPATH . 'modules/Media/',
        'Modules\WebSub'          => ROOTPATH . 'modules/WebSub/',
        'Modules\Api\Rest\V1'     => ROOTPATH . 'modules/Api/Rest/V1',
        'Modules\MediaClipper'    => ROOTPATH . 'modules/MediaClipper/',
        'Modules\PodcastImport'   => ROOTPATH . 'modules/PodcastImport/',
        'Modules\PremiumPodcasts' => ROOTPATH . 'modules/PremiumPodcasts/',
        'Config'                  => APPPATH . 'Config/',
        'Modules\Update'          => ROOTPATH . 'modules/Update/',
        'Modules\WebSub'          => ROOTPATH . 'modules/WebSub/',
        'Themes'                  => ROOTPATH . 'themes',
        'ViewComponents'          => APPPATH . 'Libraries/ViewComponents/',
        'ViewThemes'              => APPPATH . 'Libraries/ViewThemes/',
        'MediaClipper'            => APPPATH . 'Libraries/MediaClipper/',
        'Vite'                    => APPPATH . 'Libraries/Vite/',
        'Themes'                  => ROOTPATH . 'themes',
    ];

    /**

app/Config/Tasks.php

0 → 100644
+55 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Config;

use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Tasks\Scheduler;

class Tasks extends BaseConfig
{
    /**
     * --------------------------------------------------------------------------
     * Should performance metrics be logged
     * --------------------------------------------------------------------------
     *
     * If true, will log the time it takes for each task to run.
     * Requires the settings table to have been created previously.
     */
    public bool $logPerformance = false;

    /**
     * --------------------------------------------------------------------------
     * Maximum performance logs
     * --------------------------------------------------------------------------
     *
     * The maximum number of logs that should be saved per Task.
     * Lower numbers reduced the amount of database required to
     * store the logs.
     */
    public int $maxLogsPerTask = 10;

    /**
     * Register any tasks within this method for the application.
     * Called by the TaskRunner.
     */
    public function init(Scheduler $schedule): void
    {
        $schedule->command('fediverse:broadcast')
            ->everyMinute()
            ->named('fediverse-broadcast');

        $schedule->command('websub:publish')
            ->everyMinute()
            ->named('websub-publish');

        $schedule->command('video-clips:generate')
            ->everyMinute()
            ->named('video-clips-generate');

        $schedule->command('podcast:import')
            ->everyMinute()
            ->named('podcast-import');
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -89,11 +89,11 @@ class WebmanifestController extends Controller

        $webmanifest = [
            'name'             => esc($podcast->title),
            'short_name'       => '@' . esc($podcast->handle),
            'short_name'       => $podcast->at_handle,
            'description'      => $podcast->description,
            'lang'             => $podcast->language_code,
            'start_url'        => $podcast->link,
            'scope'            => '/@' . esc($podcast->handle),
            'scope'            => '/' . $podcast->at_handle,
            'display'          => 'standalone',
            'orientation'      => 'portrait',
            'theme_color'      => self::THEME_COLORS[service('settings')->get('App.theme')]['theme'],
+3 −3
Original line number Diff line number Diff line
@@ -129,15 +129,15 @@ class BaseClip extends Entity
            $this->getMedia()
                ->setFile($file);
            $this->getMedia()
                ->updated_by = (int) user_id();
                ->updated_by = $this->attributes['updated_by'];
            (new MediaModel('audio'))->updateMedia($this->getMedia());
        } else {
            $media = new Audio([
                'file_key'      => $fileKey,
                'language_code' => $this->getPodcast()
->language_code,
                'uploaded_by' => $this->attributes['created_by'],
                'updated_by'  => $this->attributes['created_by'],
                'uploaded_by' => $this->attributes['updated_by'],
                'updated_by'  => $this->attributes['updated_by'],
            ]);
            $media->setFile($file);

+12 −12
Original line number Diff line number Diff line
@@ -188,15 +188,15 @@ class Episode extends Entity
            $this->getCover()
                ->setFile($file);
            $this->getCover()
                ->updated_by = (int) user_id();
                ->updated_by = $this->attributes['updated_by'];
            (new MediaModel('image'))->updateMedia($this->getCover());
        } else {
            $cover = new Image([
                'file_key' => 'podcasts/' . $this->getPodcast()->handle . '/' . $this->attributes['slug'] . '.' . $file->getExtension(),
                'sizes'    => config('Images')
->podcastCoverSizes,
                'uploaded_by' => user_id(),
                'updated_by'  => user_id(),
                'uploaded_by' => $this->attributes['updated_by'],
                'updated_by'  => $this->attributes['updated_by'],
            ]);
            $cover->setFile($file);

@@ -234,7 +234,7 @@ class Episode extends Entity
            $this->getAudio()
                ->setFile($file);
            $this->getAudio()
                ->updated_by = (int) user_id();
                ->updated_by = $this->attributes['updated_by'];
            (new MediaModel('audio'))->updateMedia($this->getAudio());
        } else {
            $audio = new Audio([
@@ -244,8 +244,8 @@ class Episode extends Entity
                ) . '.' . $file->getExtension(),
                'language_code' => $this->getPodcast()
                    ->language_code,
                'uploaded_by' => user_id(),
                'updated_by'  => user_id(),
                'uploaded_by' => $this->attributes['updated_by'],
                'updated_by'  => $this->attributes['updated_by'],
            ]);
            $audio->setFile($file);

@@ -274,15 +274,15 @@ class Episode extends Entity
            $this->getTranscript()
                ->setFile($file);
            $this->getTranscript()
                ->updated_by = (int) user_id();
                ->updated_by = $this->attributes['updated_by'];
            (new MediaModel('transcript'))->updateMedia($this->getTranscript());
        } else {
            $transcript = new Transcript([
                'file_key'      => 'podcasts/' . $this->getPodcast()->handle . '/' . $this->attributes['slug'] . '-transcript.' . $file->getExtension(),
                'language_code' => $this->getPodcast()
->language_code,
                'uploaded_by' => user_id(),
                'updated_by'  => user_id(),
                'uploaded_by' => $this->attributes['updated_by'],
                'updated_by'  => $this->attributes['updated_by'],
            ]);
            $transcript->setFile($file);

@@ -311,15 +311,15 @@ class Episode extends Entity
            $this->getChapters()
                ->setFile($file);
            $this->getChapters()
                ->updated_by = (int) user_id();
                ->updated_by = $this->attributes['updated_by'];
            (new MediaModel('chapters'))->updateMedia($this->getChapters());
        } else {
            $chapters = new Chapters([
                'file_key'      => 'podcasts/' . $this->getPodcast()->handle . '/' . $this->attributes['slug'] . '-chapters' . '.' . $file->getExtension(),
                'language_code' => $this->getPodcast()
->language_code,
                'uploaded_by' => user_id(),
                'updated_by'  => user_id(),
                'uploaded_by' => $this->attributes['updated_by'],
                'updated_by'  => $this->attributes['updated_by'],
            ]);
            $chapters->setFile($file);

Loading