Fix the replay of a Lambda that sends email
Your task
Your Lambda sends a welcome email. The first version started the send as a background task and returned 202 at once. Some users never got the email, and nothing was logged. Lambda freezes the environment the moment the handler returns, so the task never ran. Your team now replays a handler's actions to see which jobs survive.
An assistant wrote surviving_jobs(actions). It is in the editor. It has a bug. Find it and fix it.
Input and output:
actions: what the handler does, in order. Each one is"spawn:<job>"(start a background task and do not wait for it),"await:<job>"(finish the job before going on),"enqueue:<job>"(hand the job to a durable queue) or"return"(the handler returns).- Return the names of the jobs that survive, without repeats, sorted by plain character order.
Rules the tests check:
- Actions after the first
"return"never run. With no"return", every action runs. - Split an action at its first
:into a verb and a job name. The job name is everything after that:. It can be empty or contain:. - An action with no
:, other than"return"itself, is ignored. So is an unknown verb. - A job survives when an
awaitor anenqueuefor it runs. - A
spawnalone never makes a job survive. It also does not stop a laterawaitorenqueueof the same job from counting.
Examples
surviving_jobs(actions: list[str]) -> list[str]Example 1
Input
surviving_jobs(["spawn:welcome", "return"])Output
[]Example 2
Input
surviving_jobs(["await:welcome", "return"])Output
["welcome"]Example 3
Input
surviving_jobs(["enqueue:welcome", "return"])Output
["welcome"]