Answer the question
In order to leave comments, you need to log in
How to properly track the execution of cron scripts?
In my Laravel project, many scripts are run by cron.
Well, for example, something like this:
$users = User::all();
foreach ($users as $user) {
try {
$json = file_get_contents('vkapicom/xxx');
$content = json_decode($json, true);
usleep(500);
} catch (\Exception $e) {
Log::create(['message' => $e->getMessage()]);
continue;
}
if (isset($content)) {
//do something
try {
Post::create([/*...*/]);
} catch (\Exception $e) {
Log::create(['message' => $e->getMessage()]);
}
}
}
Answer the question
In order to leave comments, you need to log in
What's the difference? what will the answer be?
on one of the projects where there is payment, I throw out the olpat log into a separate file, the rest is all poured into the Larovsky daily.
on the other - working out a heavy cron data collector - each instance of the collector into its own single file, sometimes archived manually.
on the third long-running collector, where it is important what the script is doing right now, a tree of segments with the properties that it was going to work on in this iteration and a beat for each ok / neok is displayed in its log. By properties, you can quickly write a query to the database with handles to check possible plugs.
I try to put everything in one log, so as not to produce garbage.
into the account "clog the log". if you have something important that needs to be monitored, then this is no longer a log, but some kind of event system.
I have a log recording function, in addition to it, it also writes "system events" - that is, what is important for me as an administrator to observe. e.g. system errors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question