@@ -26,7 +26,8 @@ class NodeIndexQueueCommandController extends CommandController
2626{
2727 use LoggerTrait;
2828
29- const QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer ' ;
29+ const BATCH_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer ' ;
30+ const LIVE_QUEUE_NAME = 'Flowpack.ElasticSearch.ContentRepositoryQueueIndexer.Live ' ;
3031
3132 /**
3233 * @var JobManager
@@ -84,9 +85,9 @@ public function buildCommand($workspace = null)
8485 $ this ->outputLine ();
8586 $ this ->outputLine ('<b>Indexing on %s ...</b> ' , [$ indexName ]);
8687
87- $ pendingJobs = $ this ->queueManager ->getQueue (self ::QUEUE_NAME )->count ();
88+ $ pendingJobs = $ this ->queueManager ->getQueue (self ::BATCH_QUEUE_NAME )->count ();
8889 if ($ pendingJobs !== 0 ) {
89- $ this ->outputLine ('<error>!! </error> The queue "%s" is not empty (%d pending jobs), please flush the queue. ' , [self ::QUEUE_NAME , $ pendingJobs ]);
90+ $ this ->outputLine ('<error>!! </error> The queue "%s" is not empty (%d pending jobs), please flush the queue. ' , [self ::BATCH_QUEUE_NAME , $ pendingJobs ]);
9091 $ this ->quit (1 );
9192 }
9293
@@ -101,38 +102,50 @@ public function buildCommand($workspace = null)
101102 $ this ->indexWorkspace ($ workspace , $ indexPostfix );
102103 }
103104 $ updateAliasJob = new UpdateAliasJob ($ indexPostfix );
104- $ this ->jobManager ->queue (self ::QUEUE_NAME , $ updateAliasJob );
105+ $ this ->jobManager ->queue (self ::BATCH_QUEUE_NAME , $ updateAliasJob );
105106
106- $ this ->outputLine ("Indexing jobs created for queue %s with success ... " , [self ::QUEUE_NAME ]);
107+ $ this ->outputLine ("Indexing jobs created for queue %s with success ... " , [self ::BATCH_QUEUE_NAME ]);
107108 $ this ->outputSystemReport ();
108109 $ this ->outputLine ();
109110 }
110111
111112 /**
113+ * @param string $queue Type of queue to process, can be "live" or "batch"
112114 * @param int $exitAfter If set, this command will exit after the given amount of seconds
113115 * @param int $limit If set, only the given amount of jobs are processed (successful or not) before the script exits
114116 * @param bool $verbose Output debugging information
115117 * @return void
116118 */
117- public function workCommand ($ exitAfter = null , $ limit = null , $ verbose = false )
119+ public function workCommand ($ queue = ' batch ' , $ exitAfter = null , $ limit = null , $ verbose = false )
118120 {
121+ $ allowedQueues = [
122+ 'batch ' => self ::BATCH_QUEUE_NAME ,
123+ 'live ' => self ::LIVE_QUEUE_NAME
124+ ];
125+ if (!isset ($ allowedQueues [$ queue ])) {
126+ $ this ->output ('Invalid queue, should be "live" or "batch" ' );
127+ }
128+ $ queueName = $ allowedQueues [$ queue ];
129+
119130 if ($ verbose ) {
120- $ this ->output ('Watching queue <b>"%s"</b> ' , [self :: QUEUE_NAME ]);
131+ $ this ->output ('Watching queue <b>"%s"</b> ' , [$ queueName ]);
121132 if ($ exitAfter !== null ) {
122133 $ this ->output (' for <b>%d</b> seconds ' , [$ exitAfter ]);
123134 }
124135 $ this ->outputLine ('... ' );
125136 }
137+
126138 $ startTime = time ();
127139 $ timeout = null ;
128140 $ numberOfJobExecutions = 0 ;
141+
129142 do {
130143 $ message = null ;
131144 if ($ exitAfter !== null ) {
132145 $ timeout = max (1 , $ exitAfter - (time () - $ startTime ));
133146 }
134147 try {
135- $ message = $ this ->jobManager ->waitAndExecute (self :: QUEUE_NAME , $ timeout );
148+ $ message = $ this ->jobManager ->waitAndExecute ($ queueName , $ timeout );
136149 } catch (JobQueueException $ exception ) {
137150 $ numberOfJobExecutions ++;
138151 $ this ->outputLine ('<error>%s</error> ' , [$ exception ->getMessage ()]);
@@ -171,7 +184,7 @@ public function workCommand($exitAfter = null, $limit = null, $verbose = false)
171184 */
172185 public function flushCommand ()
173186 {
174- $ this ->queueManager ->getQueue (self ::QUEUE_NAME )->flush ();
187+ $ this ->queueManager ->getQueue (self ::BATCH_QUEUE_NAME )->flush ();
175188 $ this ->outputSystemReport ();
176189 $ this ->outputLine ();
177190 }
@@ -185,8 +198,8 @@ protected function outputSystemReport()
185198 $ this ->outputLine ('Memory Usage : %s ' , [Files::bytesToSizeString (memory_get_peak_usage (true ))]);
186199 $ time = microtime (true ) - $ _SERVER ["REQUEST_TIME_FLOAT " ];
187200 $ this ->outputLine ('Execution time : %s seconds ' , [$ time ]);
188- $ this ->outputLine ('Indexing Queue : %s ' , [self ::QUEUE_NAME ]);
189- $ this ->outputLine ('Pending Jobs : %s ' , [$ this ->queueManager ->getQueue (self ::QUEUE_NAME )->count ()]);
201+ $ this ->outputLine ('Indexing Queue : %s ' , [self ::BATCH_QUEUE_NAME ]);
202+ $ this ->outputLine ('Pending Jobs : %s ' , [$ this ->queueManager ->getQueue (self ::BATCH_QUEUE_NAME )->count ()]);
190203 }
191204
192205 /**
@@ -217,7 +230,7 @@ protected function indexWorkspace($workspaceName, $indexPostfix)
217230 }
218231
219232 $ indexingJob = new IndexingJob ($ indexPostfix , $ workspaceName , $ jobData );
220- $ this ->jobManager ->queue (self ::QUEUE_NAME , $ indexingJob );
233+ $ this ->jobManager ->queue (self ::BATCH_QUEUE_NAME , $ indexingJob );
221234 $ this ->output ('. ' );
222235 $ offset += $ batchSize ;
223236 $ this ->persistenceManager ->clearState ();
0 commit comments