Skip to content

Commit

Permalink
fix microtime to datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
leocarmo committed Nov 23, 2021
1 parent 53f8c3e commit b026550
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Adapters/SwooleTableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function createTable()
{
$table = new Table(12);
$table->column('count', Table::TYPE_INT, 4);
$table->column('until_date', Table::TYPE_FLOAT);
$table->column('until_date', Table::TYPE_INT, 4);
$table->create();
return $table;
}
Expand Down Expand Up @@ -61,7 +61,7 @@ public function reachRateLimit(string $service, int $failureRateThreshold): bool

$failures = $this->table->get($key);

if (microtime(true) > $failures['until_date']) {
if ((new \DateTime('now'))->getTimestamp() > $failures['until_date']) {
$this->table->delete("{$service}-failures");
return false;
}
Expand Down Expand Up @@ -93,7 +93,9 @@ public function isOpen(string $service): bool

$open = $this->table->get($key, 'until_date');

return (microtime(true) < $open);
return (
(new \DateTime('now'))->getTimestamp() < $open
);
}

/**
Expand All @@ -110,7 +112,9 @@ public function isHalfOpen(string $service): bool

$halfOpen = $this->table->get($key, 'until_date');

return (microtime(true) < $halfOpen);
return (
(new \DateTime('now'))->getTimestamp() < $halfOpen
);
}

/**
Expand Down

0 comments on commit b026550

Please sign in to comment.