55 "flag"
66 "net/http"
77 "os"
8+ "sync"
89
910 "github.com/jmhodges/clock"
1011
@@ -78,6 +79,21 @@ type Config struct {
7879 // in this file must be identical to those in the RA.
7980 Defaults string `validate:"required_with=Redis"`
8081 }
82+
83+ // OverridesImporter configures the periodic import of approved rate
84+ // limit override requests from Zendesk.
85+ OverridesImporter struct {
86+ // Mode controls which tickets are processed. Valid values are:
87+ // - "all": process all tickets
88+ // - "even": process only tickets with even IDs
89+ // - "odd": process only tickets with odd IDs
90+ // If unspecified or empty, defaults to "all".
91+ Mode string `validate:"omitempty,required_with=Interval,oneof=all even odd"`
92+ // Interval is the amount of time between runs of the importer. If
93+ // zero or unspecified, the importer is disabled. Minimum value is
94+ // 20 minutes.
95+ Interval config.Duration `validate:"omitempty,required_with=Mode,min=1200s"`
96+ } `validate:"omitempty,dive"`
8197 Features features.Config
8298 }
8399
@@ -141,6 +157,8 @@ func main() {
141157 }
142158
143159 var zendeskClient * zendesk.Client
160+ var overridesImporterShutdown func ()
161+ var overridesImporterWG sync.WaitGroup
144162 if c .SFE .Zendesk != nil {
145163 zendeskToken , err := c .SFE .Zendesk .Token .Pass ()
146164 cmd .FailOnError (err , "Failed to load Zendesk token" )
@@ -162,6 +180,30 @@ func main() {
162180 if err != nil {
163181 cmd .FailOnError (err , "Failed to create Zendesk client" )
164182 }
183+
184+ if c .SFE .OverridesImporter .Interval .Duration > 0 {
185+ mode := sfe .ProcessMode (c .SFE .OverridesImporter .Mode )
186+ if mode == "" {
187+ mode = sfe .ProcessAll
188+ }
189+
190+ importer , err := sfe .NewOverridesImporter (
191+ mode ,
192+ c .SFE .OverridesImporter .Interval .Duration ,
193+ zendeskClient ,
194+ rac ,
195+ clk ,
196+ logger ,
197+ )
198+ cmd .FailOnError (err , "Creating overrides importer" )
199+
200+ var ctx context.Context
201+ ctx , overridesImporterShutdown = context .WithCancel (context .Background ())
202+ overridesImporterWG .Go (func () {
203+ importer .Start (ctx )
204+ })
205+ logger .Infof ("Overrides importer started with mode=%s interval=%s" , mode , c .SFE .OverridesImporter .Interval .Duration )
206+ }
165207 }
166208
167209 var limiter * ratelimits.Limiter
@@ -211,6 +253,10 @@ func main() {
211253 defer func () {
212254 ctx , cancel := context .WithTimeout (context .Background (), c .SFE .ShutdownStopTimeout .Duration )
213255 defer cancel ()
256+ if overridesImporterShutdown != nil {
257+ overridesImporterShutdown ()
258+ overridesImporterWG .Wait ()
259+ }
214260 _ = srv .Shutdown (ctx )
215261 oTelShutdown (ctx )
216262 }()
0 commit comments