/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     Heartbeat::chunk(10, function ($heartbeats) {
         foreach ($heartbeats as $heartbeat) {
             $last_heard_from = $heartbeat->last_activity;
             if (!$last_heard_from) {
                 $last_heard_from = $heartbeat->created_at;
             }
             $missed = $heartbeat->missed + 1;
             $next_time = $last_heard_from->addMinutes($heartbeat->interval * $missed);
             if (Carbon::now()->gt($next_time)) {
                 $heartbeat->status = Heartbeat::MISSING;
                 $heartbeat->missed = $missed;
                 $heartbeat->save();
                 foreach ($heartbeat->project->notifications as $notification) {
                     $this->dispatch(new Notify($notification, $heartbeat->notificationPayload()));
                 }
             }
         }
     });
 }
 public function run()
 {
     DB::table('heartbeats')->delete();
     Heartbeat::create(['name' => 'My Cron Job', 'project_id' => 1, 'interval' => 30]);
 }