Skip to content
This repository has been archived by the owner on Mar 22, 2020. It is now read-only.

Commit

Permalink
added the ability to queue the project to redis easily
Browse files Browse the repository at this point in the history
  • Loading branch information
kencochrane committed Sep 29, 2013
1 parent 1b3af22 commit 3a4826f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ django-bootstrap3==0.0.7
djangorestframework==2.3.8
Markdown==2.3.1
django-filter==0.7
redis==2.7.5
hiredis==0.1.1

# deployment
Fabric==1.7.0
Expand Down
15 changes: 15 additions & 0 deletions scorinator/core/queue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os
from redis import Redis, StrictRedis

if 'REDIS_HOST' in os.environ:
redis = StrictRedis(host=os.environ['REDIS_HOST'],
port=int(os.environ['REDIS_PORT']),
db=0,
password=os.environ['REDIS_PASSWORD'])
else:
redis = Redis()

QUEUE_KEY = "scorinator_list"

def enqueue(value):
return redis.rpush(QUEUE_KEY, value)
20 changes: 19 additions & 1 deletion scorinator/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.text import slugify

from core.queue import enqueue
import json

def set_slug(name):
# make sure there are no duplicate slugs
Expand Down Expand Up @@ -52,6 +53,23 @@ def score(self):
else:
return pscore

@property
def dict_val(self):
""" return object as a dict """
return {'name': self.name,
'repo_id': self.pk,
'repo_url': self.repo_url,
'slug': self.slug}

@property
def json_val(self):
""" Get the json version of this project """
return json.dumps(self.dict_val)

def rebuild_score(self):
""" Queue up a build request for this project """
return enqueue(self.json_val)

def __repr__(self):
return self.__str__()

Expand Down

0 comments on commit 3a4826f

Please sign in to comment.