Skip to content

add retry delay #2309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/swagger/collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3321,6 +3321,8 @@ components:
type: integer
max_msg_retries:
type: integer
retry_delay:
type: string
idle_timeout:
type: string
wait_timeout:
Expand Down Expand Up @@ -3355,6 +3357,8 @@ components:
type: integer
max_msg_retries:
type: integer
retry_delay:
type: string
idle_timeout:
type: string
wait_timeout:
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/views/settings/messengers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
controls-position="compact" placeholder="2" min="1" max="1000" />
</b-field>
</div>
</div>
<div class="column is-4">
<b-field :label="$t('settings.messengers.retryDelay')" label-position="on-border"
:message="$t('settings.messengers.retryDelayHelp')">
<b-input v-model="item.retry_delay" name="retry_delay" placeholder="15s" :pattern="regDuration"
:maxlength="10" />
</b-field>
<div class="column is-4">
<b-field :label="$t('settings.messengers.timeout')" label-position="on-border"
:message="$t('settings.messengers.timeoutHelp')">
Expand Down Expand Up @@ -111,6 +118,7 @@ export default Vue.extend({
password: '',
max_conns: 25,
max_msg_retries: 2,
retry_delay: '15s',
timeout: '5s',
});

Expand Down
8 changes: 8 additions & 0 deletions frontend/src/views/settings/smtp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,13 @@
controls-position="compact" placeholder="2" min="1" max="1000" />
</b-field>
</div>
<div class="column is-3">
<b-field :label="$t('settings.smtp.retryDelay')" label-position="on-border"
:message="$t('settings.smtp.retryDelay')">
<b-input v-model="item.retry_delay" name="retry_delay" placeholder="15s" :pattern="regDuration"
:maxlength="10" />
</b-field>
</div>
<div class="column is-3">
<b-field :label="$t('settings.mailserver.idleTimeout')" label-position="on-border"
:message="$t('settings.mailserver.idleTimeoutHelp')">
Expand Down Expand Up @@ -271,6 +278,7 @@ export default Vue.extend({
email_headers: [],
max_conns: 10,
max_msg_retries: 2,
retry_delay: '15s',
idle_timeout: '15s',
wait_timeout: '5s',
tls_type: 'STARTTLS',
Expand Down
4 changes: 4 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@
"settings.messengers.password": "Password",
"settings.messengers.retries": "Retries",
"settings.messengers.retriesHelp": "Number of times to retry when a message fails.",
"settings.messengers.retryDelay": "Retry delay",
"settings.messengers.retryDelayHelp": "Time to wait between retries.",
"settings.messengers.skipTLSHelp": "Skip hostname check on the TLS certificate.",
"settings.messengers.timeout": "Idle timeout",
"settings.messengers.timeoutHelp": "Time to wait for new activity on a connection before closing it and removing it from the pool (s for second, m for minute).",
Expand Down Expand Up @@ -538,6 +540,8 @@
"settings.smtp.name": "SMTP",
"settings.smtp.retries": "Retries",
"settings.smtp.retriesHelp": "Number of times to retry when a message fails.",
"settings.smtp.retryDelay": "Retry delay",
"settings.smtp.retryDelayHelp": "Time to wait between retries.",
"settings.smtp.sendTest": "Send e-mail",
"settings.smtp.setCustomHeaders": "Set custom headers",
"settings.smtp.testConnection": "Test connection",
Expand Down
13 changes: 13 additions & 0 deletions internal/messenger/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@
return nil
}

// Retrieve the retry delay from the configuration
retryDelay := time.Duration(config.RetryDelay) * time.Second

Check failure on line 194 in internal/messenger/email/email.go

View workflow job for this annotation

GitHub Actions / build

syntax error: non-declaration statement outside function body

// Implement retry logic
var err error
for i := 0; i < maxRetries; i++ {

Check failure on line 198 in internal/messenger/email/email.go

View workflow job for this annotation

GitHub Actions / build

syntax error: non-declaration statement outside function body
err = sendSMTPMail(...)
if err == nil {
break
}
time.Sleep(retryDelay) // Wait for the retry delay before the next attempt
}

// Close closes the SMTP pools.
func (e *Emailer) Close() error {
for _, s := range e.servers {
Expand Down
2 changes: 2 additions & 0 deletions models/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Settings struct {
EmailHeaders []map[string]string `json:"email_headers"`
MaxConns int `json:"max_conns"`
MaxMsgRetries int `json:"max_msg_retries"`
RetryDelay string `json:"retry_delay"`
IdleTimeout string `json:"idle_timeout"`
WaitTimeout string `json:"wait_timeout"`
TLSType string `json:"tls_type"`
Expand All @@ -91,6 +92,7 @@ type Settings struct {
MaxConns int `json:"max_conns"`
Timeout string `json:"timeout"`
MaxMsgRetries int `json:"max_msg_retries"`
RetryDelay string `json:"retry_delay"`
} `json:"messengers"`

BounceEnabled bool `json:"bounce.enabled"`
Expand Down
4 changes: 2 additions & 2 deletions schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ INSERT INTO settings (key, value) VALUES
('upload.s3.bucket_type', '"public"'),
('upload.s3.expiry', '"167h"'),
('smtp',
'[{"enabled":true, "host":"smtp.yoursite.com","port":25,"auth_protocol":"cram","username":"username","password":"password","hello_hostname":"","max_conns":10,"idle_timeout":"15s","wait_timeout":"5s","max_msg_retries":2,"tls_type":"STARTTLS","tls_skip_verify":false,"email_headers":[]},
{"enabled":false, "host":"smtp.gmail.com","port":465,"auth_protocol":"login","username":"[email protected]","password":"password","hello_hostname":"","max_conns":10,"idle_timeout":"15s","wait_timeout":"5s","max_msg_retries":2,"tls_type":"TLS","tls_skip_verify":false,"email_headers":[]}]'),
'[{"enabled":true, "host":"smtp.yoursite.com","port":25,"auth_protocol":"cram","username":"username","password":"password","hello_hostname":"","max_conns":10,"idle_timeout":"15s","wait_timeout":"5s","max_msg_retries":2,"retry_delay":"15s","tls_type":"STARTTLS","tls_skip_verify":false,"email_headers":[]},
{"enabled":false, "host":"smtp.gmail.com","port":465,"auth_protocol":"login","username":"[email protected]","password":"password","hello_hostname":"","max_conns":10,"idle_timeout":"15s","wait_timeout":"5s","max_msg_retries":2,"retry_delay":"15s","tls_type":"TLS","tls_skip_verify":false,"email_headers":[]}]'),
('messengers', '[]'),
('bounce.enabled', 'false'),
('bounce.webhooks_enabled', 'false'),
Expand Down
Loading