Skip to content

Commit

Permalink
Migrating in the lock check from version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Baker committed Feb 6, 2017
1 parent 94fa592 commit 4870aa0
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function skipMultiserver()
->delete();

// Attempt to acquire the lock
$gotLock = true;
try {
DB::connection($this->connection)
->table($this->lock_table)
Expand All @@ -86,23 +87,10 @@ public function skipMultiserver()
]);
} catch (\PDOException $e) {
// Catch the PDOException to fail silently because the query builder does not support INSERT IGNORE
$gotLock = false;
}

// If the mutex already exists in the table, the above query will fail silently.
// Now we will perform a select to see if we got the lock or not.
$lock = DB::connection($this->connection)
->table($this->lock_table)
->where('mutex', $this->key)
->select('lock')
->get();

if ($lock[0]->lock == $this->server_id) {
// We got the lock
return false;
}

// Someone else has the lock
return true;
return $gotLock === false;
}

/**
Expand Down

0 comments on commit 4870aa0

Please sign in to comment.