EzDevInfo.com

django-cron

Write cron business logic as a Python class and let this app do the rest! It enables Django projects to schedule cron tasks, tracks their success / failures, manages contention (via a cache) etc. Basically takes care of all the boring work for you :-) Custom web and mobile applications | Tivix

How does django-cron work?

A normal approach to cron jobs with a django site would be to use cron to run custom management commands periodically.

But I found this http://code.google.com/p/django-cron/

How does it work, without needing cron? What invokes it to poll?

If it just sets up an address for an http request to hit periodically, what if the job takes a long time, won't the server time out?


Source: (StackOverflow)

How to use Tivix django-cron app

I got exact same problem described in this post, but the answer doesn't help at all. In short, I am using Tivix django-cron, the cron job is not running at regular basis.

To illustrate the problem, the following cron job class is intended to send email every min once running runcrons command. But in fact, it only sends out one email and no more. That defeats the purpose of cron... What am I missing?

class TestCron(CronJobBase):
    schedule = Schedule(run_every_mins=1)
    code = 'test_cron_philip'

    def do(self):
        send_mail('cron test', 'body is test body', 'coach_zhong@163.com',
                  ['admin@dessert.webfactional.com'],fail_silently=False)

Source: (StackOverflow)

Advertisements

Django-cron not executing job

I am trying to use Django-cron to regularly run a script on my Django server. It seems as though the cronScheduler is registering the Test class as "class ran" prints to my terminal, but I have not found any indication that the job is run (i.e. I have not seen "job ran" printed to the terminal). In case I shouldn't have been relying on printing to know if the job was running, I also watched the django_cron_job table in my database for a few minutes to see if the job's "last_run" value changed after initially sending a request to my server but I found that it did not.

Just so you know: Each time I test I have been hitting my server with one request so that the job will start, I have modified the CRON_POLLING_FREQUENCY in my settings file to be lower than the run_every value I specify for the job, and also ensured that the job was set to queued per this posts' suggestion: Similar problem.

In order to solve an error I was originally getting ("AttributeError: 'Settings' object has no attribute 'PROJECT_DIR'"), I set my PROJECT_DIR to os.path.dirname(__file__) in settings.py. Could that be a problem?

I also get the following when I start the server but I've looked into it and couldn't find any reason why it would be the problem:

"RuntimeWarning: DateTimeField received a naive datetime (2013-07-23 13:55:56.016085) while time zone support is active."

The only other thing of note is that I often retrieve the following printout to my terminal a few seconds after relaunching the server and hitting the server with a request, but it only happens once until I restart the server:

"Already executing Oops! process with pid 17099 is not running. Fixing status in db. Validating models..."

My cron.py file:

from django_cron import cronScheduler, Job, HOUR, DAY, WEEK, MONTH
import sys

class Test(Job):
    print "class ran"
    run_every=2
    def job(self):
        print "job ran"

cronScheduler.register(Test)

Source: (StackOverflow)

django-cron does not work

After installing the django_cron correctly, i write the following codes named as cron.py in django app to call django_cron to execute. But it's so odd that this script does not work at all!

from django_cron import cronScheduler, Job
from mysite.tds.models import machine_list,flavor_list,image_list
from mysite.views import *
import datetime,os

class CheckExpire(Job):
run_every = 60

def job(self):
    mac_list = machine_list.objects.filter(expire_date=datetime.date.today())
    for lst in mac_list:
        delete_vm(lst.servername)
        nagios_delete(lst.servername,lst.machine_ip)
    mac_list.delete()

cronScheduler.register(CheckExpire)

The codes above can be executed successfully if i wrtie them in anther script and run this script, so there is no mistake in these codes.

