Skip to content

Commit

Permalink
Background tweeting with Flask-RQ
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Feb 10, 2014
1 parent 31b8426 commit 49fd580
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions hasjob/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from flask import Flask
from flask.ext.rq import RQ
from flask.ext.mail import Mail
from flask.ext.lastuser import Lastuser
from baseframe import baseframe, assets, Version
Expand Down Expand Up @@ -31,6 +32,7 @@
# Configure the app
def init_for(env):
coaster.app.init_app(app, env)
RQ(app)
if app.config.get('SERVER_NAME'):
subdomain = 'static'
else:
Expand Down
5 changes: 5 additions & 0 deletions hasjob/twitter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# -*- coding: utf-8 -*-

from flask.ext.rq import job
from tweepy import OAuthHandler, API
import bitlyapi
import urllib2
import json
import re
from hasjob import app


@job('hasjob')
def tweet(title, url, location=None):
auth = OAuthHandler(app.config['TWITTER_CONSUMER_KEY'], app.config['TWITTER_CONSUMER_SECRET'])
auth.set_access_token(app.config['TWITTER_ACCESS_KEY'], app.config['TWITTER_ACCESS_SECRET'])
Expand Down
2 changes: 1 addition & 1 deletion hasjob/views/listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def confirm_email(hashid, key):
db.session.commit()
if app.config['TWITTER_ENABLED']:
try:
tweet(post.headline, url_for('jobdetail', hashid=post.hashid,
tweet.delay(post.headline, url_for('jobdetail', hashid=post.hashid,
_external=True), post.location)
flash("Congratulations! Your job listing has been published and tweeted",
"interactive")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Flask-WTF
Flask-Mail
Flask-Assets
Flask-Uploads
Flask-RQ
Pillow
pytz
markdown
Expand Down
3 changes: 3 additions & 0 deletions rq.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

rqworker -c rqdev hasjob
16 changes: 16 additions & 0 deletions rqdev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from urlparse import urlparse

from hasjob import init_for, app

init_for('dev')

REDIS_URL = app.config.get('REDIS_URL', 'redis://localhost:6379/0')

# REDIS_URL is not taken by setup_default_arguments function of rq/scripts/__init__.py
# so, parse it into pieces and give it

r = urlparse(REDIS_URL)
REDIS_HOST = r.hostname
REDIS_PORT = r.port
REDIS_PASSWORD = r.password
REDIS_DB = 0
15 changes: 15 additions & 0 deletions rqinit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from urlparse import urlparse

from hasjob import init_for, app

init_for('production')
REDIS_URL = app.config.get('REDIS_URL', 'redis://localhost:6379/0')

# REDIS_URL is not taken by setup_default_arguments function of rq/scripts/__init__.py
# so, parse that into pieces and give it

r = urlparse(REDIS_URL)
REDIS_HOST = r.hostname
REDIS_PORT = r.port
REDIS_PASSWORD = r.password
REDIS_DB = 0

0 comments on commit 49fd580

Please sign in to comment.