Comments (11)
@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.
Ok and what's the problem?
What the output of crontab -l
on the console?
from django-crontab.
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.
vehicle_control_system.persons.contrab -> vehicle_control_system.persons.crontab?
from django-crontab.
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.
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.
ty, I'm going to review
from django-crontab.
@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.
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.
can you tell me what is the exactly that path is point to...I am getting the similiar issue
from django-crontab.
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)
- python manage.py crontab add is not working on heroku server HOT 1
- ModuleNotFoundError: No module named 'fcntl'(windows ) HOT 1
- Cron job with hidden file
- How to run crontab job as user instead of root
- Django Crontab not working on a specific time HOT 6
- macOS 10.15.6 Failed to import the site module HOT 3
- Crontab does not work when running server HOT 3
- Django cronjob error while using database HOT 4
- Does it work in Django==3.1.2 ? HOT 3
- ImportError: Couldn't import Django HOT 1
- List of all optional argumentsfor django-crontab
- How to call a command with no-value arguments
- Why we can't add individual job and can't remove individual job to crontab HOT 1
- Not call cronjob HOT 6
- How do I run a job without adding it to cron HOT 2
- Consider moving the project to Jazzband? HOT 1
- Django Crontab on docker-image not reading env-variable from K8S deployment config HOT 1
- python3 manage.py crontab add not executing HOT 1
- Django Crontab Job Not Executing Within Docker Container HOT 9
- Can I set a timeout for a job?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-crontab.