New creates a new chat processor. The processor polls for pending chats and processes them. It is the caller's responsibility to call Close on the returned instance.
(cfg Config)
| 4200 | // chats and processes them. It is the caller's responsibility to call Close |
| 4201 | // on the returned instance. |
| 4202 | func New(cfg Config) *Server { |
| 4203 | ctx, cancel := context.WithCancel(context.Background()) |
| 4204 | |
| 4205 | pendingChatAcquireInterval := cfg.PendingChatAcquireInterval |
| 4206 | if pendingChatAcquireInterval == 0 { |
| 4207 | pendingChatAcquireInterval = DefaultPendingChatAcquireInterval |
| 4208 | } |
| 4209 | |
| 4210 | inFlightChatStaleAfter := cfg.InFlightChatStaleAfter |
| 4211 | if inFlightChatStaleAfter == 0 { |
| 4212 | inFlightChatStaleAfter = DefaultInFlightChatStaleAfter |
| 4213 | } |
| 4214 | |
| 4215 | maxChatsPerAcquire := cfg.MaxChatsPerAcquire |
| 4216 | if maxChatsPerAcquire <= 0 { |
| 4217 | maxChatsPerAcquire = DefaultMaxChatsPerAcquire |
| 4218 | } |
| 4219 | |
| 4220 | chatHeartbeatInterval := cfg.ChatHeartbeatInterval |
| 4221 | if chatHeartbeatInterval == 0 { |
| 4222 | chatHeartbeatInterval = DefaultChatHeartbeatInterval |
| 4223 | } |
| 4224 | |
| 4225 | clk := cfg.Clock |
| 4226 | if clk == nil { |
| 4227 | clk = quartz.NewReal() |
| 4228 | } |
| 4229 | |
| 4230 | instructionLookupTimeout := cfg.InstructionLookupTimeout |
| 4231 | if instructionLookupTimeout == 0 { |
| 4232 | instructionLookupTimeout = homeInstructionLookupTimeout |
| 4233 | } |
| 4234 | |
| 4235 | workerID := cfg.ReplicaID |
| 4236 | if workerID == uuid.Nil { |
| 4237 | workerID = uuid.New() |
| 4238 | } |
| 4239 | |
| 4240 | allowBYOK := true |
| 4241 | if cfg.AllowBYOKSet { |
| 4242 | allowBYOK = cfg.AllowBYOK |
| 4243 | } |
| 4244 | |
| 4245 | p := &Server{ |
| 4246 | cancel: cancel, |
| 4247 | db: cfg.Database, |
| 4248 | workerID: workerID, |
| 4249 | logger: cfg.Logger.Named("processor"), |
| 4250 | subscribeFn: cfg.SubscribeFn, |
| 4251 | agentConnFn: cfg.AgentConn, |
| 4252 | agentInactiveDisconnectTimeout: cfg.AgentInactiveDisconnectTimeout, |
| 4253 | dialTimeout: defaultDialTimeout, |
| 4254 | instructionLookupTimeout: instructionLookupTimeout, |
| 4255 | createWorkspaceFn: cfg.CreateWorkspace, |
| 4256 | startWorkspaceFn: cfg.StartWorkspace, |
| 4257 | stopWorkspaceFn: cfg.StopWorkspace, |
| 4258 | pubsub: cfg.Pubsub, |
| 4259 | webpushDispatcher: cfg.WebpushDispatcher, |