I post the steps on how i install django-cron for you guys to check if i install it correctly.

  1. Put 'django_cron' into your python path

  2. Add 'django_cron' to INSTALLED_APPS in your settings.py file

  3. Add the following code to the beginning of your urls.py file (just after the imports): import django_cron django_cron.autodiscover()

  4. Create a file called 'cron.py' inside each installed app that you want to add a recurring job to.

  5. update MaxRequestsPerChild in httpd.conf and set it to be 100

  6. update the base.py in django_cron and set polling_frequency 30(less than run_every)

Could someone figure out why django_cron does not work under this condition? Thanks in advance.


Source: (StackOverflow)

cron job 'django-cron' not running in ubuntu cron tab

I am using django_cron for a schedule a job, when i am use python manage.py runcrons this work good. but after adding the cron job in ubuntu cron list job is not executing. My setting.py is:

CRON_CLASSES = [
    "home.cron.HomeCronJob",
]

FAILED_RUNS_CRONJOB_EMAIL_PREFIX = []
INSTALLED_APPS = (
    'django.contrib.auth',
    '..................'
    'django_cron',
)

My cron.py file is:

from django_cron import CronJobBase, Schedule
from home.management.commands.auto_renueva import republishAds
class HomeCronJob(CronJobBase):
    RUN_EVERY_MINS = 2
    MIN_NUM_FAILURES = 2
    schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
    code = 'home.home_cron_job'

    def do(self):
        republishAds()

then I have created a shell script for run this job, cron.sh:

#! /bin/bash
source /home/cis/ENV/muna/bin/activate
python /home/cis/DjangoLive/Newmunda/mund2anuncios/manage.py runcrons
deactivate

and the code i have added in ubuntu cron file are:

*/1 * * * *  /home/cis/DjangoLive/Newmunda/mund2anuncios/crons.sh >> /home/cis/Desktop/crons.log 3 >> /home/cis/Desktop/cron_errors.log

Please suggest me what i am doing wrong Here.

Thanks in Advance


Source: (StackOverflow)

How to get django-cron to work automatically

I am trying to get django-cron working and its not. I followed the instruction here to set up my cron but the problem is that my job only runs when i type python manage.py runcrons on my command line and the job is not run every 5 minutes. I don't know what else to do. I have read other documents on crontabs and chronograph but am confused. Do I install crontabs along with cron or chronograph or will cron work fine with only django-cron. Also how do I get my job to run automatically. In the documentation here I read Now everytime you run the management command python manage.py runcrons all the crons will run if required. Depending on the application the management command can be called from the Unix crontab as often as required. Every 5 minutes usually works for most of my applications. . What does this mean. What am I missing here. Am lost. HELP

Settings.py

CRON_CLASSES = (
"myapp.views.MyCronJob",
)

INSTALLED_APPS = (

'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_cron',

'django.contrib.admin',
'django.contrib.admindocs',
'myapp',


)

views.py

from django_cron import CronJobBase, Schedule
class MyCronJob(CronJobBase):
RUN_EVERY_MINS = 10 # every 10 min

schedule = Schedule(run_every_mins=RUN_EVERY_MINS)
code = 'my_app.my_cron_job'    # a unique code

def do(self):
    print "10 min Cron"
    theJob()

I should mention that am using pycharm on a windows platform to run django...


Source: (StackOverflow)

Django: Getting Django-cron Running

I am trying to get Django-cron running, but it seems to only run after hitting the site once. I am using Virtualenv.

Any ideas why it only runs once?

On my PATH, I added the location of django_cron: '/Users/emilepetrone/Workspace/zapgeo/zapgeo/django_cron'

My cron.py file within my Django app:

from django_cron import cronScheduler, Job

from products.views import index

class GetProducts(Job):

    run_every = 60

    def job(self):
        index()

cronScheduler.register(GetProducts)

class GetLocation(Job):

    run_every = 60

    def job(self):
        index()

cronScheduler.register(GetLocation)

Source: (StackOverflow)

How to install django-cron on windows machine?

I'm trying to get django-cron to work on a winXP machine. (Wish I could use *nix).

Done

pip install django-cron 

Added django_cron to INSTALLED_APPS in settings.py.

