Skip to content

Remove a flight that was checked in but not boarded for 24 hours - #350

Merged
oskarbarcz merged 1 commit into
mainfrom
remove-stale-check-ins
Nov 18, 2026
Merged

oskarbarcz merged 1 commit into
mainfrom
remove-stale-check-ins

Conversation

@oskarbarcz

Copy link
Copy Markdown
Member

A pilot's own import checks them in straight away, and a flight in progress blocks the next import (#348). An import the pilot never flies would therefore block them for good. This removes a flight that was checked in but hasn't started boarding 24 hours after check-in.

What changes

  • StaleCheckInRemovalService (automations module, every 5 minutes, through ScheduledJobs.runExclusively):
    • lists flights in checked_in whose flight.pilot-checked-in event is more than 24 hours old (ListStaleCheckInsQuery)
    • runs RemoveStaleCheckInCommand on each, logging and carrying on when one fails
  • Flight.removeStaleCheckIn() expects checked_in (otherwise StaleCheckInHasMovedOnError, 409) and records StaleCheckInWasRemovedEvent with the captain, aircraft and airports. The handler emits it, waits for the listeners, then removes the flight.
  • Each module undoes what check-in started for it, in its existing lifecycle listener:
    • users: clear the pilot's current flight, delete the pending performing_flight travel, delete the user_aircraft row (it has no cascade, so the delete would fail without it)
    • aircraft: state back to idle, delete the pending performing_flight reposition
    • rotations: a rotation this check-in moved to in_progress, with no leg flown, goes back to ready
    • airports: stop the weather watch for the flight's airports
  • Repositionings stay. Any automatic deadhead check-in recorded (pilot or aircraft to the departure airport) stays, since that move happened. Its flight reference is set to null by the existing onDelete: SetNull.
  • No age cap. The scheduler is off locally and in CI (SCHEDULER_ENABLED="false"), so the seeded January check-ins are safe. In production it also clears check-ins that are already stuck.

Tests

  • Unit:
    • the aggregate rule records the event only from checked_in, and every other status is left alone
    • the job's 24-hour cutoff
    • the job removes each listed flight and carries on past a failure
  • End to end on the local API:
    • A new pilot imported LH80, the check-in event was backdated two days, and the query and command ran inside the container.
    • The query found the flight; after the command the flight and its events were gone.
    • The pilot's current flight was cleared, the pending travel and user_aircraft row were gone, and D-AIMC was back to idle.
  • Full run: On this commit: format (whole repo; its only warning is a git-excluded local .impeccable cache CI never sees), lint, test (1449) and test:functional (1624 scenarios) all exit 0.

Version 3.91.0. Stacked on #349.

Knowledge base: mypreflight/product#78.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

OpenTofu plan for infra

Commit 929892c · Plan: 1 to add, 1 to change, 1 to destroy.

Show plan
 OpenTofu used the selected providers to generate the following execution
 plan. Resource actions are indicated with the following symbols:
!  ~ update in-place (current -> planned)
!-/+ destroy and then create replacement
 
 OpenTofu will perform the following actions:
 
   # aws_ecs_service.app will be updated in-place
!  ~ resource "aws_ecs_service" "app" {
         id                                 = "arn:aws:ecs:eu-central-1:805830022748:service/mypreflight/flight-tracker-api"
         name                               = "flight-tracker-api"
         tags                               = {}
!      ~ task_definition                    = "arn:aws:ecs:eu-central-1:805830022748:task-definition/flight-tracker-api:23" -> (known after apply)
         # (19 unchanged attributes hidden)
 
         # (4 unchanged blocks hidden)
     }
 
   # aws_ecs_task_definition.app must be replaced
