Skip to content

Commit

Permalink
Merge pull request #115 from cego/lejo/remove-nbj-stopwatch
Browse files Browse the repository at this point in the history
Remove nbj/stopwatch
  • Loading branch information
LauJosefsen authored Nov 13, 2024
2 parents 5a5480b + f9cfe8e commit c1253ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"ext-pcntl": "*",
"ext-curl": "*",
"nesbot/carbon": "^2.17|^3.0",
"nbj/stopwatch": "^0.0.5",
"illuminate/view": "^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/http": "^7.0|^8.0|^9.0|^10.0|^11.0",
"illuminate/routing": "^7.0|^8.0|^9.0|^10.0|^11.0",
Expand Down
13 changes: 7 additions & 6 deletions src/RequestInsurance/RequestInsuranceWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Exception;
use Throwable;
use Carbon\Carbon;
use Nbj\Stopwatch;
use Carbon\CarbonImmutable;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -74,12 +73,14 @@ public function run(bool $runOnlyOnce = false): void
DB::reconnect();
}

$executionTime = Stopwatch::time(function () {
$this->processRequestInsurances();
$this->atMostOnceEverySecond(fn () => $this->readyWaitingRequestInsurances());
});
$start = hrtime(true);

$waitTime = (int) max(Config::get('request-insurance.microSecondsToWait') - $executionTime->microseconds(), 0);
$this->processRequestInsurances();
$this->atMostOnceEverySecond(fn () => $this->readyWaitingRequestInsurances());

$executionTimeNs = hrtime(true) - $start;

$waitTime = (int) max(Config::get('request-insurance.microSecondsToWait') - ($executionTimeNs / 1000), 0);

usleep($waitTime);
} catch (Throwable $throwable) {
Expand Down

0 comments on commit c1253ba

Please sign in to comment.