Notifications in Lastuser

16 views
Skip to first unread message

Kiran Jonnalagadda

unread,
Jun 1, 2013, 6:44:10 PM6/1/13
to hasgee...@googlegroups.com
Hi all,

TL;DR version: if you are working with Lastuser, install Redis, the Flask-RQ package, and run "./rq.sh" in a separate shell.

I've just added rudimentary background notification support in Lastuser via Flask-RQ. If you've not tried RQ before, it's a deliciously simple job queuing framework.


RQ's simplicity can also be beguiling as it depends on Python pickles to pass a task to a worker, including the module name, function and parameters for a worker to look up and call. In the HasGeek setup, each app runs as a separate user process and apps are not installed to the global Python path, so we need a separate rqworker per app.

To facilitate this setup, I've added three files to Lastuser's repo: rq.sh, rqdev.py and rqinit.py. Here is what they do:

rq.sh: In development, open a new tab, cd to the lastuser folder and run "./rq.sh". This will fire up rqworker and init lastuser to development mode.

rqdev.py: This file is loaded by rq.sh to put lastuser into development mode.

rqinit.py: This file inits Lastuser into production mode. See the supervisord section below.

I've also placed these files in the hgapp repo so they are available to any other app that needs background task management. Devi, you should consider this setup for Imgee.

Finally, for production use, RQ recommends supervisord for process management. Here's my config from production (/etc/supervisor/conf.d/rq-lastuser.conf):

"""
[program:rq-lastuser]
; Point the command to the specific rqworker command you want to run.
; If you use virtualenv, be sure to point it to
; /path/to/virtualenv/bin/rqworker
; Also, you probably want to include a settings module to configure this
; worker.  For more info on that, see http://python-rq.org/docs/workers/
command=rqworker -c rqinit lastuser
process_name=%(program_name)s
user=lastuser

; If you want to run more than one worker instance, increase this
numprocs=1

; This is the directory from which RQ is ran. Be sure to point this to the
; directory where your source code is importable from
directory=/var/www/lastuser/lastuser

; RQ requires the TERM signal to perform a warm shutdown. If RQ does not die 
; within 10 seconds, supervisor will forcefully kill it
stopsignal=TERM

; These are up to you
autostart=true
autorestart=true
"""

As per this config, rqworker is run as the lastuser process and is told to load "rqinit.py", which initializes lastuser and establishes the database connection so that jobs have access to the same working environment as the main website process.

Next task: update Flask-Lastuser to support receiving notifications. When this is done, users will no longer have to logout and login for changes to reflect on app websites (at last)!

Kiran

-- 
Kiran Jonnalagadda

Kiran Jonnalagadda

unread,
Jun 1, 2013, 8:11:29 PM6/1/13
to hasgee...@googlegroups.com
I've updated Flask-Lastuser and several of the client apps. Here is what you need to do in your client app:

1. Implement a notification endpoint, like here: https://github.com/hasgeek/hgapp/blob/master/hgapp/views/login.py#L29

2. Add this URL to your app's settings in Lastuser, in the "Notification URI" field.

That's it!

PS: Delete notifications (for organizations and teams) aren't handled correctly at the moment. I'll have to implement a delete journal to do that properly.

Kiran

-- 
Kiran Jonnalagadda

Reply all
Reply to author
Forward
0 new messages