From b1e4edad3b314796f9f9eb6999a0cb433f7f88d5 Mon Sep 17 00:00:00 2001 From: drkthunder02 Date: Sun, 30 May 2021 17:50:54 +0900 Subject: [PATCH] import moons --- .../Commands/Files/ImportAllianceMoons.php | 8 +- app/Jobs/Middleware/EveMailLimiter.php | 169 ++++++++++++++++++ app/Models/MiningTax/RentalInvoice.php | 10 -- app/Models/MiningTax/RentalLedger.php | 10 -- app/Models/MiningTax/RentalPayment.php | 10 -- app/Models/MiningTax/RentalStructure.php | 10 -- 6 files changed, 175 insertions(+), 42 deletions(-) create mode 100644 app/Jobs/Middleware/EveMailLimiter.php delete mode 100644 app/Models/MiningTax/RentalInvoice.php delete mode 100644 app/Models/MiningTax/RentalLedger.php delete mode 100644 app/Models/MiningTax/RentalPayment.php delete mode 100644 app/Models/MiningTax/RentalStructure.php diff --git a/app/Console/Commands/Files/ImportAllianceMoons.php b/app/Console/Commands/Files/ImportAllianceMoons.php index 812d56027..6c2a54008 100644 --- a/app/Console/Commands/Files/ImportAllianceMoons.php +++ b/app/Console/Commands/Files/ImportAllianceMoons.php @@ -65,9 +65,13 @@ class ImportAllianceMoons extends Command //Create the file handler $data = Storage::get('public/alliance_moons.txt'); //Split the string into separate arrays based on the line - $data = preg_split("/\n\t/", $data); + $data = preg_split("/\n/", $data); + + foreach($i = 0; $i < sizeof($data); $i++) { + $lineData = preg_split("/\t/", $data[$i]); + var_dump($lineData); + } - var_dump($data); dd(); } } diff --git a/app/Jobs/Middleware/EveMailLimiter.php b/app/Jobs/Middleware/EveMailLimiter.php new file mode 100644 index 000000000..67f9e0d6c --- /dev/null +++ b/app/Jobs/Middleware/EveMailLimiter.php @@ -0,0 +1,169 @@ +key($calledByClass); + } + + /** + * @param bool|\Closure $enabled + * + * @return $this + */ + public function enabled($enabled = true) + { + $this->enabled = $enabled; + + return $this; + } + + public function connectionName(string $connectionName = 'redis') + { + $this->connectionName = $connectionName; + + return $this; + } + + public function key(string $key) + { + $this->key = $key; + + return $this; + } + + public function timespanInSeconds(int $timespanInSeconds) + { + $this->timeSpanInSeconds = $timespanInSeconds; + + return $this; + } + + public function allow(int $allowedNumberOfJobsInTimeSpan = 4) + { + $this->allowedNumberOfJobsInTimeSpan = $allowedNumberOfJobsInTimeSpan; + + return $this; + } + + public function everySecond(int $timespanInSeconds = 1) + { + $this->timeSpanInSeconds = $timespanInSeconds; + + return $this; + } + + public function everySeconds(int $timespanInSeconds = 60) + { + return $this->everySecond($timespanInSeconds); + } + + public function everyMinute(int $timespanInMinutes = 1) + { + return $this->everySecond($timespanInMinutes * 60); + } + + public function everyMinutes(int $timespanInMinutes) + { + return $this->everySecond($timespanInMinutes * 60); + } + + public function releaseAfterOneSecond() + { + return $this->releaseAfterSeconds(1); + } + + public function releaseAfterSeconds(int $releaseInSeconds) + { + $this->releaseInSeconds = $releaseInSeconds; + + return $this; + } + + public function releaseAfterOneMinute() + { + return $this->releaseAfterMinutes(1); + } + + public function releaseAfterMinutes(int $releaseInMinutes) + { + return $this->releaseAfterSeconds($releaseInMinutes * 60); + } + + public function releaseAfterRandomSeconds(int $min = 1, int $max = 10) + { + $this->releaseRandomSeconds = [$min, $max]; + + return $this; + } + + public function releaseAfterBackoff(int $attemptedCount, int $backoffRate = 2) + { + $releaseAfterSeconds = 0; + $interval = $this->releaseInSeconds; + for ($attempt = 0; $attempt <= $attemptedCount; $attempt++) { + $releaseAfterSeconds += $interval * pow($backoffRate, $attempt); + } + + return $this->releaseAfterSeconds($releaseAfterSeconds); + } + + protected function releaseDuration(): int + { + if (! is_null($this->releaseRandomSeconds)) { + return random_int(...$this->releaseRandomSeconds); + } + + return $this->releaseInSeconds; + } + + public function handle($job, $next) + { + if ($this->enabled instanceof Closure) { + $this->enabled = (bool) $this->enabled(); + } + + if (! $this->enabled) { + return $next($job); + } + + Redis::connection($this->connectionName) + ->throttle($this->key) + ->block(0) + ->allow($this->allowedNumberOfJobsInTimeSpan) + ->every($this->timeSpanInSeconds) + ->then(function () use ($job, $next) { + $next($job); + }, function () use ($job) { + $job->release($this->releaseDuration()); + }); + } +} \ No newline at end of file diff --git a/app/Models/MiningTax/RentalInvoice.php b/app/Models/MiningTax/RentalInvoice.php deleted file mode 100644 index 1e7ea9bf5..000000000 --- a/app/Models/MiningTax/RentalInvoice.php +++ /dev/null @@ -1,10 +0,0 @@ -