Giter Site home page Giter Site logo

Help Please about django-crontab HOT 11 CLOSED

kraiz avatar kraiz commented on July 17, 2024
Help Please

from django-crontab.

Comments (11)

rollue avatar rollue commented on July 17, 2024 1

@brayan15 @kraiz
I managed to figure out the solution. Apparently, crontab does not automatically pick up local virtual environment's(=pyenv in my case) environment variables. So you have to set them manually using crontab -e command.

After setting the following 4 environment variables in crontab -e, crontab started working as expected. (Not all of the four environment variables may be needed; I'll leave it up to you to test that :))

DJANGO_SETTINGS_MODULE=core.settings.development
DATABASE_URL=postgres://my_id:my_password@localhost:5432/my_db_name
DJANGO_SECRET_KEY=my_django_secret key
PATH=~/.pyenv/shims:~/.pyenv/bin:"$PATH"

*/1 * * * * /Users/mhjeon/.pyenv/versions/3.6.0/envs/djangocrawler/bin/python /Users/mhjeon/projects/djangocrawler/manage.py crontab run b9a4006b4087d6494c1b442bcadb1db0 >> /tmp/scheduled_job.log # django-cronjobs for core

I guess this probably should be added to doc or REAME, for I have spent more than 5 days searching for the right answer in futile. I owe getting the hint about environment variables to this blog, which in Korean.

Note: I'm yet to test this solution on live, on AWS EBS. I only tested on local development settings. But I presume if you set those environment variables correctly, I should work on remote servers also.

from django-crontab.

kraiz avatar kraiz commented on July 17, 2024

Ok and what's the problem?
What the output of crontab -l on the console?

from django-crontab.

brayan15 avatar brayan15 commented on July 17, 2024

the output was this:
*/2 * * * * /Users/brayanlara/virtualenvs/vehicle/bin/python /Users/brayanlara/Desktop/Projects/vehicle_control_system/manage.py crontab run b11ab998cc14f55a4642db8bfd678835 # django-cronjobs for config

from django-crontab.

addisonlynch avatar addisonlynch commented on July 17, 2024

vehicle_control_system.persons.contrab -> vehicle_control_system.persons.crontab?

from django-crontab.

brayan15 avatar brayan15 commented on July 17, 2024

not, because my file called contrab and als I run python manage.py. crontab add later python manage.py runserver, but never doesn't show print, only show print when I run python manage.py crontab run b11ab998cc14f55a4642db8bfd678835, but with python manage.py runserver never run.

from django-crontab.

kraiz avatar kraiz commented on July 17, 2024

Sure...as the command will be called from a system service not from within your shell. If you're interested in the stdout stream you should redirect it into a logfile. It's documeted in the README, have a look at example 1 on settting CRONJOBS.

from django-crontab.

brayan15 avatar brayan15 commented on July 17, 2024

ty, I'm going to review

from django-crontab.

rollue avatar rollue commented on July 17, 2024

@kraiz I'm having the same trouble. I CAN add and run with python manage.py crontab add or python manage.py crontab run xxxxxx, but if I do python manage.py runserver to see if django server is actually doing my scheduled jobs(scheduled_crawl to create CrawlLog for testing purposes), nothing happens. I tried redirecting it into logfile like you suggested, but it's not working neither.

settings.py

import os


CRONJOBS = [
    ('* * * * *', 'crawlers.cronjobs.scheduled_crawl', '>> /tmp/crawllog.log'),
]

crawlers.cronjobs.py

from .models import CronLog


def scheduled_crawl():
    CronLog.objects.create()

crawlers.models.py

from django.db import models


class CronLog(models.Model):
    date = models.DateTimeField(auto_now_add=True, blank=True)

    def __unicode__(self):
        return self.date.ctime()

crontab -l

* * * * * /Users/mhjeon/.pyenv/versions/3.6.0/envs/djangocrawler/bin/python /Users/mhjeon/projects/djangocrawler/manage.py crontab run b7143ae3a11fd76146b49a5f54d11706 >> /crawllog.log # django-cronjobs for core

I'm using django within pyenv environment. Any ideas what it is not working?

from django-crontab.

kraiz avatar kraiz commented on July 17, 2024

Hi @mhoonjeon, that's kind of strange. django-crontab writes the python interpeter (or virtualenv) used to run the add subcommand into cronjob which seems to work fine for you.

It seems pyenv really need this PATH changes to actually work. Can you please assist and remove just the PATH line. If it's not working then, we double checked it and i'll add a pyenv-hint into the FAQ section of the README.

from django-crontab.

clock21am avatar clock21am commented on July 17, 2024

can you tell me what is the exactly that path is point to...I am getting the similiar issue

from django-crontab.

chirag-jn avatar chirag-jn commented on July 17, 2024

I usually add the following variables in crontab -e and things seem to be moving:

SHELL=/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin

from django-crontab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.