Skip to content

Commit

Permalink
Fixed retry functionality in the job dashboard not working. Fixes #1167
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Nov 6, 2021
1 parent 0734fe0 commit 2725656
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions IHP/Job/Dashboard.hs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ class JobsDashboard (jobs :: [*]) where
deleteJob :: (?context :: ControllerContext, ?modelContext :: ModelContext) => Text -> UUID -> IO ()
deleteJob' :: (?context :: ControllerContext, ?modelContext :: ModelContext) => Bool -> IO ()

retryJob :: (?context :: ControllerContext, ?modelContext :: ModelContext) => Text -> UUID -> IO ()
retryJob' :: (?context :: ControllerContext, ?modelContext :: ModelContext) => IO ()

-- If no types are passed, try to get all tables dynamically and render them as BaseJobs
instance JobsDashboard '[] where

Expand Down Expand Up @@ -204,6 +207,16 @@ instance JobsDashboard '[] where
redirectTo ListJobsAction

where delete id table = sqlExec (PG.Query $ cs $ "DELETE FROM " <> table <> " WHERE id = ?") (Only id)

retryJob = error "retryJob: Requested job type not in JobsDashboard Type"
retryJob' = do
let id :: UUID = param "id"
table :: Text = param "tableName"
retryJobById table id
setSuccessMessage (columnNameToFieldLabel table <> " record deleted.")
redirectTo ListJobsAction

where retryJobById table id = sqlExec ("UPDATE ? SET status = 'job_status_retry' WHERE id = ?") (PG.Identifier table, id)


-- | Defines the default implementation for a dashboard of a list of job types.
Expand Down Expand Up @@ -372,4 +385,5 @@ instance (JobsDashboard jobs, AuthenticationMethod authType) => Controller (Jobs
action ViewJobAction' = autoRefresh $ viewJob' @jobs True
action CreateJobAction' = newJob' @jobs True
action DeleteJobAction' = deleteJob' @jobs True
action RetryJobAction' = retryJob' @jobs
action _ = error "Cannot call this action directly. Call the backtick function with no parameters instead."
4 changes: 4 additions & 0 deletions IHP/Job/Dashboard/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ data JobsDashboardController authType (jobs :: [*])
| ViewJobAction { jobTableName :: Text, jobId :: UUID }
| CreateJobAction { jobTableName :: Text }
| DeleteJobAction { jobTableName :: Text, jobId :: UUID }
| RetryJobAction { jobTableName :: Text, jobId :: UUID }

-- These actions are used for interal routing. Parameters are extracted dynamically in the action based on types
| ListJobAction'
| ViewJobAction'
| CreateJobAction'
| DeleteJobAction'
| RetryJobAction'
deriving (Show, Eq, Data)


Expand All @@ -99,6 +101,7 @@ instance HasPath (JobsDashboardController authType jobs) where
pathTo ViewJobAction { .. } = "/jobs/ViewJob?tableName=" <> jobTableName <> "&id=" <> tshow jobId
pathTo CreateJobAction { .. } = "/jobs/CreateJob?tableName=" <> jobTableName
pathTo DeleteJobAction { .. } = "/jobs/DeleteJob?tableName=" <> jobTableName <> "&id=" <> tshow jobId
pathTo RetryJobAction { .. } = "/jobs/RetryJob?tableName=" <> jobTableName <> "&id=" <> tshow jobId
pathTo _ = error "pathTo for internal JobsDashboard functions not supported. Use non-backtick action and pass necessary parameters to use pathTo."

instance CanRoute (JobsDashboardController authType jobs) where
Expand All @@ -110,4 +113,5 @@ instance CanRoute (JobsDashboardController authType jobs) where
<|> (string "/jobs/ViewJob" <* endOfInput >> pure ViewJobAction')
<|> (string "/jobs/CreateJob" <* endOfInput >> pure CreateJobAction')
<|> (string "/jobs/DeleteJob" <* endOfInput >> pure DeleteJobAction')
<|> (string "/jobs/RetryJob" <* endOfInput >> pure RetryJobAction')

2 changes: 1 addition & 1 deletion IHP/Job/Dashboard/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ renderBaseJobTableRow job = [hsx|
<td>{renderStatus job}</td>
<td><a href={ViewJobAction (get #table job) (get #id job)} class="text-primary">Show</a></td>
<td>
<form action={CreateJobAction (get #table job)} method="POST">
<form action={RetryJobAction (get #table job) (get #id job)} method="POST">
<button type="submit" style={retryButtonStyle} class="btn btn-link text-secondary">Retry</button>
</form>
</td>
Expand Down

0 comments on commit 2725656

Please sign in to comment.