Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
perf(horizon): skip queues for platforms that are disabled (#321)
Maciej Dzierżekca497e1f3c24
diff --git a/app/Enums/SocialAccount/Platform.php b/app/Enums/SocialAccount/Platform.phpindex 1d9d207c8..0ed567840 100644--- a/app/Enums/SocialAccount/Platform.php+++ b/app/Enums/SocialAccount/Platform.php@@ -380,6 +380,18 @@ enum Platform: stringreturn array_map(fn (self $platform) => $platform->queue(), self::cases());}+ /**+ * @return array<string>+ */+ public static function enabledQueues(): array+ {+ return collect(self::cases())+ ->filter(fn (self $platform): bool => $platform->isEnabled())+ ->map(fn (self $platform): string => $platform->queue())+ ->values()+ ->all();+ }+public function instagramGraphBaseUrl(): string{return match ($this) {@@ -390,7 +402,25 @@ enum Platform: stringpublic function isEnabled(): bool{- return config("trypost.platforms.{$this->value}.enabled", true);+ return (bool) config(+ "trypost.platforms.{$this->value}.enabled",+ env(match ($this) {+ self::LinkedIn => 'LINKEDIN_ENABLED',+ self::LinkedInPage => 'LINKEDIN_PAGE_ENABLED',+ self::X => 'X_ENABLED',+ self::TikTok => 'TIKTOK_ENABLED',+ self::YouTube => 'YOUTUBE_ENABLED',+ self::Facebook => 'FACEBOOK_ENABLED',+ self::Instagram => 'INSTAGRAM_ENABLED',+ self::InstagramFacebook => 'INSTAGRAM_FACEBOOK_ENABLED',+ self::Threads => 'THREADS_ENABLED',+ self::Pinterest => 'PINTEREST_ENABLED',+ self::Bluesky => 'BLUESKY_ENABLED',+ self::Mastodon => 'MASTODON_ENABLED',+ self::Telegram => 'TELEGRAM_ENABLED',+ self::Discord => 'DISCORD_ENABLED',+ }, true),+ );}/**diff --git a/config/horizon.php b/config/horizon.phpindex c2e8b3184..f45602ddf 100644--- a/config/horizon.php+++ b/config/horizon.php@@ -228,7 +228,7 @@ return ['social-publishing' => ['connection' => 'redis',- 'queue' => Platform::allQueues(),+ 'queue' => Platform::enabledQueues(),'balance' => 'auto','autoScalingStrategy' => 'time','minProcesses' => 1,diff --git a/tests/Unit/Enums/PlatformTest.php b/tests/Unit/Enums/PlatformTest.phpindex 803756c5c..5b9fc8f70 100644--- a/tests/Unit/Enums/PlatformTest.php+++ b/tests/Unit/Enums/PlatformTest.php@@ -103,17 +103,193 @@ test('platform exposes the correct default token TTL fallback', function () {expect(Platform::Facebook->defaultTokenTtlSeconds())->toBeNull();});-test('platform is enabled by default', function () {- expect(Platform::LinkedIn->isEnabled())->toBeTrue();- expect(Platform::Instagram->isEnabled())->toBeTrue();+test('platform is enabled by default for every platform', function (Platform $platform) {+ expect($platform->isEnabled())->toBeTrue();+})->with([+ Platform::LinkedIn,+ Platform::LinkedInPage,+ Platform::X,+ Platform::TikTok,+ Platform::YouTube,+ Platform::Facebook,+ Platform::Instagram,+ Platform::InstagramFacebook,+ Platform::Threads,+ Platform::Pinterest,+ Platform::Bluesky,+ Platform::Mastodon,+ Platform::Telegram,+ Platform::Discord,+]);++test('each platform can be disabled via config', function (Platform $platform) {+ config(["trypost.platforms.{$platform->value}.enabled" => false]);++ expect($platform->isEnabled())->toBeFalse();+})->with([+ Platform::LinkedIn,+ Platform::LinkedInPage,+ Platform::X,+ Platform::TikTok,+ Platform::YouTube,+ Platform::Facebook,+ Platform::Instagram,+ Platform::InstagramFacebook,+ Platform::Threads,+ Platform::Pinterest,+ Platform::Bluesky,+ Platform::Mastodon,+ Platform::Telegram,+ Platform::Discord,+]);++test('each platform maps to its publishing queue', function (Platform $platform, string $queue) {+ expect($platform->queue())->toBe($queue);+})->with([+ [Platform::LinkedIn, 'social-linkedin'],+ [Platform::LinkedInPage, 'social-linkedin-page'],+ [Platform::X, 'social-x'],+ [Platform::TikTok, 'social-tiktok'],+ [Platform::YouTube, 'social-youtube'],+ [Platform::Facebook, 'social-facebook'],+ [Platform::Instagram, 'social-instagram'],+ [Platform::InstagramFacebook, 'social-instagram-facebook'],+ [Platform::Threads, 'social-threads'],+ [Platform::Pinterest, 'social-pinterest'],+ [Platform::Bluesky, 'social-bluesky'],+ [Platform::Mastodon, 'social-mastodon'],+ [Platform::Telegram, 'social-telegram'],+ [Platform::Discord, 'social-discord'],+]);++test('allQueues lists every platform publishing queue in enum order', function () {+ expect(Platform::allQueues())->toBe([+ 'social-linkedin',+ 'social-linkedin-page',+ 'social-x',+ 'social-tiktok',+ 'social-youtube',+ 'social-facebook',+ 'social-instagram',+ 'social-instagram-facebook',+ 'social-threads',+ 'social-pinterest',+ 'social-bluesky',+ 'social-mastodon',+ 'social-telegram',+ 'social-discord',+ ])->and(Platform::allQueues())->toHaveCount(count(Platform::cases()));});-test('platform can be disabled via config', function () {- config(['trypost.platforms.linkedin.enabled' => false]);+test('enabledQueues matches allQueues when every platform is enabled', function () {+ foreach (Platform::cases() as $platform) {+ config(["trypost.platforms.{$platform->value}.enabled" => true]);+ }- expect(Platform::LinkedIn->isEnabled())->toBeFalse();+ expect(Platform::enabledQueues())->toBe(Platform::allQueues());});+test('disabling a platform removes only its queue from enabledQueues', function (Platform $disabled) {+ foreach (Platform::cases() as $platform) {+ config(["trypost.platforms.{$platform->value}.enabled" => true]);+ }++ config(["trypost.platforms.{$disabled->value}.enabled" => false]);++ $enabledQueues = Platform::enabledQueues();++ expect($enabledQueues)+ ->not->toContain($disabled->queue())+ ->toHaveCount(count(Platform::cases()) - 1);++ foreach (Platform::cases() as $platform) {+ if ($platform === $disabled) {+ continue;+ }++ expect($enabledQueues)->toContain($platform->queue());+ }++ expect(Platform::allQueues())->toContain($disabled->queue());+})->with([+ Platform::LinkedIn,+ Platform::LinkedInPage,+ Platform::X,+ Platform::TikTok,+ Platform::YouTube,+ Platform::Facebook,+ Platform::Instagram,+ Platform::InstagramFacebook,+ Platform::Threads,+ Platform::Pinterest,+ Platform::Bluesky,+ Platform::Mastodon,+ Platform::Telegram,+ Platform::Discord,+]);++test('disabling every platform yields no enabled queues', function () {+ foreach (Platform::cases() as $platform) {+ config(["trypost.platforms.{$platform->value}.enabled" => false]);+ }++ expect(Platform::enabledQueues())->toBe([]);+});++test('enabledQueues is always a subset of allQueues', function () {+ config([+ 'trypost.platforms.linkedin.enabled' => true,+ 'trypost.platforms.linkedin-page.enabled' => false,+ 'trypost.platforms.x.enabled' => false,+ 'trypost.platforms.tiktok.enabled' => true,+ 'trypost.platforms.youtube.enabled' => false,+ 'trypost.platforms.facebook.enabled' => true,+ 'trypost.platforms.instagram.enabled' => false,+ 'trypost.platforms.instagram-facebook.enabled' => true,+ 'trypost.platforms.threads.enabled' => false,+ 'trypost.platforms.pinterest.enabled' => true,+ 'trypost.platforms.bluesky.enabled' => false,+ 'trypost.platforms.mastodon.enabled' => true,+ 'trypost.platforms.telegram.enabled' => false,+ 'trypost.platforms.discord.enabled' => true,+ ]);++ $enabledQueues = Platform::enabledQueues();++ expect($enabledQueues)->toEqual(array_values(array_intersect(Platform::allQueues(), $enabledQueues)))+ ->and(array_diff($enabledQueues, Platform::allQueues()))->toBe([]);+});++test('horizon social publishing queues match enabledQueues', function () {+ expect(config('horizon.defaults.social-publishing.queue'))->toBe(Platform::enabledQueues());+});++test('isEnabled falls back to env when enabled config is missing', function (Platform $platform, string $envKey) {+ $platforms = config('trypost.platforms');+ unset($platforms[$platform->value]['enabled']);+ config(['trypost.platforms' => $platforms]);++ $original = getenv($envKey);+ putenv("{$envKey}=false");++ try {+ expect($platform->isEnabled())->toBeFalse();+ } finally {+ if ($original === false) {+ putenv($envKey);+ } else {+ putenv("{$envKey}={$original}");+ }+ }+})->with([+ [Platform::LinkedIn, 'LINKEDIN_ENABLED'],+ [Platform::LinkedInPage, 'LINKEDIN_PAGE_ENABLED'],+ [Platform::X, 'X_ENABLED'],+ [Platform::InstagramFacebook, 'INSTAGRAM_FACEBOOK_ENABLED'],+ [Platform::Telegram, 'TELEGRAM_ENABLED'],+ [Platform::Discord, 'DISCORD_ENABLED'],+]);+test('linkedin pages and instagram facebook are not directly connectable', function () {expect(Platform::LinkedInPage->isConnectable())->toBeFalse();expect(Platform::LinkedIn->isConnectable())->toBeTrue();