0

I'm building a Facebook Messenger chatbot that can process long running jobs (that may fail), and I need to respond 200 to Facebook before the job is completed.

I've tried using Pipes, but after a while I realized that I didn't know what I was doing.

How can I achieve this?

Thanks in advance

EDIT: As epsilonhalbe pointed, the question is very broad. I would try to make it more clear.

Right now I have this:

myHandler :: Message -> Handler Text
myHandler msg = do
    doSomeStuff msg
    return "ok"

The problem is that "doSomeStuff" is a long proccess and it can give a timeout error. So what I want to achieve is to respond "ok" before the process is completed. The Http code is 202 Accepted.

I was thinking that sending a message to a mailbox could be a solution. But I would like a more idiomatic way to doing it.

paparga
  • 11
  • 1
  • Hi, right now it is very broad and unclear what concrete problem you have. As a rule of thumb, when asking for help I try to put as last as much effort in writing the question as i would expect someone answering it. – epsilonhalbe Aug 20 '17 at 01:37
  • Thanks for the feedback! – paparga Aug 20 '17 at 21:49
  • Regardless of the "message passing" mechanism that you'll pick, you definitely want the long running computation/process to happen in a separate thread or even process. The servant handler here would therefore just "submit" the computation to this separate thread or process and return some identifier that would allow one to later get the status of the job, in case the caller needs the output of the computation. – Alp Mestanogullari Aug 22 '17 at 13:29

1 Answers1

1

I use hworker at work for something like this -- sending batch emails. You make instances of Job, ToJSON, and FromJSON for your long-running job, then use queue whenever you want to start the job. You'll also need Redis to keep track of the state of your jobs to use hworker.

Libby
  • 1,357
  • 12
  • 17