Then from windows console, ran below command

python manage.py syncdb

The result I got is:

"Not synced (use migrations):
 `- django_cron`
(use ./manage.py migrate to migrate these)"

OK, So as per instructions from error msg I did, C:\ python manage.py migrate. Result is as follow:

Running migrations for django_cron:
- Nothing to migrate.
- Loading initial data for django_cron.
Installed 0 object(s) from 0 fixture(s)

Now what? What should I Google in order to figure out what's wrong with the migration?

Did I installed django-cron on the appropriate location? Right now it's in

python27\Lib\site-packages\django_cron

Source: (StackOverflow)

Django custom commend + cron job

I have custom commend:

python manage.py checksomething

How to run this every two hours?

I saw django-cron:

#example from doc
from django_cron import cronScheduler, Job

from MyMailFunctions import check_feedback_mailbox

class CheckMail(Job):
        # run every 300 seconds (5 minutes)
        run_every = 300

        def job(self):
                # This will be executed every 5 minutes
                check_feedback_mailbox()

cronScheduler.register(CheckMail)

but how to run it? It will turn on automatically? Do I have something set up on the server? Where should be this file? (In what folder?)


Source: (StackOverflow)

How to run django-cron job in exact time

I can't use celery in my project, only django-cron. I need to run my task 2 times a day:

  • at 11:59 A.M.
  • at 11:59 P.M.

Can I do it? I found only RUN_EVERY (in mins or secs) variable.


Source: (StackOverflow)

what is the directory .virtualenvs? (was: ImportError: No module named django_cron, is my virtual environment set correct?)

I am trying to modify my virtual environment to add a new library (django-cron). When I execute a pip list

(env_dili_py27)[todd@somewhere site-packages]$ pip list
Django (1.5.4)
django-common-helpers (0.6.0)
django-cron (0.3.3)
django-filter (0.7)
djangorestframework (2.3.8)
Markdown (2.3.1)
MySQL-python (1.2.4)
pip (1.4.1)
setuptools (0.9.8)
South (0.8.4)
wsgiref (0.1.2)

however the list of packages doesn't include djanago cron:

(env_dili_py27)[todd@somewhere python2.7]$ ls site-packages/ -l
total 448
drwxrwxr-x 17 todd todd   4096 Oct 19 08:54 django
drwxrwxr-x  2 todd todd   4096 Oct 19 08:54 Django-1.5.4-py2.7.egg-info
drwxrwxr-x  2 todd todd   4096 Oct 19 08:56 django_filter-0.7-py2.7.egg-info
drwxrwxr-x  3 todd todd   4096 Oct 19 08:56 django_filters
drwxr-xr-x  2 root root   4096 Oct 22 11:02 djangorestframework-2.3.8-py2.7.egg-info
-rw-rw-r--  1 todd todd    126 Jul 15  2013 easy_install.py
-rw-rw-r--  1 todd todd    340 Oct 19 08:28 easy_install.pyc
drwxrwxr-x  3 todd todd   4096 Oct 19 08:54 markdown
drwxrwxr-x  2 todd todd   4096 Oct 19 08:54 Markdown-2.3.1-py2.7.egg-info
drwxrwxr-x  2 todd todd   4096 Oct 19 08:28 _markerlib
drwxr-xr-x  3 root root   4096 Oct 22 11:08 MySQLdb
-rw-r--r--  1 root root   2352 Oct 22 11:07 _mysql_exceptions.py
-rw-r--r--  1 root root   4555 Oct 22 11:08 _mysql_exceptions.pyc
drwxr-xr-x  2 root root   4096 Oct 22 11:08 MySQL_python-1.2.4-py2.7.egg-info
-rwxr-xr-x  1 root root 139849 Oct 22 11:08 _mysql.so
drwxrwxr-x  6 todd todd   4096 Oct 19 08:28 pip
drwxrwxr-x  2 todd todd   4096 Oct 19 08:50 pip-1.4.1-py2.7.egg-info
-rw-rw-r--  1 todd todd 101108 Jul 15  2013 pkg_resources.py
-rw-rw-r--  1 todd todd 114723 Oct 19 08:28 pkg_resources.pyc
drwxr-xr-x  9 root root   4096 Oct 22 11:02 rest_framework
drwxrwxr-x  5 todd todd   4096 Oct 19 08:28 setuptools
drwxrwxr-x  2 todd todd   4096 Oct 19 08:50 setuptools-0.9.8-py2.7.egg-info

