File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1111
1212class Events
1313{
14+ /**
15+ * @var string mutex to acquire
16+ */
17+ const MUTEX_ID = 'rss-cron ' ;
1418
1519 /**
1620 * Defines what to do if admin menu is initialized.
@@ -40,6 +44,11 @@ public static function onAdminMenuInit($event)
4044 */
4145 public static function onCron ($ event )
4246 {
47+ if (! Yii::$ app ->mutex ->acquire (static ::MUTEX_ID )) {
48+ Console::stdout ("RSS cron execution skipped - already running! \n" );
49+ return ;
50+ }
51+
4352 try {
4453 Console::stdout ("Updating RSS news feeds... \n" );
4554 $ ccmsEnabled = ContentContainerModuleState::find ()->
@@ -62,6 +71,8 @@ public static function onCron($event)
6271 $ event ->sender ->stderr ($ e ->getMessage ()."\n" );
6372 Yii::error ($ e );
6473 }
74+
75+ Yii::$ app ->mutex ->release (static ::MUTEX_ID );
6576 }
6677
6778}
Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ class GetFeedUpdates extends ActiveJob
4949 private $ newest ; # newest date we are accepting
5050 private $ items ; # array of sij\humhub\modules\rss\components\RssElement keyed by pubDate
5151
52+ /**
53+ * @var string mutex to acquire
54+ */
55+ const MUTEX_ID = 'rss-queue ' ;
56+
5257 private function log ($ message ) {
5358 if ( $ this ->logFileHandle ) {
5459 fwrite ($ this ->logFileHandle , $ message );
@@ -444,6 +449,10 @@ private function downloadNewsFeed()
444449 */
445450 public function run ()
446451 {
452+ if (! Yii::$ app ->mutex ->acquire (static ::MUTEX_ID )) {
453+ Console::stdout ("RSS queue execution skipped - already running! \n" );
454+ return ;
455+ }
447456
448457####### $this->logFileHandle = fopen(dirname(__FILE__) . '/log.txt', 'w');
449458
@@ -478,5 +487,6 @@ public function run()
478487 fclose ($ this ->logFileHandle );
479488 }
480489
490+ Yii::$ app ->mutex ->release (static ::MUTEX_ID );
481491 }
482492}
You can’t perform that action at this time.
0 commit comments