So I have a background procss that I need to expose/control as a web service. I have wrapped the process to be able to accept commands via a pipe, but now am trying to find out how to control it.
Requirements are as follows:
- Need to be able to start the process via the web
- Need to be able to send cmds
- Need to be able to return results from cmds
- Process once started is alive until killed
I think the main question is how do I get django to own the process? Own in the sense, keep a valid save the pipe for future communication with the background process. Right now its something along the lines (just an example):
if __name__ == '__main__':
to_process_pipe, process_pipe = Pipe()
node = PFacade(process_pipe)
p.start()
to_process_pipe.send(['connect'])
print to_process_pipe.recv()
p.killed = True
p.join()
I think I need a better way to be able to communicate, bc I am not sure how I could store the Pipe in DJango.
And please, if you are going to respond with use Celery, please give me a good explination of how.
My final solution was to write a custom “mailbox” based on pidbox.Mailbox. Their implementation was horribly broken but the algorithm was solid.
I basically stood up a REST API hosted via django and then had that rest api send a message to a AMQP Queue(QPID implementation).
I then had a process that sits, monitors the queues, and passess along any commands as they came in.
It worked well and was pretty awesome when it came together.