This repository was archived by the owner on Nov 8, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork20
feat(status): realtime visitors#442
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
3465c97
refactor(statistics): online-status & update Telsa stack
mydearxymd9d750d
chore(status): online visitors set to 1
mydearxymbb0d9d3
fix(ci): rss tesla client name
mydearxymb83b23b
fix(ci): community query arg
mydearxymb0d2a94
fix(ci): community query arg
mydearxymfb0df05
fix(ci): test errors
mydearxymFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
20 changes: 16 additions & 4 deletionsconfig/config.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletionconfig/prod.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionslib/groupher_server/accounts/delegates/profile.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionslib/groupher_server/application.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletionslib/groupher_server/cms/delegates/blog_curd.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletionslib/groupher_server/cms/delegates/community_operation.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
39 changes: 35 additions & 4 deletionslib/groupher_server/statistics/delegates/status.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionslib/groupher_server/statistics/statistics.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletionslib/groupher_server_web/resolvers/statistics_resolver.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletionslib/groupher_server_web/schema/statistics/statistics_queries.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 10 additions & 1 deletionlib/groupher_server_web/schema/statistics/statistics_types.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 9 additions & 2 deletionslib/helper/RSS.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionlib/helper/cache.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletionslib/helper/radar_search.ex → lib/helper/ip_2_city.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
11 changes: 6 additions & 5 deletionslib/helper/oauth2/github.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletionslib/helper/plausible.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule Helper.Plausible do | ||
@moduledoc """ | ||
find city info by ip | ||
refer: https://lbs.amap.com/api/webservice/guide/api/ipconfig/?sug_index=0 | ||
""" | ||
use Tesla, only: [:get] | ||
import Helper.Utils, only: [get_config: 2] | ||
alias Helper.Cache | ||
@endpoint "https://plausible.io" | ||
@realtime_visitors_query "/api/v1/stats/realtime/visitors" | ||
@timeout_limit 4000 | ||
@site_id "coderplanets.com" | ||
@service_key get_config(:plausible, :token) | ||
@cache_pool :online_status | ||
plug(Tesla.Middleware.BaseUrl, @endpoint) | ||
plug(Tesla.Middleware.Headers, [{"Authorization", "Bearer #{@service_key}"}]) | ||
plug(Tesla.Middleware.Retry, delay: 200, max_retries: 2) | ||
plug(Tesla.Middleware.Timeout, timeout: @timeout_limit) | ||
plug(Tesla.Middleware.JSON) | ||
def realtime_visitors() do | ||
query = [site_id: @site_id] | ||
path = "#{@realtime_visitors_query}" | ||
# NOTICE: DO NOT use Tesla.get, otherwise the middleware will not woking | ||
# see https://github.com/teamon/tesla/issues/88 | ||
# with true <- Mix.env() !== :test do | ||
with {:ok, %{body: body}} <- get(path, query: query) do | ||
case is_number(body) do | ||
true -> | ||
Cache.put(@cache_pool, :realtime_visitors, body) | ||
{:ok, body} | ||
false -> | ||
{:ok, 1} | ||
end | ||
else | ||
error -> | ||
IO.inspect(error, label: "got error") | ||
Cache.put(@cache_pool, :realtime_visitors, 1) | ||
{:ok, 1} | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletionslib/helper/scheduler.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletionmix.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionmix.lock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionstest/groupher_server/cms/comments/works_comment_replies_test.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletiontest/groupher_server/cms/community/community_meta_test.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.