Skip to content

Commit

Permalink
Changed daily sending to hourly sending, added builtin cron
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz Juraszewski committed Apr 22, 2024
1 parent 5862016 commit 283f70c
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 17 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/ConfigUpdateRequest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
}
2 changes: 1 addition & 1 deletion app/Models/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ final class Api extends Model
'uninstall_token',

'payment_url',
'orders_from_days',
'orders_from_hours',
];
}
4 changes: 2 additions & 2 deletions app/Services/SendService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 14 additions & 8 deletions database/migrations/2023_05_24_093342_update_token_length.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateTokenLength extends Migration
{
return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('apis', function (Blueprint $table) {
Schema::table('apis', function (Blueprint $table): void {
$table->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();
});
}

Expand All @@ -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();
});
}
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('apis', function (Blueprint $table): void {
$table->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');
});
}
};
6 changes: 6 additions & 0 deletions docker/Dockerfile-prod
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 283f70c

Please sign in to comment.