mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(feeds): add force run (#1243)
* feat(feeds): add force run * fix: simplify ForceRun * add confirmation modal * handle errors by using the test func * require user input to run * make sure to reschedule next job after forcerun * refactor modal centering with grid * refactor: Simplify startJob and forceRun logic - Refactor `startJob` to accept a `runImmediately` flag. This flag controls whether the job should be run immediately or scheduled for later. This change simplifies the `ForceRun` function by allowing it to call `startJob` with `runImmediately` set to `true`. - Remove redundant checks in `ForceRun` related to feed type. These checks are handled in `startJob`. BREAKING CHANGE: The `startJob` function now requires a second argument, `runImmediately`. This change affects all calls to `startJob`. * fix(web) Invalidate queries after forceRun * refactor(feeds): init and test run --------- Co-authored-by: ze0s <43699394+zze0s@users.noreply.github.com>
This commit is contained in:
parent
ff70a341ad
commit
2bd1a68a94
10 changed files with 318 additions and 38 deletions
|
@ -23,6 +23,7 @@ type feedService interface {
|
|||
ToggleEnabled(ctx context.Context, id int, enabled bool) error
|
||||
Test(ctx context.Context, feed *domain.Feed) error
|
||||
GetLastRunData(ctx context.Context, id int) (string, error)
|
||||
ForceRun(ctx context.Context, id int) error
|
||||
}
|
||||
|
||||
type feedHandler struct {
|
||||
|
@ -48,6 +49,7 @@ func (h feedHandler) Routes(r chi.Router) {
|
|||
r.Delete("/cache", h.deleteCache)
|
||||
r.Patch("/enabled", h.toggleEnabled)
|
||||
r.Get("/latest", h.latestRun)
|
||||
r.Post("/forcerun", h.forceRun)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -122,6 +124,24 @@ func (h feedHandler) update(w http.ResponseWriter, r *http.Request) {
|
|||
h.encoder.StatusResponse(w, http.StatusCreated, data)
|
||||
}
|
||||
|
||||
func (h feedHandler) forceRun(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
feedID := chi.URLParam(r, "feedID")
|
||||
|
||||
id, err := strconv.Atoi(feedID)
|
||||
if err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.service.ForceRun(ctx, id); err != nil {
|
||||
h.encoder.Error(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
h.encoder.StatusResponse(w, http.StatusNoContent, nil)
|
||||
}
|
||||
|
||||
func (h feedHandler) toggleEnabled(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue