Add scheduled tasks with a Project tab section and lead tools
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"g.fc.run/ai/byre/internal/api"
|
||||
)
|
||||
|
||||
func (s *Server) ListSchedules(w http.ResponseWriter, r *http.Request, projectID string) {
|
||||
list, err := s.store.ListSchedules(r.Context(), projectID)
|
||||
if err != nil {
|
||||
writeStoreError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, list)
|
||||
}
|
||||
|
||||
func (s *Server) CreateSchedule(w http.ResponseWriter, r *http.Request, projectID string) {
|
||||
s.saveSchedule(w, r, projectID, "", http.StatusCreated)
|
||||
}
|
||||
|
||||
func (s *Server) UpdateSchedule(w http.ResponseWriter, r *http.Request, scheduleID string) {
|
||||
s.saveSchedule(w, r, "", scheduleID, http.StatusOK)
|
||||
}
|
||||
|
||||
func (s *Server) saveSchedule(w http.ResponseWriter, r *http.Request, projectID, scheduleID string, status int) {
|
||||
req := api.ScheduleSave{}
|
||||
if !readJSON(w, r, &req) {
|
||||
return
|
||||
}
|
||||
sc, err := s.agents.SaveSchedule(r.Context(), projectID, scheduleID, req, actor(r), actor(r))
|
||||
if err != nil {
|
||||
writeAgentError(w, err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, status, sc)
|
||||
}
|
||||
|
||||
func (s *Server) DeleteSchedule(w http.ResponseWriter, r *http.Request, scheduleID string) {
|
||||
err := s.agents.DeleteSchedule(r.Context(), scheduleID, actor(r))
|
||||
if err != nil {
|
||||
writeAgentError(w, err)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
"g.fc.run/ai/byre/internal/clients"
|
||||
"g.fc.run/ai/byre/internal/git"
|
||||
"g.fc.run/ai/byre/internal/ids"
|
||||
"g.fc.run/ai/byre/internal/schedule"
|
||||
"g.fc.run/ai/byre/internal/store"
|
||||
"g.fc.run/ai/byre/internal/terminal"
|
||||
"g.fc.run/ai/byre/internal/todo"
|
||||
@@ -980,7 +981,7 @@ func writeAgentError(w http.ResponseWriter, err error) {
|
||||
writeError(w, http.StatusNotFound, err)
|
||||
case errors.Is(err, agents.ErrConflict):
|
||||
writeError(w, http.StatusConflict, err)
|
||||
case errors.Is(err, agents.ErrInvalid), errors.Is(err, agents.ErrNoGitIdentity), errors.Is(err, workflow.ErrInvalid):
|
||||
case errors.Is(err, agents.ErrInvalid), errors.Is(err, agents.ErrNoGitIdentity), errors.Is(err, workflow.ErrInvalid), errors.Is(err, schedule.ErrInvalid):
|
||||
writeError(w, http.StatusBadRequest, err)
|
||||
default:
|
||||
writeError(w, http.StatusInternalServerError, err)
|
||||
|
||||
Reference in New Issue
Block a user