From 66f0c7c2d52187853613e098aafa4060d98e6604 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Wed, 2 Jul 2025 21:10:35 +0200 Subject: [PATCH] Run commands at boot --- app/Jobs/SyncChannelPostsJob.php | 12 ++++++++++++ docker/entrypoint.sh | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/Jobs/SyncChannelPostsJob.php b/app/Jobs/SyncChannelPostsJob.php index d787fa0..014934d 100644 --- a/app/Jobs/SyncChannelPostsJob.php +++ b/app/Jobs/SyncChannelPostsJob.php @@ -22,6 +22,18 @@ public function __construct( $this->onQueue('lemmy-posts'); } + public static function dispatchForLemmy(): void + { + $communityId = config('lemmy.community_id'); + $communityName = config('lemmy.community'); + + if ($communityId && $communityName) { + self::dispatch(PlatformEnum::LEMMY, (string) $communityId, $communityName); + } else { + logger()->warning('Cannot dispatch Lemmy sync job: missing community configuration'); + } + } + public function handle(): void { if ($this->platform === PlatformEnum::LEMMY) { diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index de00dd8..efc7cbd 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -44,6 +44,12 @@ elif [ "$1" = "queue" ]; then echo "All migrations completed." echo "Waiting for database to stabilize..." sleep 5 + + echo "Dispatching initial sync job..." + php artisan tinker --execute="App\\Jobs\\SyncChannelPostsJob::dispatchForLemmy();" + + echo "Fetching initial articles..." + php artisan article:refresh fi # Execute the command based on the argument @@ -54,7 +60,7 @@ case "$1" in ;; "queue") echo "Starting queue worker..." - exec php artisan queue:work --tries=3 + exec php artisan queue:work --tries=3 --queue=lemmy-posts,default ;; *) echo "Usage: $0 {web|queue}"