Support / KnowledgeBase

 
Search the KnowledgeBase Search

Creating a cronjob for your (gc) Django GridContainer application

  • Applies to: (gs)

  • Difficulty: Medium

  • Time needed: 5 minutes

  • Tools needed: None

 

This article has the following dependencies:

  • If you currently do not have your Django GridContainer enabled you will need to have one in order to complete the steps in this article. You can add a container from within the AccountCenter.
  • Whenever installing Third-Party software please consult the official documentation. (mt) Media Temple does not support the installation and configuration of software not installed at time of service activation. For issues that fall outside of our Scope of Support, we recommend checking our User Forums and searching on Google for possible avenues of resolution.
  • mt-example.com is used as an example. Please be sure to replace this text with the proper information for your site or server.
  • GridContainer technology allows you to process frameworks such as Django or Ruby on Rails in an isolated environment. Make sure that you have RAM appropriate to the needs of your application. Not having enough resources can cause memory problems and instability in your application.

The following example should help you create a cronjob for your django application.  Please be careful to edit your code to match your own unique requirements.

  1. Create a file with a descriptive name such as cron.sh in your project root that has the following code:

    export PYTHONPATH=/home/#####/data/python/lib:/home/#####/data/python/bin:/home/#####/containers/django:/home/#####/data/python/django:/home/#####/containers/django/[projectname]
    export DJANGO_SETTINGS_MODULE=settings
    export PYTHON_EGG_CACHE=/home/#####/containers/django/[projectname]
    
    /usr/bin/python /home/#####/containers/django/[projectname]/pageview/cron.py > /home/#####/containers/django/[projectname]/cronlog
     
  2. Create a cron.py script that will be called from the above file:
    from django.core.management import setup_environ
    from django.contrib.contenttypes.models import ContentType
    import settings
    from pageview.models import *
    from photo.models import *
    import re, datetime, time, MySQLdb
    setup_environ(settings)
    
    [PUT THE REST OF YOUR CODE HERE!!]

Revisions:

07-20-2009: Minor Fixes

User Comments

No visitor comments posted. Post a comment

Fields marked with an asterisk(*) are required. Comment on this article

Fill out the form below if you would like to comment on this article.
 
 
 

(code is not case-sensitive)
 
Submit
 
 

Continue