!-/+ resource "aws_ecs_task_definition" "app" {
!      ~ arn                      = "arn:aws:ecs:eu-central-1:805830022748:task-definition/flight-tracker-api:23" -> (known after apply)
!      ~ arn_without_revision     = "arn:aws:ecs:eu-central-1:805830022748:task-definition/flight-tracker-api" -> (known after apply)
!      ~ container_definitions    = jsonencode(
!          ~ [
                 {
                     command                = [
                         "tunnel",
                         "--no-autoupdate",
                         "--metrics",
                         "localhost:20241",
                         "--grace-period",
                         "20s",
                         "run",
                     ]
                     dependsOn              = [
                         {
                             condition     = "HEALTHY"
                             containerName = "flight-tracker-api"
                         },
                     ]
                     environment            = []
                     essential              = true
                     healthCheck            = {
                         command     = [
                             "CMD",
                             "cloudflared",
                             "tunnel",
                             "--metrics",
                             "localhost:20241",
                             "ready",
                         ]
                         interval    = 5
                         retries     = 6
                         startPeriod = 10
                         timeout     = 2
                     }
                     image                  = "cloudflare/cloudflared@sha256:4955524aeaa379e154023d5a027c250f7b35041a2e7e950cf13f144bc9b9c5ba"
                     linuxParameters        = {
                         capabilities = {
                             add  = []
                             drop = [
                                 "ALL",
                             ]
                         }
                     }
                     logConfiguration       = {
                         logDriver = "awslogs"
                         options   = {
                             awslogs-group         = "/ecs/flight-tracker-api"
                             awslogs-region        = "eu-central-1"
                             awslogs-stream-prefix = "cloudflared"
                         }
                     }
                     mountPoints            = []
                     name                   = "cloudflared"
                     portMappings           = []
                     readonlyRootFilesystem = true
                     secrets                = [
                         {
                             name      = "TUNNEL_TOKEN"
                             valueFrom = "arn:aws:ssm:eu-central-1:805830022748:parameter/mypreflight/api/cloudflare-tunnel-token"
                         },
                     ]
                     systemControls         = []
                     volumesFrom            = []
                 },
!              ~ {
!                  ~ image                  = "ghcr.io/mypreflight/flight-tracker-api:3.89.0" -> "ghcr.io/mypreflight/flight-tracker-api:3.91.0"
                     name                   = "flight-tracker-api"
                     # (11 unchanged attributes hidden)
                 },
             ] # forces replacement
         )
!      ~ enable_fault_injection   = false -> (known after apply)
!      ~ id                       = "flight-tracker-api" -> (known after apply)
!      ~ revision                 = 23 -> (known after apply)
-      - tags                     = {} -> null
         # (11 unchanged attributes hidden)
 
-      - volume {
-          - configure_at_launch = false -> null
-          - name                = "tmp" -> null
         }
+      + volume {
+          + configure_at_launch = (known after apply)
+          + name                = "tmp"
         }
 
         # (1 unchanged block hidden)
     }
 
 Plan: 1 to add, 1 to change, 1 to destroy.
 
 Changes to Outputs:
!  ~ app_image        = "ghcr.io/mypreflight/flight-tracker-api:3.89.0" -> "ghcr.io/mypreflight/flight-tracker-api:3.91.0"

Workflow run

@oskarbarcz
oskarbarcz force-pushed the remove-stale-check-ins branch from 999b01b to e3960ea Compare November 18, 2026 10:53
Base automatically changed from pilot-own-flights to main November 18, 2026 11:00
A pilot's own import checks them in straight away, and one flight in
progress blocks the next import, so an import they never fly would
block them for good. Every five minutes, a flight checked in more than
24 hours ago that hasn't started boarding is removed. Each module
undoes what check-in started for it: the pilot's current flight and
pending travel, the pilot's aircraft entry, the aircraft's checked-in
state and pending flight, a rotation that only this check-in started,
and the weather watch. Repositionings to the departure airport stay,
since that move happened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@oskarbarcz
oskarbarcz force-pushed the remove-stale-check-ins branch from e3960ea to 929892c Compare November 18, 2026 11:01
@oskarbarcz
oskarbarcz merged commit 107bbc8 into main Nov 18, 2026
4 checks passed
@oskarbarcz
oskarbarcz deleted the remove-stale-check-ins branch November 18, 2026 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant