I'm attempting to send a CURL to my Slack channel whenever an Artisan command fails in any of one of my scripts (it runs hourly so I want to make sure we know what's causing these errors at any point in the night), but it doesn't want to send the CURL. I've confirmed other things work, but it just doesn't seem to want to send it right now.
Here's the code to send it, it's not much
} catch(\Throwable $e) {
$message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish.";
Curl::to('https://hooks.slack.com/services/MYHOOK/RAWR/NOSEE')
->withContentType('application/json')->withData('{"text":"'.$message.'"}')->post();
}
No idea why that doesn't work, I'm using a PHP Curl library, but it does the same thing as the regular cURL
I can include the rest of the code but it really doesn't matter as this is the only part not working
Edit: Full Code
public function handle() {
//This function updates a bars hours after they're closed to the next day's hours
//First we remove unwanted barDays
try {
$this->cleanBar();
$this->cleanBarDays();
$this->fixBarStats();
$this->fixPromoStats();
$this->cleanUserBars();
$count = count(barDays::all()) + count(promoStats::where('timeLeft', NULL)->get()) + count(User::where('bar_id', '!=', NULL)->get()) + count(barStats::where('timeLeft', NULL)->get());
$Bars = Bars::all();
$this->output->progressStart(count($Bars));
foreach($Bars as $Bar) {
$now = Carbon::now()->setTimezone($Bar->timezone);
$hours = $Bar->getHours();
if($hours[0] === 'Closed') {
$Bar->numPeople = 0;
$Bar->hours = 'Closed';
Bars::withoutSyncingToSearch(function() use($Bar) {
$Bar->save();
});
} else {
//Not closed, we check if the exploded hours followed the format
$openHours = $hours[0];
$closedHours = $hours[1];
//Then we try to parse them, otherwise we catch the error to follow the culprit
$open = Carbon::parse($openHours, $Bar->timezone);
$closed = Carbon::parse($closedHours, $Bar->timezone);
//If the bar is closed, we update the hours on the bar
if(!$now->between($open, $closed)) {
$Bar->updateHours();
$Bar->numPeople = 0;
//UPDATE BARSTATS HERE WITH BAR ID
$barStats = barStats::where('bar_id', $Bar->id)->where('timeLeft', NULL)->get();
foreach($barStats as $barStat) {
$barStat->timeLeft = Carbon::now();
$barStat->save();
}
} elseif($now->between($open, $closed)) {
$Bar->updateHours();
}
Bars::withoutSyncingToSearch(function() use($Bar) {
$Bar->save();
});
}
$this->output->progressAdvance();
}
$this->output->progressFinish();
Curl::to('https://hooks.slack.com/services/nuh uh/')
->withContentType('application/json')->withData('{"text":"Reset '.count($Bars).' Bars Hour\'s, '.$count.' number of miscellaneous models and reset number of people if closed."}')->post();
return "Updated";
} catch(Exception $e) {
$message = "Found an error with the message " . $e->getMessage() . " , The function ResetBars did not finish.";
Curl::to('https://hooks.slack.com/services/nope/')
->withContentType('application/json')->withData('{"text":"'.$message.'"}')->post();
}
}
Ignore the function calls at the top Thanks
- Zach