Skip to content

Commit ed268e1

Browse files
committed
Add sentry error reporting
1 parent 5f7d04d commit ed268e1

File tree

8 files changed

+633
-19
lines changed

8 files changed

+633
-19
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ SATKER_REKENING="652074285781000"
8080
FONNTE_TOKEN = "your_token"
8181
FONNTE_NUMBER = "your_number"
8282
FONNTE_HOUR = "09.00 WITA"
83+
84+
# SENTRY
85+
SENTRY_LARAVEL_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
86+
SENTRY_TRACES_SAMPLE_RATE=1.0
87+
SENTRY_PROFILES_SAMPLE_RATE=1.0

app/Console/Commands/SendReminder.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
namespace App\Console\Commands;
44

5-
use App\Helpers\Fonnte;
65
use App\Helpers\Helper;
76
use App\Models\DaftarReminder;
8-
use App\Models\UnitKerja;
9-
use App\Models\User;
107
use Illuminate\Console\Command;
118

129
class SendReminder extends Command
@@ -33,18 +30,7 @@ public function handle()
3330
$tanggal = date('Y-m-d');
3431
$reminders = DaftarReminder::with('daftarKegiatan')->where('tanggal', $tanggal)->where('status', '!=', 'sent')->get();
3532
foreach ($reminders as $reminder) {
36-
$kegiatan = $reminder->daftarKegiatan;
37-
$hari = $kegiatan->awal->diffInDays($reminder->tanggal);
38-
$pesan = strtr($kegiatan->pesan, [
39-
'{judul}' => '[Reminder Deadline (H'.$hari.')]',
40-
'{tanggal}' => Helper::terbilangTanggal($kegiatan->awal),
41-
'{kegiatan}' => $kegiatan->kegiatan,
42-
'{pj}' => $kegiatan->daftar_kegiatanable_type == 'App\Models\UnitKerja' ? UnitKerja::find($kegiatan->daftar_kegiatanable_id)->unit : User::find($kegiatan->daftar_kegiatanable_id)->name,
43-
]);
44-
$response = Fonnte::make()->sendWhatsAppMessage($kegiatan->wa_group_id, $pesan);
45-
$reminder->status = $response['data']['process'] ?? 'Gagal';
46-
$reminder->message_id = $response['data']['id'][0];
47-
$reminder->save();
33+
Helper::sendReminder($reminder);
4834
}
4935
}
5036
}

app/Helpers/Helper.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,4 +1751,20 @@ public static function setOptionBarangPersediaan()
17511751
{
17521752
return self::setOptions(MasterPersediaan::cache()->get('all'), 'id', 'barang', 'satuan');
17531753
}
1754+
1755+
public static function sendReminder($reminder, $method = 'auto')
1756+
{
1757+
$kegiatan = $reminder->daftarKegiatan;
1758+
$hari = $kegiatan->awal->diffInDays($method === 'auto' ? $reminder->tanggal : now());
1759+
$pesan = strtr($kegiatan->pesan, [
1760+
'{judul}' => $hari > 0 ? '[Reminder Deadline (H-'.$hari.')]' : '[Reminder Deadline]',
1761+
'{tanggal}' => Helper::terbilangTanggal($kegiatan->awal),
1762+
'{kegiatan}' => $kegiatan->kegiatan,
1763+
'{pj}' => $kegiatan->daftar_kegiatanable_type == 'App\Models\UnitKerja' ? UnitKerja::find($kegiatan->daftar_kegiatanable_id)->unit : User::find($kegiatan->daftar_kegiatanable_id)->name,
1764+
]);
1765+
$response = Fonnte::make()->sendWhatsAppMessage($kegiatan->wa_group_id, $pesan);
1766+
$reminder->status = $response['data']['process'] ?? 'Gagal';
1767+
$reminder->message_id = $response['data']['id'][0];
1768+
$reminder->save();
1769+
}
17541770
}

app/Nova/DaftarReminder.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace App\Nova;
44

55
use App\Helpers\Helper;
6+
use Illuminate\Support\Collection;
7+
use Laravel\Nova\Actions\Action;
8+
use Laravel\Nova\Fields\ActionFields;
69
use Laravel\Nova\Fields\BelongsTo;
710
use Laravel\Nova\Fields\Date;
811
use Laravel\Nova\Fields\Text;
@@ -100,7 +103,12 @@ public function lenses(NovaRequest $request)
100103
*/
101104
public function actions(NovaRequest $request)
102105
{
103-
return [];
106+
return [
107+
Action::using('Kirim Sekarang', function (ActionFields $fields, Collection $models) {
108+
$reminder = $models->first();
109+
Helper::sendReminder($reminder, 'manual');
110+
})->sole(),
111+
];
104112
}
105113

106114
public static function indexQuery(NovaRequest $request, $query)

app/Providers/NovaServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ public function tools()
252252
public function register()
253253
{
254254
parent::register();
255-
// Nova::initialPath('/resources/users');
255+
Nova::report(function ($exception) {
256+
if (app()->bound('sentry')) {
257+
app('sentry')->captureException($exception);
258+
}
259+
});
256260
}
257261
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"laravelwebdev/welcome": "^1.0",
2727
"mostafaznv/laracache": "^2.4",
2828
"phpoffice/phpword": "^1.2",
29-
"rap2hpoutre/fast-excel": "^5.5"
29+
"rap2hpoutre/fast-excel": "^5.5",
30+
"sentry/sentry-laravel": "^4.10"
3031
},
3132
"require-dev": {
3233
"barryvdh/laravel-debugbar": "^3.13",

0 commit comments

Comments
 (0)