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
2603f240
Unverified
Commit
2603f240
authored
5 months ago
by
Ngoc Khuat
Committed by
GitHub
5 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Do not clear http channels when sending pulse (#48330)
parent
3c16a1bd
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/task/send_pulses.clj
+8
-3
8 additions, 3 deletions
src/metabase/task/send_pulses.clj
test/metabase/channel/http_test.clj
+3
-3
3 additions, 3 deletions
test/metabase/channel/http_test.clj
test/metabase/task/send_pulses_test.clj
+64
-25
64 additions, 25 deletions
test/metabase/task/send_pulses_test.clj
with
75 additions
and
31 deletions
src/metabase/task/send_pulses.clj
+
8
−
3
View file @
2603f240
...
...
@@ -100,14 +100,19 @@
"Delete PulseChannels that have no recipients and no channel set for a pulse, returns the channel ids that were deleted."
[
pulse-id
]
(
when-let
[
ids-to-delete
(
seq
(
for
[
channel
(
t2/select
[
:model/PulseChannel
:id
:details
]
(
for
[
channel
(
t2/select
[
:model/PulseChannel
:id
:details
:channel_id
:channel_type
]
:pulse_id
pulse-id
:id
[
:not-in
{
:select
[[
:pulse_channel_id
:id
]]
:from
:pulse_channel_recipient
:group-by
[
:pulse_channel_id
]
:having
[
:>=
:%count.*
[
:raw
1
]]}])
:when
(
and
(
empty?
(
get-in
channel
[
:details
:emails
]))
(
not
(
get-in
channel
[
:details
:channel
])))]
:when
(
case
(
:channel_type
channel
)
:email
(
empty?
(
get-in
channel
[
:details
:emails
]))
:slack
(
empty?
(
get-in
channel
[
:details
:channel
]))
:http
(
nil?
(
:channel_id
channel
)))]
(
:id
channel
)))]
(
log/infof
"Deleting %d PulseChannels with id: %s due to having no recipients"
(
count
ids-to-delete
)
(
str/join
", "
ids-to-delete
))
(
t2/delete!
:model/PulseChannel
:id
[
:in
ids-to-delete
])
...
...
This diff is collapsed.
Click to expand it.
test/metabase/channel/http_test.clj
+
3
−
3
View file @
2603f240
...
...
@@ -7,7 +7,7 @@
[
compojure.core
:as
compojure
]
[
medley.core
:as
m
]
[
metabase.channel.core
:as
channel
]
[
metabase.pulse
:as
pulse
]
[
metabase.
task.send-
pulse
s
:as
task.send-
pulse
s
]
[
metabase.test
:as
mt
]
[
metabase.util.i18n
:refer
[
deferred-tru
]]
[
ring.adapter.jetty
:as
jetty
]
...
...
@@ -328,10 +328,10 @@
:model/Channel
{
chn-id
:id
}
{
:type
:channel/http
:details
{
:url
(
str
url
(
:path
receive-route
))
:auth-method
"none"
}}
:model/PulseChannel
_
{
:pulse_id
pulse-id
:model/PulseChannel
{
pc-id
:id
}
{
:pulse_id
pulse-id
:channel_type
"http"
:channel_id
chn-id
}]
(
pulse/send-pulse!
pulse
)
(
#
'task.send-
pulse
s
/send-pulse!
*
pulse
-id
[
pc-id
]
)
(
is
(
=?
{
:body
{
:type
"alert"
:alert_id
pulse-id
:alert_creator_id
(
mt/malli=?
int?
)
...
...
This diff is collapsed.
Click to expand it.
test/metabase/task/send_pulses_test.clj
+
64
−
25
View file @
2603f240
...
...
@@ -30,33 +30,72 @@
(
t2/count
PulseChannel
)))
(
is
(
:archived
(
t2/select-one
Pulse
:id
pulse-id
)))))
(
testing
"Has PulseChannelRecipient"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
{
pc-id
:id
}
{
:pulse_id
pulse-id
:channel_type
:email
}
PulseChannelRecipient
_
{
:user_id
(
mt/user->id
:rasta
)
:pulse_channel_id
pc-id
}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
PulseChannel
)))))
(
testing
"emails"
(
testing
"keep if has PulseChannelRecipient"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
{
pc-id
:id
}
{
:pulse_id
pulse-id
:channel_type
:email
}
PulseChannelRecipient
_
{
:user_id
(
mt/user->id
:rasta
)
:pulse_channel_id
pc-id
}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
PulseChannel
)))))
(
testing
"
Has
email"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:email
:details
{
:emails
[
"test@metabase.com"
]}}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
PulseChannel
)))))
(
testing
"
keep if has external
email"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:email
:details
{
:emails
[
"test@metabase.com"
]}}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
PulseChannel
)))))
(
testing
"Has channel"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:slack
:details
{
:channel
[
"#test"
]}}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
PulseChannel
)))))))
(
testing
"clear if no recipients"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:email
}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
0
(
t2/count
PulseChannel
))))))
(
testing
"slack"
(
testing
"Has channel"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:slack
:details
{
:channel
"#test"
}}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
PulseChannel
)))))
(
testing
"No channel"
(
mt/with-temp
[
Pulse
{
pulse-id
:id
}
{}
PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:slack
:details
{
:channel
nil
}}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
0
(
t2/count
PulseChannel
))))))
(
testing
"http"
(
testing
"do not clear if has a channel_id"
(
mt/with-temp
[
:model/Channel
{
channel-id
:id
}
{
:type
:channel/metabase-test
:details
{}}
:model/Pulse
{
pulse-id
:id
}
{}
:model/PulseChannel
_
{
:pulse_id
pulse-id
:channel_id
channel-id
:channel_type
"http"
}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
1
(
t2/count
:model/PulseChannel
)))))
(
testing
"clear if there is no channel_id"
(
mt/with-temp
[
:model/Pulse
{
pulse-id
:id
}
{}
:model/PulseChannel
_
{
:pulse_id
pulse-id
:channel_type
:http
}]
(
#
'task.send-pulses/clear-pulse-channels-no-recipients!
pulse-id
)
(
is
(
=
0
(
t2/count
:model/PulseChannel
))))))))
(
def
^
:private
daily-at-1am
{
:schedule_type
"daily"
...
...
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