-
Notifications
You must be signed in to change notification settings - Fork 1
/
sessions.go
48 lines (43 loc) · 1.52 KB
/
sessions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"log"
"time"
"github.com/rothskeller/wppsvr/report"
"github.com/rothskeller/wppsvr/retrieve"
"github.com/rothskeller/wppsvr/store"
)
// closeSessions closes any sessions that are past their end time and sends
// reports for them.
func closeSessions(st *store.Store) {
var now = time.Now()
for _, session := range st.GetRunningSessions() {
if session.End.Before(now) {
session.Flags &^= store.Running
st.UpdateSession(session)
log.Printf("Closed session for %s ending %s.", session.Name, session.End.Format("2006-01-02 15:04"))
if len(session.ReportToText) != 0 || len(session.ReportToHTML) != 0 || st.SessionHasMessages(session.ID) {
var conn = retrieve.ConnectToBBS(session.ToBBSes[0], session.CallSign)
report.Send(st, conn, session)
conn.Close()
}
}
}
}
// openSessions marks as "running" any sessions that encompass the current time
// and are not already running.
func openSessions(st *store.Store) {
// Sessions generally run for a week, so it suffices to look for an end
// date between now and a week from now. However, for safety's sake,
// we'll make it a month.
start := time.Now()
end := start.AddDate(0, 1, 0)
for _, session := range st.GetSessions(start, end) {
if session.Flags&store.Running != 0 || session.Start.After(start) {
continue
}
// We found a session that should be started.
session.Flags |= store.Running
st.UpdateSession(session)
log.Printf("Opened session for %s ending %s.", session.Name, session.End.Format("2006-01-02 15:04"))
}
}