Don't fail oban job when provision_ssl_certificates fails

This commit is contained in:
Uku Taht 2021-04-28 15:25:30 +03:00
parent 718aff1bdf
commit 07653079e8
2 changed files with 22 additions and 2 deletions

View File

@ -23,7 +23,7 @@ defmodule Plausible.Workers.ProvisionSslCertificates do
)
for domain <- recent_custom_domains do
{:ok, res, code} =
res =
ssh.run(
conn,
'sudo certbot certonly --webroot -w /root/webroot -n -d \"#{domain.domain}\"',
@ -31,7 +31,13 @@ defmodule Plausible.Workers.ProvisionSslCertificates do
exec_timeout: @timeout
)
report_result({res, code}, domain)
case res do
{:ok, msg, code} ->
report_result({msg, code}, domain)
e ->
Logger.warn("Error obtaining SSL certificate for #{domain.domain}: #{inspect(e)}")
end
end
:ok

View File

@ -46,4 +46,18 @@ defmodule Plausible.Workers.SslCertificatesTest do
domain = Repo.get_by(Plausible.Site.CustomDomain, site_id: site.id)
refute domain.has_ssl_certificate
end
test "does not set has_ssl_certficate=true if the ssh command errors completely" do
site = insert(:site)
insert(:custom_domain, site: site, domain: "custom-site.com")
ssh_stub =
stub(SSHEx, :connect, fn _cmd -> {:ok, nil} end)
|> stub(:run, fn _conn, _cmd, _opts -> {:error, "msg"} end)
ProvisionSslCertificates.perform(nil, ssh_stub)
domain = Repo.get_by(Plausible.Site.CustomDomain, site_id: site.id)
refute domain.has_ssl_certificate
end
end