Skip to content
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Integration Test

on:
pull_request:
branches: [ "main" ]

jobs:
integration-test:
runs-on: ubuntu-latest
steps:
- name: Trigger and wait for integration test
env:
GH_TOKEN: ${{ secrets.FMSG_DOCKER_PAT }}
run: |
FMSGD_REF="${{ github.event.pull_request.head.ref }}"

# Trigger the integration test workflow in fmsg-docker,
# passing the PR branch so it builds fmsgd from the PR
gh workflow run integration-test.yml \
--repo markmnl/fmsg-docker \
--ref main \
-f fmsgd_ref="$FMSGD_REF"

echo "Triggered integration test for fmsgd_ref=$FMSGD_REF, polling for run..."

# Poll until we find the run matching our fmsgd_ref
RUN_ID=""
for i in $(seq 1 30); do
sleep 10
RUN_ID=$(gh run list \
--repo markmnl/fmsg-docker \
--workflow integration-test.yml \
--limit 10 \
--json databaseId,displayTitle \
--jq ".[] | select(.displayTitle | contains(\"$FMSGD_REF\")) | .databaseId" \
| head -1)
if [ -n "$RUN_ID" ]; then
break
fi
echo "Attempt $i: run not found yet..."
done

if [ -z "$RUN_ID" ]; then
echo "::error::Timed out waiting for integration test run to appear"
exit 1
fi

echo "Found run $RUN_ID, waiting for completion..."

# Wait for completion and exit with its status
gh run watch "$RUN_ID" \
--repo markmnl/fmsg-docker \
--exit-status
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
PRs are welcome!

Please create a GitHub issue to discuss and relate a PR to that issue.
* Create a GitHub issue to discuss and relate a PR to that issue.
* Tests must pass
* Codeowner must approve
5 changes: 3 additions & 2 deletions dd.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ create table if not exists msg (
version int not null,
pid bigint references msg (id),
flags int not null,
time_sent double precision not null, -- time sending host recieved message for sending, message timestamp field
time_sent double precision, -- time sending host recieved message for sending, message timestamp field, NULL means message not ready for sending i.e. draft
from_addr varchar(255) not null,
topic varchar(255) not null,
type varchar(255) not null,
Expand Down Expand Up @@ -46,7 +46,8 @@ create table if not exists msg_attachment (
create or replace function notify_msg_to_insert() returns trigger as $$
begin
if NEW.time_delivered is null then
perform pg_notify('new_msg_to', NEW.msg_id::text || ',' || NEW.addr);
perform pg_notify('new_msg_to', NEW.msg_id::text || ',' || NEW.addr)
from msg where id = NEW.msg_id and time_sent is not null;
end if;
return NEW;
end;
Expand Down
2 changes: 2 additions & 0 deletions src/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func findPendingTargets() ([]pendingTarget, error) {
FROM msg_to mt
INNER JOIN msg m ON m.id = mt.msg_id
WHERE mt.time_delivered IS NULL
AND m.time_sent IS NOT NULL
AND (mt.response_code IS NULL OR mt.response_code IN (3, 5))
AND (mt.time_last_attempt IS NULL OR ($1 - mt.time_last_attempt) > $2)
AND ($1 - m.time_sent) < $3
Expand Down Expand Up @@ -149,6 +150,7 @@ func deliverMessage(target pendingTarget) {
INNER JOIN msg m ON m.id = mt.msg_id
WHERE mt.msg_id = $1
AND mt.time_delivered IS NULL
AND m.time_sent IS NOT NULL
AND (mt.response_code IS NULL OR mt.response_code IN (3, 5))
AND (mt.time_last_attempt IS NULL OR ($2 - mt.time_last_attempt) > $3)
AND ($2 - m.time_sent) < $4
Expand Down
Loading