Permalink
Browse files

Add cron jobs.

  • Loading branch information...
glogiotatidis committed Dec 1, 2015
1 parent 375a146 commit 4d9d7d8533cb23a72ccdd82d49c586380bd2be1b
Showing with 86 additions and 5 deletions.
  1. +1 −0 Procfile
  2. +0 −4 bin/deploy-travis.sh
  3. +1 −1 bin/run-common.sh
  4. +3 −0 bin/run-prod.sh
  5. +3 −0 careers/settings.py
  6. +15 −0 requirements.txt
  7. 0 scripts/__init__.py
  8. +63 −0 scripts/cron.py
View
@@ -1 +1,2 @@
web: ./bin/run-prod.sh
cron: ./manage.py runscript cron
View
@@ -1,10 +1,6 @@
#!/bin/bash
set -e
# Workaround to ignore mtime until we upgrade to Docker 1.8
# See https://github.com/docker/docker/pull/12031
find . -newerat 20140101 -exec touch -t 201401010000 {} \;
function setup_ssh_bin() {
echo '#!/bin/sh' >> ssh-bin
echo 'exec ssh -o StrictHostKeychecking=no -o CheckHostIP=no -o UserKnownHostsFile=/dev/null "$@"' >> ssh-bin
View
@@ -1,3 +1,3 @@
#!/bin/bash
./manage.py migrate
python manage.py migrate --noinput
View
@@ -1,4 +1,7 @@
#!/bin/sh
./bin/run-common.sh
echo "$GIT_SHA" > static/revision.txt
gunicorn careers.wsgi:application -b 0.0.0.0:${PORT:-8000} --log-file -
View
@@ -42,6 +42,7 @@
# Third party apps
'django_jinja',
'django_jobvite',
'django_extensions',
# Django apps
'django.contrib.admin',
@@ -190,3 +191,5 @@
JOBVITE_URI = config(
'JOBVITE_URI',
default='https://www.jobvite.com/CompanyJobs/Xml.aspx?c=qpX9Vfwa&cf=e')
DEAD_MANS_SNITCH_URL = config('DEAD_MANS_SNITCH', default=None)
View
@@ -134,3 +134,18 @@ html5lib==0.9999999
# sha256: -s_gx8zq_Uno9-RyERKUVmYF_f3cIwEdoGzDpGAcn30
# sha256: BHu7ukG6w3xETHXd_fBXPdbi8fvYJOYke7Jvp9j6ODA
six==1.8.0
# sha256: sLOVxVffrYQVsISLuKUNBidXX0S9a1d8j-lts60wdo0
# sha256: i5s54QKtKgA_uCmfMGrcIl5_EGKvjqgZu2GhzYyFUtI
apscheduler==3.0.4
# sha256: Q48SLWhMlRsiy5iuzID9uWG4TmlUK_h4xrmpQZ3gmos
tzlocal==1.2
# sha256: BK-ioGq33MqdgXF7Qgp6FIJgYemyYUpcd90kx1zPl-Q
# sha256: L-I0K7T-i44hfw0htZIcvlQIv5Ztn5ICXnB-iBsZi-0
futures==3.0.3
# sha256: R5lTTzXrocB8tvmFmqW7cZiGdp9dNdKjjnSQzpDAzmk
# sha256: -Y-ZHSsDkDOsX6pjjA0a-ycgq_TZ14FXPDWS1omUgKE
django-extensions==1.6.1
View
No changes.
View
@@ -0,0 +1,63 @@
from __future__ import print_function
import datetime
from django.core.management import call_command
from django.conf import settings
import requests
from apscheduler.schedulers.blocking import BlockingScheduler
schedule = BlockingScheduler()
class scheduled_job(object):
"""Decorator for scheduled jobs. Takes same args as apscheduler.schedule_job."""
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
def __call__(self, fn):
job_name = fn.__name__
self.name = job_name
self.callback = fn
schedule.add_job(self.run, id=job_name, *self.args, **self.kwargs)
self.log('Registered.')
return self.run
def run(self):
self.log('starting')
try:
self.callback()
except Exception as e:
self.log('CRASHED: {}'.format(e))
raise
else:
self.log('finished successfully')
def log(self, message):
print('Clock job {0}: {1}'.format(self.name, message))
def ping_dms(function):
"""Pings Dead Man's Snitch after job completion if URL is set."""
def _ping():
function()
if settings.DEAD_MANS_SNITCH_URL:
utcnow = datetime.datetime.utcnow()
payload = {'m': 'Run {} on {}'.format(function.__name__, utcnow.isoformat())}
requests.get(settings.DEAD_MANS_SNITCH_URL, params=payload)
return _ping
@scheduled_job('interval', minutes=3)
@ping_dms
def job_syncjobvite():
call_command('syncjobvite')
def run():
try:
schedule.start()
except (KeyboardInterrupt, SystemExit):
pass

0 comments on commit 4d9d7d8

Please sign in to comment.