In my settings.py i reference the django_cron library (as referenced: https://github.com/Tivix/django-cron):

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_cron',
    'rest_framework',
    'somewhereApp',
)

This is the exception log I am recieving:

[Tue Feb 04 15:05:05 2014] [info] [client 76.119.143.226] mod_wsgi (pid=10049, process='api.somewhere.com', application='api.somewhere.com|'): Loading WSGI script '/var/www/python.somewhere.com/somewhere/wsgi.py'.
[Tue Feb 04 15:05:06 2014] [error] Internal Server Error: /
[Tue Feb 04 15:05:06 2014] [error] Traceback (most recent call last):
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/core/handlers/base.py", line 92, in get_response
[Tue Feb 04 15:05:06 2014] [error]     response = middleware_method(request)
[Tue Feb 04 15:05:06 2014] [error]   File "/var/www/python.somewhere.com/somewhereApp/authentication.py", line 62, in process_request
[Tue Feb 04 15:05:06 2014] [error]     user = lookupUserById(userId)
[Tue Feb 04 15:05:06 2014] [error]   File "/var/www/python.somewhere.com/somewhereApp/authentication.py", line 15, in lookupUserById
[Tue Feb 04 15:05:06 2014] [error]     user = diliModels.User.objects.get(user_id=userId)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/manager.py", line 143, in get
[Tue Feb 04 15:05:06 2014] [error]     return self.get_query_set().get(*args, **kwargs)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/query.py", line 395, in get
[Tue Feb 04 15:05:06 2014] [error]     clone = self.filter(*args, **kwargs)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/query.py", line 669, in filter
[Tue Feb 04 15:05:06 2014] [error]     return self._filter_or_exclude(False, *args, **kwargs)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/query.py", line 687, in _filter_or_exclude
[Tue Feb 04 15:05:06 2014] [error]     clone.query.add_q(Q(*args, **kwargs))
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1271, in add_q
[Tue Feb 04 15:05:06 2014] [error]     can_reuse=used_aliases, force_having=force_having)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1139, in add_filter
[Tue Feb 04 15:05:06 2014] [error]     process_extras=process_extras)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1325, in setup_joins
[Tue Feb 04 15:05:06 2014] [error]     field, model, direct, m2m = opts.get_field_by_name(name)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/options.py", line 351, in get_field_by_name
[Tue Feb 04 15:05:06 2014] [error]     cache = self.init_name_map()
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/options.py", line 380, in init_name_map
[Tue Feb 04 15:05:06 2014] [error]     for f, model in self.get_all_related_m2m_objects_with_model():
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/options.py", line 469, in get_all_related_m2m_objects_with_model
[Tue Feb 04 15:05:06 2014] [error]     cache = self._fill_related_many_to_many_cache()
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/options.py", line 483, in _fill_related_many_to_many_cache
[Tue Feb 04 15:05:06 2014] [error]     for klass in get_models(only_installed=False):
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/loading.py", line 197, in get_models
[Tue Feb 04 15:05:06 2014] [error]     self._populate()
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/loading.py", line 72, in _populate
[Tue Feb 04 15:05:06 2014] [error]     self.load_app(app_name, True)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/db/models/loading.py", line 94, in load_app
[Tue Feb 04 15:05:06 2014] [error]     app_module = import_module(app_name)
[Tue Feb 04 15:05:06 2014] [error]   File "/home/todd/Envs/env_dili_py27/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Tue Feb 04 15:05:06 2014] [error]     __import__(name)
[Tue Feb 04 15:05:06 2014] [error] ImportError: No module named django_cron

