Merge pull request #1019 from keriati/feat/uniqueappupdate

feat: Make app update job unique
This commit is contained in:
KodeStar 2022-11-22 17:05:28 +00:00 committed by GitHub
commit 256160727c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View file

@ -9,6 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
class UpdateApps implements ShouldQueue, ShouldBeUnique class UpdateApps implements ShouldQueue, ShouldBeUnique
@ -41,5 +42,17 @@ class UpdateApps implements ShouldQueue, ShouldBeUnique
Application::getApp($app['appid']); Application::getApp($app['appid']);
sleep(1); sleep(1);
} }
Log::debug('Update of all apps finished!');
Cache::lock('updateApps')->forceRelease();
}
/**
* @return void
*/
public function failed($exception)
{
Cache::lock('updateApps')->forceRelease();
} }
} }

View file

@ -8,6 +8,7 @@ use App\Jobs\UpdateApps;
use App\Setting; use App\Setting;
use App\User; use App\User;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
@ -170,6 +171,12 @@ class AppServiceProvider extends ServiceProvider
*/ */
private function updateApps() private function updateApps()
{ {
UpdateApps::dispatchAfterResponse(); // This lock ensures that the job is not invoked multiple times.
// In 5 minutes all app updates should be finished.
$lock = Cache::lock('updateApps', 5*60);
if ($lock->get()) {
UpdateApps::dispatchAfterResponse();
}
} }
} }

File diff suppressed because one or more lines are too long