Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rapicastillo authored Apr 20, 2018
2 parents 7681830 + ce01f4e commit 08d7de2
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ python-firebase = "*"
sass = "*"
django-sass-processor = "*"
sendgrid = "*"
redis = "*"
rq = "*"
apscheduler = "*"

[requires]
python_version = "3.6"
36 changes: 35 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
web: gunicorn gettingstarted.wsgi
worker: python worker.py
clock: python clock.py
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ For PostGreSQL

**Note:** `locations` and `message` are the initial data for all the locations and messages.


### 4. Setup Scheduled tasks

In your Heroku project root:

```
heroku addons:create redistogo
heroku scale worker=1
heroku scale clock=1
```

# TBD Django Commands

These commands can be incorporated to your cron / scheduled tasks.
Expand Down
20 changes: 20 additions & 0 deletions clock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# encoding=utf8

from apscheduler.schedulers.blocking import BlockingScheduler
from tasks import maintask

from rq import Queue
from worker import conn

sched = BlockingScheduler()

@sched.scheduled_job('interval', minutes=6)
def timed_for_task():
q = Queue(connection=conn)
result = q.enqueue(maintask.run_pull_data, timeout=500)

time.sleep(180)

result2 = q.enqueue(maintask.run_send_confirmation, timeout=500)

sched.start()
10 changes: 10 additions & 0 deletions tasks/maintask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# encoding=utf8
from django.core.management import call_command

def run_pull_data():
print('RUN] Running Scheduled work: Pull Data');
call_command('pull_data')

def run_send_confirmation():
print('RUN] Running Scheduled work: Pull Data');
call_command('send_confirmation')
18 changes: 18 additions & 0 deletions twilio_mgr/migrations/0023_auto_20180420_1633.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.3 on 2018-04-20 16:33

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('twilio_mgr', '0022_auto_20180412_2125'),
]

operations = [
migrations.AlterField(
model_name='message',
name='message',
field=models.CharField(max_length=1000),
),
]
2 changes: 1 addition & 1 deletion twilio_mgr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __str__(self):


class Message(models.Model):
message = models.CharField(max_length=400)
message = models.CharField(max_length=1000)
keyword = models.CharField(max_length=100,unique=True)


Expand Down
16 changes: 16 additions & 0 deletions worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# encoding=utf8
import os

import redis
from rq import Worker, Queue, Connection

listen = ['high', 'default', 'low']

redis_url = os.getenv('REDISTOGO_URL', 'redis://localhost:6379')

conn = redis.from_url(redis_url)

if __name__ == '__main__':
with Connection(conn):
worker = Worker(map(Queue, listen))
worker.work()

0 comments on commit 08d7de2

Please sign in to comment.