I uninstalled django-cron and reinstalled it with verbose:

(env_dili_py27)[todd@somewhere site-packages]$ pip install django-cron -v
Downloading/unpacking django-cron
  Using version 0.3.3 (newest of versions: 0.3.3, 0.3.2, 0.3.1, 0.3.0, 0.2.9, 0.2.8, 0.2.7, 0.2.6, 0.2.5, 0.2.4, 0.2.3, 0.2.2, 0.2.1, 0.2, 0.1.2)
  Downloading django-cron-0.3.3.tar.gz
  Downloading from URL https://pypi.python.org/packages/source/d/django-cron/django-cron-0.3.3.tar.gz#md5=586bed6c699e6b7f78eac2e83c8f0d6e (from https://pypi.python.org/simple/django-cron/)
  Running setup.py egg_info for package django-cron
    running egg_info
    creating pip-egg-info/django_cron.egg-info
    writing requirements to pip-egg-info/django_cron.egg-info/requires.txt
    writing pip-egg-info/django_cron.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/django_cron.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/django_cron.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/django_cron.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'pip-egg-info/django_cron.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'pip-egg-info/django_cron.egg-info/SOURCES.txt'
Requirement already satisfied (use --upgrade to upgrade): Django>=1.5.0 in /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages (from django-cron)
Requirement already satisfied (use --upgrade to upgrade): South>=0.8.1 in /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages (from django-cron)
Requirement already satisfied (use --upgrade to upgrade): django-common-helpers>=0.5.1 in /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages (from django-cron)
Installing collected packages: django-cron
  Running setup.py install for django-cron
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/django_cron
    copying django_cron/timezone.py -> build/lib/django_cron
    copying django_cron/admin.py -> build/lib/django_cron
    copying django_cron/__init__.py -> build/lib/django_cron
    copying django_cron/test_settings.py -> build/lib/django_cron
    copying django_cron/tests.py -> build/lib/django_cron
    copying django_cron/cron.py -> build/lib/django_cron
    copying django_cron/models.py -> build/lib/django_cron
    creating build/lib/django_cron/migrations
    copying django_cron/migrations/__init__.py -> build/lib/django_cron/migrations
    copying django_cron/migrations/0001_initial.py -> build/lib/django_cron/migrations
    copying django_cron/migrations/0002_auto__add_field_cronjoblog_ran_at_time.py -> build/lib/django_cron/migrations
    copying django_cron/migrations/0003_auto__add_index_cronjoblog_end_time__add_index_cronjoblog_ran_at_time_.py -> build/lib/django_cron/migrations
    creating build/lib/django_cron/management
    copying django_cron/management/__init__.py -> build/lib/django_cron/management
    creating build/lib/django_cron/management/commands
    copying django_cron/management/commands/__init__.py -> build/lib/django_cron/management/commands
    copying django_cron/management/commands/runcrons.py -> build/lib/django_cron/management/commands
    running egg_info
    writing requirements to django_cron.egg-info/requires.txt
    writing django_cron.egg-info/PKG-INFO
    writing top-level names to django_cron.egg-info/top_level.txt
    writing dependency_links to django_cron.egg-info/dependency_links.txt
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'django_cron.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'django_cron.egg-info/SOURCES.txt'
    running install_lib
    creating /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    copying build/lib/django_cron/timezone.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    copying build/lib/django_cron/admin.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    copying build/lib/django_cron/__init__.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    copying build/lib/django_cron/test_settings.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    creating /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations
    copying build/lib/django_cron/migrations/__init__.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations
    copying build/lib/django_cron/migrations/0001_initial.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations
    copying build/lib/django_cron/migrations/0002_auto__add_field_cronjoblog_ran_at_time.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations
    copying build/lib/django_cron/migrations/0003_auto__add_index_cronjoblog_end_time__add_index_cronjoblog_ran_at_time_.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations
    copying build/lib/django_cron/tests.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    copying build/lib/django_cron/cron.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    creating /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management
    copying build/lib/django_cron/management/__init__.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management
    creating /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management/commands
    copying build/lib/django_cron/management/commands/__init__.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management/commands
    copying build/lib/django_cron/management/commands/runcrons.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management/commands
    copying build/lib/django_cron/models.py -> /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/timezone.py to timezone.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/admin.py to admin.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/__init__.py to __init__.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/test_settings.py to test_settings.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations/__init__.py to __init__.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations/0001_initial.py to 0001_initial.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations/0002_auto__add_field_cronjoblog_ran_at_time.py to 0002_auto__add_field_cronjoblog_ran_at_time.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/migrations/0003_auto__add_index_cronjoblog_end_time__add_index_cronjoblog_ran_at_time_.py to 0003_auto__add_index_cronjoblog_end_time__add_index_cronjoblog_ran_at_time_.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/tests.py to tests.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/cron.py to cron.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management/__init__.py to __init__.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management/commands/__init__.py to __init__.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/management/commands/runcrons.py to runcrons.pyc
    byte-compiling /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron/models.py to models.pyc
    running install_egg_info
    Copying django_cron.egg-info to /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/django_cron-0.3.3-py2.7.egg-info
    running install_scripts
    writing list of installed files to '/tmp/pip-y2KoCb-record/install-record.txt'
