14
14
use Magento \Framework \App \State ;
15
15
use Magento \Framework \Console \Cli ;
16
16
use Magento \Framework \Event \ObserverInterface ;
17
+ use Magento \Framework \Exception \CronException ;
17
18
use Magento \Framework \Profiler \Driver \Standard \Stat ;
18
19
use Magento \Framework \Profiler \Driver \Standard \StatFactory ;
19
20
use Magento \Cron \Model \DeadlockRetrierInterface ;
@@ -822,10 +823,16 @@ private function processPendingJobs(string $groupId, array $jobsRoot, int $curre
822
823
continue ;
823
824
}
824
825
825
- $ this ->tryRunJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
826
-
827
- if ($ schedule ->getStatus () === Schedule::STATUS_SUCCESS ) {
828
- $ processedJobs [$ schedule ->getJobCode ()] = true ;
826
+ try {
827
+ $ this ->tryRunJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
828
+ if ($ schedule ->getStatus () === Schedule::STATUS_SUCCESS ) {
829
+ $ processedJobs [$ schedule ->getJobCode ()] = true ;
830
+ }
831
+ } catch (CronException $ e ) {
832
+ $ this ->logger ->warning ($ e ->getMessage ());
833
+ continue ;
834
+ } catch (\Exception $ e ) {
835
+ $ this ->processError ($ schedule , $ e );
829
836
}
830
837
831
838
$ this ->retrier ->execute (
@@ -845,6 +852,7 @@ function () use ($schedule) {
845
852
* @param string[] $jobConfig
846
853
* @param Schedule $schedule
847
854
* @param string $groupId
855
+ * @throws CronException
848
856
*/
849
857
private function tryRunJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId )
850
858
{
@@ -858,10 +866,10 @@ private function tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule,
858
866
$ this ->_runJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
859
867
break ;
860
868
}
861
- $ this ->logger ->warning ("Could not acquire lock for cron job: {$ schedule ->getJobCode ()}" );
869
+ if ($ retries === 1 ) {
870
+ throw new CronException (__ ('Could not acquire lock for cron job: %1 ' , $ schedule ->getJobCode ()));
871
+ }
862
872
}
863
- } catch (\Exception $ e ) {
864
- $ this ->processError ($ schedule , $ e );
865
873
} finally {
866
874
$ this ->lockManager ->unlock ($ lockName );
867
875
}
0 commit comments