This repository has been archived by the owner on Sep 11, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plumbing for activity counters through to the JS
- Loading branch information
Showing
3 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,20 @@ | ||
from r2.lib import amqp, baseplate_integration, websockets | ||
|
||
from reddit_place.controllers import PLACE_SUBREDDIT | ||
|
||
|
||
@baseplate_integration.with_root_span("job.place_activity") | ||
def broadcast_activity(): | ||
activity = PLACE_SUBREDDIT.count_activity() | ||
if activity and activity.logged_in: | ||
websockets.send_broadcast( | ||
namespace="/place", | ||
type="activity", | ||
payload={ | ||
"count": activity.logged_in.count, | ||
}, | ||
) | ||
|
||
# ensure the message we put on the amqp worker queue is flushed before we | ||
# exit. | ||
amqp.worker.join() |
This file contains 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
This file contains 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,10 @@ | ||
description "periodically broadcast active visitors on the place canvas" | ||
|
||
task | ||
manual | ||
stop on reddit-stop or runlevel [016] | ||
|
||
script | ||
. /etc/default/reddit | ||
wrap-job paster run $REDDIT_INI -c 'from reddit_place import activity; activity.broadcast_activity()' | ||
end script |