[mirror] yet another tui rss reader github.com/olexsmir/smutok

fix(worker): start worker immediately

olexsmir.xyz d588b2a7 63bd5971

verified
Changed files
+20 -5
internal
+15 -2
internal/freshrss/client.go
··· 217 217 } 218 218 219 219 func (g Client) EditTag(ctx context.Context, writeToken string, opts EditTag) error { 220 + if len(opts.ItemID) == 0 { 221 + return ErrInvalidRequest 222 + } 223 + 220 224 body := url.Values{} 221 225 body.Set("T", writeToken) 222 226 setOption(&body, "a", opts.TagToAdd) ··· 250 254 Remove string 251 255 } 252 256 253 - func (g Client) SubscriptionEdit(ctx context.Context, token string, opts EditSubscription) (string, error) { 257 + func (g Client) SubscriptionEdit( 258 + ctx context.Context, 259 + token string, 260 + opts EditSubscription, 261 + ) (string, error) { 254 262 if opts.Action == "" { 255 263 return "", ErrInvalidRequest 256 264 } ··· 305 313 } 306 314 307 315 // postRequest makes POST requests with parameters passed as form. 308 - func (g *Client) postRequest(ctx context.Context, endpoint string, body url.Values, resp any) error { 316 + func (g *Client) postRequest( 317 + ctx context.Context, 318 + endpoint string, 319 + body url.Values, 320 + resp any, 321 + ) error { 309 322 var reqBody io.Reader 310 323 if body != nil { 311 324 reqBody = strings.NewReader(body.Encode())
+4 -2
internal/freshrss/worker.go
··· 25 25 } 26 26 27 27 func (w *Worker) Run(ctx context.Context) { 28 - // TODO: get tick time from config ??? 29 28 ticker := time.NewTicker(5 * time.Second) 30 29 defer ticker.Stop() 31 30 ··· 34 33 select { 35 34 case <-ctx.Done(): 36 35 return 37 - case <-ticker.C: 36 + default: 38 37 if !w.isNetworkAvailable(ctx) { 39 38 slog.Info("worker: no internet connection") 40 39 continue ··· 60 59 slog.Error("worker: unread", "err", err) 61 60 } 62 61 }) 62 + 63 63 wg.Wait() 64 + <-ticker.C 64 65 } 65 66 } 66 67 } ··· 97 98 } 98 99 99 100 if len(articleIDs) == 0 { 101 + slog.Debug("worker: no pending actions", "action", action) 100 102 return nil 101 103 } 102 104
+1 -1
internal/store/sqlite_pendin_actions.go
··· 67 67 from pending_actions 68 68 where action = ? 69 69 order by created_at desc 70 - limit 10` 70 + limit 20` 71 71 72 72 rows, err := s.db.QueryContext(ctx, query, action.String()) 73 73 if err != nil {