I've made a simple scheduler in Go that is meant to be long-running and using channels, when the ticker's channel is ready, I poll my database for emails to be sent out, which sends the email to the send channel and when it is ready, the email is sent out. For now the tick interval is every 10 minutes. This scheduler connects to the pg database once on startup.
Example:
for {
select {
case <-s.ticker.C:
// query db, sends each email to s.send channel. Could just send them
// without the channel though.
go poll()
case email := s.send:
send(email) // sends the email via some email service
}
}
My question is if would it be more safe/efficient to use this Go program which connects to the database once, or setup a Lambda function as a cronjob every 10 minutes? I've never used Lambda, but I believe there would be a new database connection every time it is run, which also involves fetching credentials.
Cost-wise assume that it doesn't matter, I'm only curious as to which would be more safe/efficient. Any information is appreciated!