|
2 | 2 |
|
3 | 3 | from lightning_app import CloudCompute, LightningApp, LightningFlow, LightningWork |
4 | 4 | from lightning_app.storage.path import _artifacts_path, _filesystem |
5 | | -from lightning_app.utilities.enum import WorkStageStatus, WorkStopReasons |
| 5 | +from lightning_app.utilities.enum import WorkStageStatus |
6 | 6 |
|
7 | 7 |
|
8 | 8 | class SourceFileWriterWork(LightningWork): |
@@ -35,22 +35,21 @@ def run(self): |
35 | 35 | if self.work.counter == 0: |
36 | 36 | self.work.run() |
37 | 37 |
|
38 | | - elif ( |
39 | | - self.work.status.stage == WorkStageStatus.STOPPED |
40 | | - and self.work.status.reason == WorkStopReasons.SIGTERM_SIGNAL_HANDLER |
41 | | - and self.make_check |
42 | | - ): |
43 | | - succeeded_status = self.work.statuses[-3] |
44 | | - stopped_status_pending = self.work.statuses[-2] |
45 | | - stopped_status_sigterm = self.work.statuses[-1] |
46 | | - assert succeeded_status.stage == WorkStageStatus.SUCCEEDED |
47 | | - assert stopped_status_pending.stage == WorkStageStatus.STOPPED |
48 | | - assert stopped_status_pending.reason == WorkStopReasons.PENDING |
49 | | - assert stopped_status_sigterm.stage == WorkStageStatus.STOPPED |
50 | | - assert stopped_status_sigterm.reason == WorkStopReasons.SIGTERM_SIGNAL_HANDLER |
| 38 | + elif self.work.status.stage == WorkStageStatus.STOPPED and self.make_check: |
| 39 | + succeeded_statuses = [status for status in self.work.statuses if status.stage == WorkStageStatus.SUCCEEDED] |
| 40 | + # Ensure the work succeeded at some point |
| 41 | + assert len(succeeded_statuses) > 0 |
| 42 | + succeeded_status = succeeded_statuses[-1] |
| 43 | + |
| 44 | + stopped_statuses = [status for status in self.work.statuses if status.stage == WorkStageStatus.STOPPED] |
| 45 | + |
| 46 | + # We want to check that the work started shutting down withing the required timeframe, so we take the first |
| 47 | + # status that has `stage == STOPPED`. |
| 48 | + stopped_status = stopped_statuses[0] |
| 49 | + |
51 | 50 | # Note: Account for the controlplane, k8s, SIGTERM handler delays. |
52 | | - assert (stopped_status_pending.timestamp - succeeded_status.timestamp) < 20 |
53 | | - assert (stopped_status_sigterm.timestamp - stopped_status_pending.timestamp) < 120 |
| 51 | + assert (stopped_status.timestamp - succeeded_status.timestamp) < 20 |
| 52 | + |
54 | 53 | fs = _filesystem() |
55 | 54 | destination_path = _artifacts_path(self.work) / pathlib.Path(*self.work.path.resolve().parts[1:]) |
56 | 55 | assert fs.exists(destination_path) |
|
0 commit comments