ソースを参照

Set multiple retries with lighter lock & Send 409 in case of deadlock

Bubka 5 ヶ月 前
コミット
c8b5bd32a6

+ 2 - 0
app/Api/v1/Controllers/GroupController.php

@@ -107,6 +107,8 @@ class GroupController extends Controller
             $group->loadCount('twofaccounts');
             $group->loadCount('twofaccounts');
         } catch (ModelNotFoundException $exc) {
         } catch (ModelNotFoundException $exc) {
             abort(404);
             abort(404);
+        } catch (\Throwable $th) {
+            abort(409, 'Conflict');
         }
         }
 
 
         return new GroupResource($group);
         return new GroupResource($group);

+ 2 - 2
app/Services/GroupService.php

@@ -59,7 +59,7 @@ class GroupService
             $ids = is_array($ids) ? $ids : [$ids];
             $ids = is_array($ids) ? $ids : [$ids];
 
 
             DB::transaction(function () use ($group, $ids, $user) {
             DB::transaction(function () use ($group, $ids, $user) {
-                $group        = Group::lockForUpdate()->find($group->id);
+                $group        = Group::sharedLock()->find($group->id);
                 $twofaccounts = TwoFAccount::sharedLock()->find($ids);
                 $twofaccounts = TwoFAccount::sharedLock()->find($ids);
                 
                 
                 if (! $group) {
                 if (! $group) {
@@ -73,7 +73,7 @@ class GroupService
                 $group->twofaccounts()->saveMany($twofaccounts);
                 $group->twofaccounts()->saveMany($twofaccounts);
     
     
                 Log::info(sprintf('Twofaccounts #%s assigned to group %s (ID #%s)', implode(',', $ids), var_export($group->name, true), $group->id));
                 Log::info(sprintf('Twofaccounts #%s assigned to group %s (ID #%s)', implode(',', $ids), var_export($group->name, true), $group->id));
-            });
+            }, 5);
         } else {
         } else {
             Log::info('Cannot find a group to assign the TwoFAccounts to');
             Log::info('Cannot find a group to assign the TwoFAccounts to');
         }
         }