instedd / surveda

InSTEDD Surveda
https://instedd.org/technologies/surveda-mobile-surveys/
GNU General Public License v3.0
17 stars 6 forks source link

Improve channel broker GC #2357

Open anaPerezGhiglia opened 4 months ago

anaPerezGhiglia commented 4 months ago

Clear the channel broker queue entry if active_contact.channel_state is nil to prevent the following error

** (FunctionClauseError) no function clause matching in Ask.Runtime.Channel.Ask.Runtime.NuntiumChannel.message_inactive?/2
    (ask 0.31.0) lib/ask/runtime/nuntium_channel.ex:455: Ask.Runtime.Channel.Ask.Runtime.NuntiumChannel.message_inactive?(%Ask.Runtime.NuntiumChannel{base_url: "https://nuntium-stg.instedd.org", name: "lgwsim - qa@manas.com.ar", oauth_token: %OAuth2.AccessToken{access_token: "TRzf9Cu1v_WlwLkpiIKShi-nA_GZh1F_S2NLMEcXE_4", expires_at: 1720472770, other_params: %{}, refresh_token: "dH0-HfJfWAIVdDsyCnC3_HhyKkXU_l58i3Hl07KMRsQ", token_type: "Bearer"}, settings: %{"capacity" => 1000, "nuntium_account" => "qa@manas.com.ar", "nuntium_channel" => "lgwsim"}}, nil)
matiasgarciaisaia commented 4 months ago

We'd have to re-check, but we should probably only drop contact attempts with nil channel state if the contact attempt is really old (for some definition of really old - maybe a couple of days).

I think there's a "standard" way to have contact attempts without channel state in the queue, and we shouldn't GC those - but only do so in cases like the one we had in staging, in which a contact attempt was left there for months.

matiasgarciaisaia commented 4 months ago

We may even want to generalize this to an ultimate GC pass in which we drop old contact attempts regardless of everything else - like a forcefull GC that may leave some stuff inconsistent but will always work (ie, it won't check if there's a contact attempt queued in the channel).