GenServers or Tasks or just Ports for external processes?

genserver
otp
task

#1

I’m creating a server that uses PDFtk to merge data with a PDF template and then render a flattened PDF. I want to understand the right way to handle the external process.

Based on the port documentation, a port is a process. Does that mean that it’s unnecessary to wrap it in a Task or GenServer to get OTP benefits? Would there be a benefit to using Task or GenServer instead?

Thanks in advance.


#2

Only the owner process can talk to a port, so if you have multiple processes that wan’t to talk to a single port, you need to wrap it in a proxy-process.

But I do not know anything about PDFtk or how it works, so I can’t tell you whats the best way to use it.

If its a oneshot CLI tool that does a single job and exits with status code then, just create a port from each worker, push data, wait for result, close port, repeat…


#3

Thanks for the information. It’s a one-shot CLI tool. It returns a status code or, depending in the function, some text to stdout. The main side effect is writing a PDF, which I would want to return to the user, and re-do if it failed.