|
186 | 186 | end |
187 | 187 | end |
188 | 188 |
|
| 189 | + describe ".latest_failed_pipelines" do |
| 190 | + it "returns the latest failed pipelines including intermediate and terminal errors" do |
| 191 | + # Create a publishing queue item and associated pipeline state |
| 192 | + pqi1 = PublishingQueueItem.ensure_queued!(podcast) |
| 193 | + _s1 = PublishingPipelineState.create!(podcast: podcast, publishing_queue_item: pqi1) |
| 194 | + PublishingPipelineState.error_apple!(podcast) |
| 195 | + PublishingPipelineState.complete!(podcast) |
| 196 | + |
| 197 | + # Verify that the intermediate error is included in the latest failed pipelines |
| 198 | + assert_equal [podcast], PublishingPipelineState.latest_failed_podcasts |
| 199 | + assert_equal ["created", "error_apple", "complete"], PublishingPipelineState.latest_failed_pipelines.where(podcast: podcast).map(&:status) |
| 200 | + |
| 201 | + # Create another publishing queue item and associated pipeline state |
| 202 | + pqi2 = PublishingQueueItem.ensure_queued!(podcast) |
| 203 | + _s2 = PublishingPipelineState.create!(podcast: podcast, publishing_queue_item: pqi2) |
| 204 | + PublishingPipelineState.error!(podcast) |
| 205 | + |
| 206 | + # Verify that the terminal error is included in the latest failed pipelines |
| 207 | + assert_equal [podcast], PublishingPipelineState.latest_failed_podcasts |
| 208 | + assert_equal ["created", "error"], PublishingPipelineState.latest_failed_pipelines.where(podcast: podcast).map(&:status) |
| 209 | + |
| 210 | + # Verify that a successful pipeline is not included in the latest failed pipelines |
| 211 | + pqi3 = PublishingQueueItem.ensure_queued!(podcast) |
| 212 | + _s3 = PublishingPipelineState.create!(podcast: podcast, publishing_queue_item: pqi3) |
| 213 | + PublishingPipelineState.complete!(podcast) |
| 214 | + |
| 215 | + assert_equal [].sort, PublishingPipelineState.latest_failed_pipelines.where(podcast: podcast) |
| 216 | + assert ["created", "complete"], PublishingPipelineState.latest_pipelines.where(podcast: podcast).pluck(:status) |
| 217 | + end |
| 218 | + end |
| 219 | + |
189 | 220 | describe ".retry_failed_pipelines!" do |
190 | 221 | it "should retry failed pipelines" do |
191 | 222 | PublishingPipelineState.start_pipeline!(podcast) |
|
200 | 231 | assert_equal ["created"].sort, PublishingPipelineState.latest_pipeline(podcast).map(&:status).sort |
201 | 232 | end |
202 | 233 |
|
| 234 | + it "retries pipelines with intermediate error_apple and non-error terminal status" do |
| 235 | + PublishingPipelineState.start_pipeline!(podcast) |
| 236 | + assert_equal ["created"], PublishingPipelineState.latest_pipeline(podcast).map(&:status) |
| 237 | + |
| 238 | + # it fails |
| 239 | + PublishingPipelineState.error_apple!(podcast) |
| 240 | + assert_equal ["created", "error_apple"].sort, PublishingPipelineState.latest_pipeline(podcast).map(&:status).sort |
| 241 | + |
| 242 | + PublishingPipelineState.complete!(podcast) |
| 243 | + assert_equal ["created", "error_apple", "complete"].sort, PublishingPipelineState.latest_pipeline(podcast).map(&:status).sort |
| 244 | + |
| 245 | + # it retries |
| 246 | + PublishingPipelineState.retry_failed_pipelines! |
| 247 | + assert_equal ["created"].sort, PublishingPipelineState.latest_pipeline(podcast).map(&:status).sort |
| 248 | + end |
| 249 | + |
203 | 250 | it "ignores previously errored pipelines back in the queue" do |
204 | 251 | # A failed pipeline |
205 | 252 | PublishingPipelineState.start_pipeline!(podcast) |
|
0 commit comments