Skip to content

Commit

Permalink
Add stale listing notifications (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxe authored Sep 10, 2023
1 parent 80ceb05 commit 70a02bd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Jobs\RefreshCourseData;
use App\Jobs\ResetMoodleIntegration;
use App\Jobs\SendEventNotifications;
use App\Jobs\SendStaleListingNotifications;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

Expand All @@ -23,7 +24,8 @@ protected function schedule(Schedule $schedule)
$schedule->job(new RefreshCourseData)->dailyAt('4:00')->sentryMonitor('refresh-course-data');

$schedule->job(new SendEventNotifications)->everyMinute()->sentryMonitor('send-event-notifications');

$schedule->job(new SendStaleListingNotifications)->dailyAt('23:00' /* 6:00 PM CST */)->sentryMonitor('send-stale-notifications');

$schedule->job(new ResetMoodleIntegration)->yearlyOn(1, 1, '0:0');
$schedule->job(new ResetMoodleIntegration)->yearlyOn(6, 1, '0:0');

Expand Down
43 changes: 43 additions & 0 deletions app/Jobs/SendStaleListingNotifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Jobs;

use App\Models\Listing;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;

class SendStaleListingNotifications implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Execute the job.
*/
public function handle(): void
{
$listings = Listing::query()
->where('available', true)
->whereDate('created_at', now()->subWeek())
->with('user')
->get();

foreach($listings as $listing) {
$trimmedTitle = Str::limit($listing->title, 25);

Http::withToken(env('EXPO_ACCESS_TOKEN'))
->post('https://exp.host/--/api/v2/push/send', [
'to' => $listing->user->expo_token,
'title' => 'Is this still for sale?',
'body' => "It’s been a second since you posted “{$trimmedTitle}”. If it’s not available, you can update the listing.",
'sound' => 'default',
'data' => ['url' => "grand://marketplace/$listing->id"]
]);
}
}
}

0 comments on commit 70a02bd

Please sign in to comment.