Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
a3452842
Unverified
Commit
a3452842
authored
5 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
Better error handling when saving TaskHistory fails
parent
97e59153
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/metabase/models/task_history.clj
+16
-10
16 additions, 10 deletions
src/metabase/models/task_history.clj
src/metabase/sync/util.clj
+14
-11
14 additions, 11 deletions
src/metabase/sync/util.clj
src/metabase/task/task_history_cleanup.clj
+1
-1
1 addition, 1 deletion
src/metabase/task/task_history_cleanup.clj
with
31 additions
and
22 deletions
src/metabase/models/task_history.clj
+
16
−
10
View file @
a3452842
(
ns
metabase.models.task-history
(
:require
[
metabase.models.interface
:as
i
]
(
:require
[
clojure.tools.logging
:as
log
]
[
metabase.models.interface
:as
i
]
[
metabase.util
:as
u
]
[
metabase.util
[
date
:as
du
]
[
i18n
:refer
[
trs
]]
[
schema
:as
su
]]
[
schema.core
:as
s
]
[
toucan
...
...
@@ -20,9 +22,9 @@
;; the date that task finished, it deletes everything after that. As we continue to add TaskHistory entries, this
;; ensures we'll have a good amount of history for debugging/troubleshooting, but not grow too large and fill the
;; disk.
(
when-let
[
clean-before-date
(
db/select-one-field
:ended_at
TaskHistory
{
:limit
1
:offset
num-rows-to-keep
:order-by
[[
:ended_at
:desc
]]})]
(
when-let
[
clean-before-date
(
db/select-one-field
:ended_at
TaskHistory
{
:limit
1
:offset
num-rows-to-keep
:order-by
[[
:ended_at
:desc
]]})]
(
db/simple-delete!
TaskHistory
:ended_at
[
:<=
clean-before-date
])))
(
u/strict-extend
(
class
TaskHistory
)
...
...
@@ -36,7 +38,7 @@
(
s/defn
all
"Return all TaskHistory entries, applying `limit` and `offset` if not nil"
[
limit
:-
(
s/maybe
su/IntGreaterThanZero
)
[
limit
:-
(
s/maybe
su/IntGreaterThanZero
)
offset
:-
(
s/maybe
su/IntGreaterThanOrEqualToZero
)]
(
db/select
TaskHistory
(
merge
{
:order-by
[[
:ended_at
:desc
]]}
(
when
limit
...
...
@@ -58,11 +60,14 @@
(
defn-
save-task-history!
[
start-time-ms
info
]
(
let
[
end-time-ms
(
System/currentTimeMillis
)
duration-ms
(
-
end-time-ms
start-time-ms
)]
(
db/insert!
TaskHistory
(
assoc
info
:started_at
(
du/->Timestamp
start-time-ms
)
:ended_at
(
du/->Timestamp
end-time-ms
)
:duration
duration-ms
))))
(
try
(
db/insert!
TaskHistory
(
assoc
info
:started_at
(
du/->Timestamp
start-time-ms
)
:ended_at
(
du/->Timestamp
end-time-ms
)
:duration
duration-ms
))
(
catch
Throwable
e
(
log/warn
e
(
trs
"Error saving task history"
))))))
(
s/defn
do-with-task-history
"Impl for `with-task-history` macro; see documentation below."
...
...
@@ -85,6 +90,7 @@
"Execute `body`, recording a TaskHistory entry when the task completes; if it failed to complete, records an entry
containing information about the Exception. `info` should contain at least a name for the task (conventionally
lisp-cased) as `:task`; see the `TaskHistoryInfo` schema in this namespace for other optional keys.
(with-task-history {:task \"send-pulses\"}
...)"
{
:style/indent
1
}
...
...
This diff is collapsed.
Click to expand it.
src/metabase/sync/util.clj
+
14
−
11
View file @
a3452842
...
...
@@ -411,23 +411,26 @@
[
task-name
:-
su/NonBlankString
database
:-
i/DatabaseInstance
{
:keys
[
start-time
end-time
]}
:-
SyncOperationOrStepRunMetadata
]
{
:task
task-name
:db_id
(
u/get-id
database
)
{
:task
task-name
:db_id
(
u/get-id
database
)
:started_at
(
du/->Timestamp
start-time
)
:ended_at
(
du/->Timestamp
end-time
)
:duration
(
du/calculate-duration
start-time
end-time
)})
:ended_at
(
du/->Timestamp
end-time
)
:duration
(
du/calculate-duration
start-time
end-time
)})
(
s/defn
^
:private
store-sync-summary!
[
operation
:-
s/Str
database
:-
i/DatabaseInstance
{
:keys
[
steps
]
:as
sync-md
}
:-
SyncOperationMetadata
]
(
db/insert-many!
TaskHistory
(
cons
(
create-task-history
operation
database
sync-md
)
(
for
[[
step-name
step-info
]
steps
:let
[
task-details
(
dissoc
step-info
:start-time
:end-time
:log-summary-fn
)]]
(
assoc
(
create-task-history
step-name
database
step-info
)
:task_details
(
when
(
seq
task-details
)
task-details
))))))
(
try
(
db/insert-many!
TaskHistory
(
cons
(
create-task-history
operation
database
sync-md
)
(
for
[[
step-name
step-info
]
steps
:let
[
task-details
(
dissoc
step-info
:start-time
:end-time
:log-summary-fn
)]]
(
assoc
(
create-task-history
step-name
database
step-info
)
:task_details
(
when
(
seq
task-details
)
task-details
)))))
(
catch
Throwable
e
(
log/warn
e
(
trs
"Error saving task history"
)))))
(
s/defn
run-sync-operation
"Run `sync-steps` and log a summary message"
...
...
This diff is collapsed.
Click to expand it.
src/metabase/task/task_history_cleanup.clj
+
1
−
1
View file @
a3452842
...
...
@@ -9,7 +9,7 @@
[
metabase.util.i18n
:refer
[
trs
]]))
(
def
^
:private
history-rows-to-keep
"Maximum number of TaskHistory rows.
This is not a `const` so that we can redef it in tests
"
"Maximum number of TaskHistory rows."
100000
)
(
defn-
task-history-cleanup!
[]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment