1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

queue: Implement persistency

This patch makes the queue read and write items to disk.

It uses protobuf for serialization. We serialize to text format to make
manual troubleshooting easier, as the performance difference is not very
relevant for us.
This commit is contained in:
Alberto Bertogli
2016-09-18 06:13:42 +01:00
parent 9ed30a747b
commit aacf8ffea7
11 changed files with 457 additions and 64 deletions

View File

@@ -0,0 +1,52 @@
// addtoqueue is a test helper which adds a queue item directly to the queue
// directory, behind chasquid's back.
//
// Note that chasquid does NOT support this, we do it before starting up the
// daemon for testing purposes only.
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"time"
"blitiri.com.ar/go/chasquid/internal/queue"
)
var (
queueDir = flag.String("queue_dir", ".queue", "queue directory")
id = flag.String("id", "mid1234", "Message ID")
from = flag.String("from", "from", "Mail from")
rcpt = flag.String("rcpt", "rcpt", "Rcpt to")
)
func main() {
flag.Parse()
data, err := ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Printf("error reading data: %v\n", err)
os.Exit(1)
}
item := &queue.Item{
Message: queue.Message{
ID: *id,
From: *from,
Rcpt: []*queue.Recipient{
{*rcpt, queue.Recipient_EMAIL, queue.Recipient_PENDING},
},
Data: data,
},
CreatedAt: time.Now(),
}
os.MkdirAll(*queueDir, 0700)
err = item.WriteTo(*queueDir)
if err != nil {
fmt.Printf("error writing item: %v\n", err)
os.Exit(1)
}
}

View File

@@ -0,0 +1,8 @@
smtp_address: ":1025"
submission_address: ":1587"
monitoring_address: ":1099"
mail_delivery_agent_bin: "test-mda"
mail_delivery_agent_args: "%user%@%domain%"
data_dir: "../.data"

View File

@@ -0,0 +1,4 @@
Subject: Prueba desde el test
Crece desde el test el futuro
Crece desde el test

View File

@@ -0,0 +1 @@
testserver localhost

View File

@@ -0,0 +1,25 @@
#!/bin/bash
set -e
. $(dirname ${0})/../util/lib.sh
init
# Add an item to the queue before starting chasquid.
go run addtoqueue.go --queue_dir=.data/queue \
--from someone@testserver \
--rcpt someone@testserver \
< content
generate_certs_for testserver
mkdir -p .logs
chasquid -v=2 --log_dir=.logs --config_dir=config &
wait_until_ready 1025
# Check that the item in the queue was delivered.
wait_for_file .mail/someone@testserver
mail_diff content .mail/someone@testserver
success