Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Commit

Permalink
Add plumbing for activity counters through to the JS
Browse files Browse the repository at this point in the history
  • Loading branch information
spladug committed Mar 23, 2017
1 parent 6024ce5 commit 6dd4275
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions reddit_place/activity.py
@@ -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()
8 changes: 8 additions & 0 deletions reddit_place/controllers.py
Expand Up @@ -164,6 +164,10 @@ def GET_canvasse(self, is_embed, is_webview):
"place_fullscreen": is_embed or is_webview,
}

activity = PLACE_SUBREDDIT.count_activity()
if activity and activity.logged_in:
js_config["place_active_visitors"] = activity.logged_in.count

if is_embed:
# ensure we're off the cookie domain before allowing embedding
if request.host != g.media_domain:
Expand Down Expand Up @@ -394,6 +398,10 @@ def add_place_config(config):
config["place_canvas_height"] = CANVAS_HEIGHT
config["place_cooldown"] = cooldown

activity = c.site.count_activity()
if activity and activity.logged_in:
config["place_active_visitors"] = activity.logged_in.count


@controller_hooks.on("extra_stylesheets")
def add_place_stylesheet(extra_stylesheets):
Expand Down
10 changes: 10 additions & 0 deletions upstart/reddit-job-place_activity.conf
@@ -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

0 comments on commit 6dd4275

Please sign in to comment.