Add buttons to run 'git gc' and 'git fetch' manually

This commit is contained in:
Aaron Bieber 2023-06-16 14:51:10 -06:00
parent f152755c96
commit 372b5a58c4
No known key found for this signature in database
3 changed files with 496 additions and 211 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
result result
.pls_cache .pls_cache
elm-stuff elm-stuff
tags

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ import Html.Styled exposing (..)
import Html.Styled.Attributes exposing (css, href, placeholder, style) import Html.Styled.Attributes exposing (css, href, placeholder, style)
import Html.Styled.Events exposing (onClick, onInput) import Html.Styled.Events exposing (onClick, onInput)
import Http exposing (..) import Http exposing (..)
import Json.Decode as Decode exposing (Decoder, field, list, map6, string) import Json.Decode as Decode exposing (Decoder, field, list, map2, map6, string)
type Status type Status
@ -15,16 +15,32 @@ type Status
| Open | Open
type WorkAction
= NoOp
| GC
| Update
type Msg type Msg
= RunSearch = RunSearch
| GotResult (Result Http.Error Model) | GotResult (Result Http.Error Model)
| GCResult (Result Http.Error WorkStatus)
| UpdateResult (Result Http.Error WorkStatus)
| SetPR String | SetPR String
| UpdateBackend
| CollectGarbage
type alias Branches = type alias Branches =
List String List String
type alias WorkStatus =
{ action : WorkAction
, updateTime : Float
}
type alias Model = type alias Model =
{ pull_request : Int { pull_request : Int
, release : String , release : String
@ -33,6 +49,8 @@ type alias Model =
, branches : Branches , branches : Branches
, error : String , error : String
, loading : Bool , loading : Bool
, updateStatus : WorkStatus
, gcStatus : WorkStatus
} }
@ -65,11 +83,16 @@ httpErr error =
"Bad body: '" ++ body ++ "'" "Bad body: '" ++ body ++ "'"
loadingModel : Model
loadingModel =
{ initialModel | loading = True }
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update msg model = update msg model =
case msg of case msg of
RunSearch -> RunSearch ->
( { model | loading = True }, getResult model ) ( loadingModel, getResult model )
GotResult (Err err) -> GotResult (Err err) ->
( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none ) ( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none )
@ -77,6 +100,18 @@ update msg model =
GotResult (Ok pr) -> GotResult (Ok pr) ->
( pr, Cmd.none ) ( pr, Cmd.none )
GCResult (Err err) ->
( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none )
GCResult (Ok resp) ->
( { model | gcStatus = resp, loading = False }, Cmd.none )
UpdateResult (Err err) ->
( { model | error = "Error: " ++ httpErr err, loading = False }, Cmd.none )
UpdateResult (Ok resp) ->
( { model | updateStatus = resp, loading = False }, Cmd.none )
SetPR pr -> SetPR pr ->
( { model ( { model
| pull_request = | pull_request =
@ -90,6 +125,12 @@ update msg model =
, Cmd.none , Cmd.none
) )
CollectGarbage ->
( loadingModel, getGC )
UpdateBackend ->
( loadingModel, getUpdate )
initialModel : Model initialModel : Model
initialModel = initialModel =
@ -100,6 +141,14 @@ initialModel =
, branches = [] , branches = []
, error = "" , error = ""
, loading = False , loading = False
, updateStatus =
{ action = NoOp
, updateTime = 0.0
}
, gcStatus =
{ action = NoOp
, updateTime = 0.0
}
} }
@ -160,6 +209,25 @@ view model =
_ -> _ ->
span [ style "color" "red" ] [ text model.error ] span [ style "color" "red" ] [ text model.error ]
, hr [] []
, div []
[ button
[ onClick UpdateBackend
, Html.Styled.Attributes.disabled model.loading
]
[ text "Update Backend" ]
, button
[ onClick CollectGarbage
, Html.Styled.Attributes.disabled model.loading
]
[ text "Collect Garbage" ]
, p []
[ i []
[ viewWorkAction model.gcStatus
, viewWorkAction model.updateStatus
]
]
]
] ]
) )
] ]
@ -167,6 +235,19 @@ view model =
} }
viewWorkAction : WorkStatus -> Html Msg
viewWorkAction work =
case work.action of
NoOp ->
text ""
GC ->
text ("Garbage collection took: " ++ String.fromFloat work.updateTime ++ " seconds.")
Update ->
text ("Update took: " ++ String.fromFloat work.updateTime ++ " seconds.")
viewValidation : Model -> Bool viewValidation : Model -> Bool
viewValidation model = viewValidation model =
case model.pull_request of case model.pull_request of
@ -243,6 +324,49 @@ getResult model =
} }
getGC : Cmd Msg
getGC =
Http.get
{ url = "/gc"
, expect = Http.expectJson GCResult workStatusDecoder
}
getUpdate : Cmd Msg
getUpdate =
Http.get
{ url = "/update"
, expect = Http.expectJson UpdateResult workStatusDecoder
}
actionDecoder : Decoder WorkAction
actionDecoder =
Decode.string
|> Decode.andThen
(\str ->
case str of
"gc" ->
Decode.succeed GC
"update" ->
Decode.succeed Update
"" ->
Decode.succeed NoOp
_ ->
Decode.fail "invalid action"
)
workStatusDecoder : Decoder WorkStatus
workStatusDecoder =
map2 WorkStatus
(field "action" actionDecoder)
(field "updateTime" Decode.float)
resultDecoder : Decoder Model resultDecoder : Decoder Model
resultDecoder = resultDecoder =
map6 map6
@ -254,6 +378,8 @@ resultDecoder =
, branches = branches , branches = branches
, error = error , error = error
, loading = False , loading = False
, updateStatus = initialModel.updateStatus
, gcStatus = initialModel.gcStatus
} }
) )
(field "pull_request" Decode.int) (field "pull_request" Decode.int)