MCPcopy Create free account
hub / github.com/daodst/chat / NewOutgoingQueues

Function NewOutgoingQueues

federationapi/queue/queue.go:84–134  ·  view source on GitHub ↗

NewOutgoingQueues makes a new OutgoingQueues

(
	db storage.Database,
	process *process.ProcessContext,
	disabled bool,
	origin gomatrixserverlib.ServerName,
	client fedapi.FederationClient,
	rsAPI api.FederationRoomserverAPI,
	statistics *statistics.Statistics,
	signing *SigningInfo,
)

Source from the content-addressed store, hash-verified

82
83// NewOutgoingQueues makes a new OutgoingQueues
84func NewOutgoingQueues(
85 db storage.Database,
86 process *process.ProcessContext,
87 disabled bool,
88 origin gomatrixserverlib.ServerName,
89 client fedapi.FederationClient,
90 rsAPI api.FederationRoomserverAPI,
91 statistics *statistics.Statistics,
92 signing *SigningInfo,
93) *OutgoingQueues {
94 queues := &OutgoingQueues{
95 disabled: disabled,
96 process: process,
97 db: db,
98 rsAPI: rsAPI,
99 origin: origin,
100 client: client,
101 statistics: statistics,
102 signing: signing,
103 queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
104 }
105 // Look up which servers we have pending items for and then rehydrate those queues.
106 if !disabled {
107 serverNames := map[gomatrixserverlib.ServerName]struct{}{}
108 if names, err := db.GetPendingPDUServerNames(process.Context()); err == nil {
109 for _, serverName := range names {
110 serverNames[serverName] = struct{}{}
111 }
112 } else {
113 log.WithError(err).Error("Failed to get PDU server names for destination queue hydration")
114 }
115 if names, err := db.GetPendingEDUServerNames(process.Context()); err == nil {
116 for _, serverName := range names {
117 serverNames[serverName] = struct{}{}
118 }
119 } else {
120 log.WithError(err).Error("Failed to get EDU server names for destination queue hydration")
121 }
122 offset, step := time.Second*5, time.Second
123 if max := len(serverNames); max > 120 {
124 step = (time.Second * 120) / time.Duration(max)
125 }
126 for serverName := range serverNames {
127 if queue := queues.getQueue(serverName); queue != nil {
128 time.AfterFunc(offset, queue.wakeQueueIfNeeded)
129 offset += step
130 }
131 }
132 }
133 return queues
134}
135
136// TODO: Move this somewhere useful for other components as we often need to ferry these 3 variables
137// around together

Callers

nothing calls this directly

Calls 5

getQueueMethod · 0.95
ContextMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected