From 283f70c3830ebfbbaedfe1d96b91b6aa933f2a99 Mon Sep 17 00:00:00 2001 From: Bartosz Juraszewski Date: Mon, 22 Apr 2024 15:22:50 +0200 Subject: [PATCH] Changed daily sending to hourly sending, added builtin cron --- app/Http/Controllers/ConfigController.php | 10 ++--- app/Http/Requests/ConfigUpdateRequest.php | 2 +- app/Models/Api.php | 2 +- app/Services/SendService.php | 4 +- .../2023_05_24_093342_update_token_length.php | 22 +++++++---- ..._145042_update_send_timeframe_to_hours.php | 37 +++++++++++++++++++ docker/Dockerfile-prod | 6 +++ 7 files changed, 66 insertions(+), 17 deletions(-) mode change 100644 => 100755 app/Http/Requests/ConfigUpdateRequest.php mode change 100644 => 100755 database/migrations/2023_05_24_093342_update_token_length.php create mode 100755 database/migrations/2024_04_22_145042_update_send_timeframe_to_hours.php mode change 100644 => 100755 docker/Dockerfile-prod diff --git a/app/Http/Controllers/ConfigController.php b/app/Http/Controllers/ConfigController.php index ea7914f..ea38383 100755 --- a/app/Http/Controllers/ConfigController.php +++ b/app/Http/Controllers/ConfigController.php @@ -36,11 +36,11 @@ public function show(Request $request): JsonResponse 'required' => true, ], [ - 'key' => 'orders_from_days', - 'label' => 'Liczba dni po których zostanie wysłane powiadomienie', + 'key' => 'orders_from_hours', + 'label' => 'Liczba godzin po których zostanie wysłane powiadomienie', 'type' => 'number', - 'default_value' => $api->orders_from_days, - 'value' => $api->orders_from_days, + 'default_value' => $api->orders_from_hours, + 'value' => $api->orders_from_hours, 'required' => true, ], ]); @@ -54,7 +54,7 @@ public function store(ConfigUpdateRequest $request): HttpResponse $api->update([ 'name' => $request->input('name'), 'payment_url' => $request->input('payment_url'), - 'orders_from_days' => $request->input('orders_from_days'), + 'orders_from_hours' => $request->input('orders_from_hours'), ]); return Response::noContent(); diff --git a/app/Http/Requests/ConfigUpdateRequest.php b/app/Http/Requests/ConfigUpdateRequest.php old mode 100644 new mode 100755 index fe0c3d4..bef77e6 --- a/app/Http/Requests/ConfigUpdateRequest.php +++ b/app/Http/Requests/ConfigUpdateRequest.php @@ -18,7 +18,7 @@ public function rules(): array return [ 'name' => ['required', 'string', 'max:200'], 'payment_url' => ['required', 'string', 'max:400'], - 'orders_from_days' => ['required', 'integer', 'gte:0', 'lte:64'], + 'orders_from_hours' => ['required', 'integer', 'gte:0', 'lte:1500'], ]; } } diff --git a/app/Models/Api.php b/app/Models/Api.php index 52d3d51..d74b758 100755 --- a/app/Models/Api.php +++ b/app/Models/Api.php @@ -21,6 +21,6 @@ final class Api extends Model 'uninstall_token', 'payment_url', - 'orders_from_days', + 'orders_from_hours', ]; } diff --git a/app/Services/SendService.php b/app/Services/SendService.php index 23b10a4..7e8976d 100755 --- a/app/Services/SendService.php +++ b/app/Services/SendService.php @@ -29,8 +29,8 @@ public function __construct( */ public function sendForApi(Api $api): int { - $from = Carbon::now()->subDays($api->orders_from_days)->startOfDay()->format('Y-m-d'); - $to = Carbon::now()->subDays($api->orders_from_days)->endOfDay()->format('Y-m-d'); + $from = Carbon::now()->startOfHour($api->orders_from_hours)->subHours()->format('Y-m-d H:i:s'); + $to = Carbon::now()->endOfHour($api->orders_from_hours)->subHours()->format('Y-m-d H:i:s'); $lastPage = 1; // Get at least once $emailsSent = 0; diff --git a/database/migrations/2023_05_24_093342_update_token_length.php b/database/migrations/2023_05_24_093342_update_token_length.php old mode 100644 new mode 100755 index a1960d6..6b85992 --- a/database/migrations/2023_05_24_093342_update_token_length.php +++ b/database/migrations/2023_05_24_093342_update_token_length.php @@ -1,21 +1,22 @@ text('licence_key')->nullable()->change(); - $table->text("integration_token")->change(); - $table->text("refresh_token")->change(); - $table->string("uninstall_token", 255)->change(); + $table->text('integration_token')->change(); + $table->text('refresh_token')->change(); + $table->string('uninstall_token', 255)->change(); }); } @@ -24,6 +25,11 @@ public function up(): void */ public function down(): void { - // + Schema::table('apis', function (Blueprint $table): void { + $table->string('licence_key')->nullable()->change(); + $table->string('integration_token', 1000)->change(); + $table->string('refresh_token', 1000)->change(); + $table->string('uninstall_token', 128)->change(); + }); } -} +}; diff --git a/database/migrations/2024_04_22_145042_update_send_timeframe_to_hours.php b/database/migrations/2024_04_22_145042_update_send_timeframe_to_hours.php new file mode 100755 index 0000000..c3b6f81 --- /dev/null +++ b/database/migrations/2024_04_22_145042_update_send_timeframe_to_hours.php @@ -0,0 +1,37 @@ +unsignedInteger('orders_from_days')->default(48)->change(); + }); + + Schema::table('apis', function (Blueprint $table): void { + $table->renameColumn('orders_from_days', 'orders_from_hours'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('apis', function (Blueprint $table): void { + $table->unsignedInteger('orders_from_hours')->default(2)->change(); + }); + + Schema::table('apis', function (Blueprint $table): void { + $table->renameColumn('orders_from_hours', 'orders_from_days'); + }); + } +}; diff --git a/docker/Dockerfile-prod b/docker/Dockerfile-prod old mode 100644 new mode 100755 index 685ad5c..8afe9a4 --- a/docker/Dockerfile-prod +++ b/docker/Dockerfile-prod @@ -1,4 +1,10 @@ FROM escolasoft/php:8.2-heseya +RUN apt update && apt install cron -y +RUN echo "5 * * * * root $( which php ) /var/www/html/artisan send" >> /etc/cron.d/feed + COPY . ./ RUN composer i +RUN chown -R www-data:www-data /var/www/html + +CMD printenv > /etc/environment && service cron start && apache2-foreground