How to retry a Job In Elixir

Please i’ve got a Question, i’m replacing a Predictive dialer with Elixir. It has exceeded all expectations so far. However, i’m facing an issue. This piece of code works well assuming all third party dependencies work as expected,

def perform(phonebook_contacts,...) do
    alias FSModEvent.Connection, as: C
  for x <-Enum.chunk(phonebook_contacts,100,100,[]), y <- x  do 
    unless Telephony.user_balance(account_number) <= 0 do
  	Task.start_link(fn -> 
        # some background job to dailout phone number y
    end)
    # :timer.sleep(1000);
    end 
  ...

phonebook_contacts can be a list with as many as 200K Numbers
I’m using exq. If something external causes the job to fail, when it gets retried, it starts from the begining of the list, is there a way i can probably retry from the last contact where the Job failed at?

Assuming [12,34,56,78,90…]

Assuming the Job fails at 56, it restarts from 12 again, it there a way of continuing from 78,...? or a better way of handling this use case?

If you are already using Exq, then maybe store the progress of the job in redis?

Thank you for your suggestion. Any pointers on how to do this? While i dig through the Exq documentation

Interesting. Can you please share more about your project?

@Architect It’s part of a cloud based Call Center application - Inbound,outbound,voice analytics, IVR, … This code snippet just handles the dialing of the outbound calls.

1 Like

@devie: How about use retry library?

To save state you can use simple Agent and then skip entries based on stored information in it.

2 Likes

I don’t really know much about Exq, but looking at it… it doesn’t seem well-suited for what you’re trying to do. You’re redefining what Exq means by “retry”, which is “do this again with the same arguments as before as I’m expecting the same result”.

As for your idea of retry – you want to be able to start where the failure happened because starting from the beginning won’t give the same result - it has side effects! Even though you’re restarting what you think is the same job, with Exq semantics, that’s actually a new job because you want to use a different set of data.


I think there’s a better way to do this…

But first, what constitutes a failure? Is it when you receive a BGAPI error or a FreeSWITCH -ERR response or what?

Second, do you really want to start from the first job that failed? It makes more sense to me to collect every dial out that failed and then retry those specifically.

3 Likes

Or use the retryable_ex package which doesn’t use a single drop of metaprogramming or macros.

Or just use Faktory (by the author of Sidekiq) and the Elixir Faktory Client, which has retries built in.

1 Like

I have the same problem, how did you answer?