Re: Mail queue thread

2018-10-30 Thread brjann
> If I was building a system like the one you describe for real, then the > first tool I'd reach for would be a email sending service, like Mailgun, > Sendgrid, or AWS SES. These sorts of services take care of queuing mail, > retrying on failure, and keeping track of mail bounces. They also all hav

Re: Mail queue thread

2018-10-27 Thread James Reeves
If I was building a system like the one you describe for real, then the first tool I'd reach for would be a email sending service, like Mailgun, Sendgrid, or AWS SES. These sorts of services take care of queuing mail, retrying on failure, and keeping track of mail bounces. They also all have free t

Re: Mail queue thread

2018-10-27 Thread brjann
Hi Erik, It hadn't even crossed my mind that I could write a separate app which is trigged by cron. I will consider that! I have searched for different schedulers and found a few options but cannot locate any in Juxt's github repositories. I've read about transducers and think that I've got a supe

Re: Mail queue thread

2018-10-27 Thread brjann
> > Thanks for pointing out the submit function and explaining the wrapper. >> Would you specifically advise against sending the result back through a >> channel? >> > > It depends what you're trying to do. What are you doing with the result, > and what's your reasoning for not handling it in your

Re: Mail queue thread

2018-10-26 Thread Erik Assum
Expert answer is always “it depends”. And long winded answer: I’d first write a function that can send one “email”: (defn send-email! [ctx email-data] …) ; context contains whatever outside resources you need Now you have the freedom to work on a list of email-data like this: (doseq [email em

Re: Mail queue thread

2018-10-26 Thread James Reeves
On Fri, 26 Oct 2018 at 14:05, wrote: > Thanks for pointing out the submit function and explaining the wrapper. > Would you specifically advise against sending the result back through a > channel? > It depends what you're trying to do. What are you doing with the result, and what's your reasoning

Re: Mail queue thread

2018-10-26 Thread brjann
James, Thanks for pointing out the submit function and explaining the wrapper. Would you specifically advise against sending the result back through a channel? I have made a prototype (using ExecutorService) where the email is provided together with a channel and the sender starts a small go block

Re: Mail queue thread

2018-10-25 Thread Erik Assum
Not knowing your app nor your requirements, but it might also be an idea to separate concerns: Your web-app could store “emails to be sent” in a database table, and you could have a different process reading this table at regular intervals and sending mails, and also marking the emails as sent,

Re: Mail queue thread

2018-10-25 Thread James Reeves
On Thu, 25 Oct 2018 at 21:47, wrote: > It seems that I somewhat over-engineered my queue :-) I don't know any > Java so this is very helpful! > When it comes to Java concurrency, ExecutorService and BlockingQueue cover a lot of bases. > If I want to know the result of the email send within the

Re: Mail queue thread

2018-10-25 Thread brjann
It seems that I somewhat over-engineered my queue :-) I don't know any Java so this is very helpful! If I want to know the result of the email send within the worker thread, would you recommend sending it back through a channel? One purpose of my queue was to be able to put urgent messages at the

Re: Mail queue thread

2018-10-25 Thread James Reeves
On Thu, 25 Oct 2018 at 19:01, wrote: > Thank you for the thorough explanation! So if I understand you correctly, > if no calls are made to the executor thread, it will just rest silently > until queue-email is called again - not consuming any server resources. > That's essentially correct. Thre

Re: Mail queue thread

2018-10-25 Thread brjann
Hi James, Thank you for the thorough explanation! So if I understand you correctly, if no calls are made to the executor thread, it will just rest silently until queue-email is called again - not consuming any server resources. Are there any recommendations for the number of worker threads when ea

Re: Mail queue thread

2018-10-25 Thread James Reeves
The Java executor classes are essentially a queue backed by a thread pool of workers. So suppose we create a new executor: (def executor (java.util.concurrent.Executors/newFixedThreadPool 32)) This creates an ExecutorService object with a pool of 32 worker threads. We can pass it a zero-argume

Re: Mail queue thread

2018-10-25 Thread brjann
Hi James, Thanks! How would one create a thread that continuously monitors a mail queue and sends any mails in it? Or do you mean that I would create one thread per mail that I want to send? Wouldn't that create a problem if I'm about to send 1 mails in one go? And thanks for the heads up reg

Re: Mail queue thread

2018-10-25 Thread James Reeves
Hi Brjánn, Executing queued jobs in a background thread is a common task, and as it happens there's a set of Java classes to do just that. (let [e (java.util.concurrent.Executors/newSingleThreadExecutor)] (.execute e #(prn "foo")) (.execute e #(prn "bar")) (Thread/sleep 1000) (.execute e