Successfully installed django-cron
Cleaning up...
  Removing temporary dir /home/todd/.virtualenvs/env_dili_py27/build...
(env_dili_py27)[todd@somewhere site-packages]$

AN ls

[todd@somewhere site-packages]$ ls  /home/todd/.virtualenvs/env_dili_py27/lib/python2.7/site-packages/
django                                      django_filter-0.7-py2.7.egg-info          Markdown-2.3.1-py2.7.egg-info      _mysql.so                 setuptools
Django-1.5.4-py2.7.egg-info                 django_filters                            _markerlib                         pip                       setuptools-0.9.8-py2.7.egg-info
django_common                               djangorestframework-2.3.8-py2.7.egg-info  MySQLdb                            pip-1.4.1-py2.7.egg-info  south
django_common_helpers-0.6.0-py2.7.egg-info  easy_install.py                           _mysql_exceptions.py               pkg_resources.py          South-0.8.4-py2.7.egg-info
django_cron                                 easy_install.pyc                          _mysql_exceptions.pyc              pkg_resources.pyc
django_cron-0.3.3-py2.7.egg-info            markdown                                  MySQL_python-1.2.4-py2.7.egg-info  rest_framework
[todd@somewhere site-packages]$

So it is looking like it is installed now. The only thing I did different was install with verbose command on...


Wait i think I see something. I am running django with python loaded from:

/home/todd/Envs/env_dili_py27/...

but the library was installed at

/home/todd/.virtualenvs/env_dili_py27/...

What is .virtualenvs in the directory path (I am new to django/python and linux)?


Source: (StackOverflow)

Django Translation not working in cron

I have an application that uses Django 1.7 and it has to be translated completely. I have to send emails in 2 cases: one when I click send on a button and one when I schedule an email to send. For the second case I used a cron (using django-cron 0.3.5). When I send the email using the button it is sent translated and when I use ./manage.py runcrons it is also translated. However, after putting the application on a server the cron works, but the email is not translated.

This is my code from the cron:

from django_cron import CronJobBase, Schedule
from django.utils import translation
translation.activate('fr_FR')

class SendEmail(CronJobBase):
    schedule = Schedule(run_every_mins=60)
    code = 'send.email'

    def do(self):
        # do stuff here
        send_email(subject, receiver, email_template, values, attachment)

send_email is a function that uses EmailMessage to send the email.

Does anyone know why it could not work after being put on a server?


Source: (StackOverflow)