kraiz / django-crontab Goto Github PK
View Code? Open in Web Editor NEWdead simple crontab powered job scheduling for django.
License: Other
dead simple crontab powered job scheduling for django.
License: Other
Hey @kraiz
first off thanks for making this amazing utility, its great & dead simple to use.
Actually I am django-crontab for a project, my use case is, I want to fetch data from an api, every 1 hour, and save it into a database using a Django model and migration stuff. So far I've been able to write a function which fetches data,
def getData():
url = 'http://api.getdata.com/delhi' #sample url
r = requests.get(url)
weather = r.json()
data = {'weather'weather['data']}
w_data = weathers()
w_data.wdata = data
w_data.save()
So the data
variable is to be stored in database every 1 hour. So I'm kinda stuck how to do this every 1 hour,
should I add getData() in CRONJOBS in settings.py ?
This is where I'm unable to figure out how to use crontab in this use case, I'm quite new to python and django, it'll be a great help
Thanks ๐
Hey,
I'm quite new with Django and I'm trying to use your work for my project. I followed your steps in the documentation but I am getting the error
ImportError: No module named 'fcntl'.
Am I missing any basic step in python installation? If it matters, I'm using Windows OS.
Hope you can help!
Thanks,
Matthew Go
I've many projects on the same machine, each one has its own virtualenv.
If I add a cronjob for just 1 project everything works fine, but when I add a cronjob of another project it replaces the previously added cronjob.
I think the reason is that CRONTAB_DJANGO_MANAGE_PATH
and CRONTAB_PYTHON_EXECUTABLE
are different for each project, then there should be the possibility to specify these paths for each cronjob to avoid paths overwrite errors.
Hi there, Im assuming the remove_cronjobs is executed when running "crontab add" to make sure that no duplicates are inserted, but it would be nice to find a better way somehow.
The reason is that I have multiple django instances on the same server, and apparently the command_lines array that django_crontab uses applies to all of them, not specifically to a particular django instance.. so, whenever I try to add cronjobs from one instance, all the jobs from the other one are removed first, which is not so nice.
Cheers
I have the issue when im in console
ubuntu@ip-XXX-XX-XX-XXX:~/connectus2$ sudo python manage.py crontab run
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 342, in execute
self.check()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/usr/local/lib/python2.7/dist-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/ubuntu/connectus2/connectus2/urls.py", line 16, in <module>
from django.conf.urls import patterns, url
ImportError: cannot import name patterns
I solved downgrading to 1.9
myapp/cron.py
def my_scheduled_job(value):
print('hello %s' % value)
I tried the flow code:
CRONJOBS = [
('*/5 * * * *', 'myapp.cron.my_scheduled_job("world")' ),
('*/5 * * * *', 'myapp.cron.my_scheduled_job("python")' ),
]
return AttributeError: module 'myapp.cron' has no attribute 'my_scheduled_job("world")'
Writing and running tests showed that equal job tuples from CRONJOBS does not always generate the same hash. For the following job i found different hashs generated:
('*/1 * * * *', 'tests.cron.cron_job', [1, 'two'], {'a': 's2', 'test': 34})
fe2f7249477f5c7270f08a7a74733c98
13e8169dffe273b8b0c5f8abe1b6f643
This needs some further investigation as tests sometimes pass, sometimes not depending on which hash gets generated.
settings.py:
# django-crontab
CRONJOBS = [
('* * * * *', 'owl.cron.my_scheduled_job', '>> cron.log')
]
cron.py:
from django.utils import timezone
def my_scheduled_job():
now = timezone.now()
print('running daily_order_summary ({})'.format(now))
I can tell that the job is running, because "cron.log" is created every minutes, but it's always empty.
Please advise?
Hi, first thanks for working on this django extension.
I tried using format #1 like this:
CRONJOBS = [
('*/1 * * * *', 'myapp.cron.cron_job', '> /home/myhome/logs/cron_job.log')
]
My method cron_job() takes no argument
django_crontab's logging error saying cron_job takes no argument but 32 given in this case. somehow your code is trying to pass the redirection path into my method as argument and treating each character as an individual argument?
I'm sorry for making this a issue but I couldn't find any answers anywhere and no contact info for any of the contributors.
I followed the readme and was able to register my cronjobs and add my crontabs without it reporting any errors, but, no jobs are being executed. I even tried creating a log file but that's not being created also.
System:
Python 2.7.12
Django 1.8.14
django-crontab 0.7.1
Would I run different context?
diff --git a/django_crontab/app_settings.py b/django_crontab/app_settings.py
index 2623aca..4450699 100644
--- a/django_crontab/app_settings.py
+++ b/django_crontab/app_settings.py
@@ -41,3 +41,5 @@ COMMAND_PREFIX = getattr(settings, 'CRONTAB_COMMAND_PREFIX', '')
COMMAND_SUFFIX = getattr(settings, 'CRONTAB_COMMAND_SUFFIX', '')
LOCK_JOBS = getattr(settings, 'CRONTAB_LOCK_JOBS', False)
+
+CRONTAB_SETTINGS_MODULE = getattr(settings, 'CRONTAB_SETTINGS_MODULE', os.environ['DJANGO_SETTINGS_MODULE'])
diff --git a/django_crontab/management/commands/crontab.py b/django_crontab/management/commands/crontab.py
index f0a6ed6..e0ece51 100644
--- a/django_crontab/management/commands/crontab.py
+++ b/django_crontab/management/commands/crontab.py
@@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand
from django.utils.importlib import import_module
from django_crontab.app_settings import CRONTAB_EXECUTABLE, CRONJOBS, \
CRONTAB_LINE_PATTERN, CRONTAB_COMMENT, PYTHON_EXECUTABLE, DJANGO_MANAGE_PATH, \
- CRONTAB_LINE_REGEXP, COMMAND_PREFIX, COMMAND_SUFFIX, LOCK_JOBS
+ CRONTAB_LINE_REGEXP, COMMAND_PREFIX, COMMAND_SUFFIX, LOCK_JOBS, CRON_SETTINGS_MODULE
import fcntl
import hashlib
import json
@@ -81,14 +81,15 @@ class Command(BaseCommand):
'comment': CRONTAB_COMMENT,
'command': (
'%(global_prefix)s %(exec)s %(manage)s crontab run '
- '%(jobname)s %(job_suffix)s %(global_suffix)s'
+ '%(jobname)s %(job_suffix)s %(global_suffix)s --settings=%(settings_module)s'
) % {
'global_prefix': COMMAND_PREFIX,
'exec': PYTHON_EXECUTABLE,
'manage': DJANGO_MANAGE_PATH,
'jobname': self.__hash_job(job),
'job_suffix': job_suffix,
- 'global_suffix': COMMAND_SUFFIX
+ 'global_suffix': COMMAND_SUFFIX,
+ 'settings_module': CRONTAB_SETTINGS_MODULE
}
})
if options.get('verbosity') >= '1':
I have a tasks.py file that's located in project/app/tasks.py that uses the standard logger:
import logging
logger = logging.getLogger(__name__)
The logging file is configured with loggers for all of the following:
django
, app
, django_crontab
, django_crontab.crontab
, crontab
, and ''
When is open the shell and run the function, the logging appears:
python manage.py shell
import django
django.setup()
from app.tasks import my_scheduled_task()
my_scheduled_task()
Yet, when I add the cron job using python manage.py crontab add
everything works (I can see the end result appear), yet nothing gets logged. Any reason why logging should work using the shell, but not as a cron?
How it could be resolved per one crontab
management command call?
It is convenient to have periodic jobs as django commands (some of them already are, e.g. "clearsessions").
But crontab currently allows to specify python functions only, which are effectively run inside a "crontab run" command.
Please remove this restriction.
Hi @kraiz, thanks for your work on this project. I've been using django-crontab for the last year, it's simple and pretty much Just Works. However I've noticed recently that django-crontab logging doesn't appear to use the default timezone.
settings.py
TIME_ZONE = 'America/Toronto' # -05:00 EST
USE_TZ = True
CRONJOBS = [
('0 9 * * *', 'myapp.cron.daily_order_summary', '>> cron.log'),
]
cron.py
from django.utils import timezone
def daily_order_summary():
now = timezone.now()
print('running daily_order_summary ({})'.format(now))
cron.log
running daily_order_summary (2017-01-11 14:00:03.304917+00:00)
I was expecting cron.log to be
running daily_order_summary (2017-01-11 09:00:03.304917-05:00)
Here's my server time a few minutes after running the above cron, note the "EST"
django@host:~$ date
Wed Jan 11 09:03:39 EST 2017
I'm running
To be clear, the cron job runs at the correct time, but the logging output for some reason isn't displaying the correct timezone.
Hey @kraiz ๐
I've been using django-crontab since three months now and its super awesome. I just wanted to ask if there is any special setting required to run cron jobs inside gunicorn.
Actually my scenario is that we want to make some HTTP requests through the cronjob. Now while running Django Development Server, cron jobs are working perfectly. But the issue is when I run them in Docker + gunicorn setup, the cronjobs get registered (checked using crontab -l
) alright, but none of them work.
Here's what I've been trying,
Do yo think its something related to worker processes in gunicorn, I'm having absolutely no idea about this even after a week of googleing. Any help or pointers would really be great!
Thanks a lot!
When i call ->
python manage.py crontab run job_id, I got the above error
i can run the command 'add' in my own laptop(Mac), while i can't run it on the centos(7.0) server.
it's always show notification 'bad command'.
ps: we are using django 1.9
django-crontab 0.7.0
While the Crontab app executes as required, The logger of is not working properly. I have investigated and found that this is the comment that it shows "No handlers could be found for logger "django_crontab.crontab"" .
Can you please tell me what, if any, changes need to be done in the settings.py of my project to solve this issue.
Thanks
Although I have defined the CRONTAB_DJANGO_MANAGE_PATH variable on the settings.py
Any idea?
Traceback (most recent call last):
File "private/devcon/manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 443, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/init.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
import(name)
File "/usr/local/lib/python2.7/dist-packages/django_crontab-0.3-py2.7.egg/django_crontab/management/commands/crontab.py", line 3, in
from django_crontab.app_settings import CRONTAB_EXECUTABLE, CRONJOBS,
File "/usr/local/lib/python2.7/dist-packages/django_crontab-0.3-py2.7.egg/django_crontab/app_settings.py", line 20, in
DJANGO_MANAGE_PATH = getattr(settings, 'CRONTAB_DJANGO_MANAGE_PATH', import_module(DJANGO_PROJECT_NAME + '.manage').file.replace('pyc', 'py'))
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
import(name)
ImportError: No module named manage
django-crontab
settings:CRONJOBS = [
('*/1 * * * *', 'indicei3.cron.test_cron', '>> /tmp/scheduled_job.log')
]
crontab -l
after running python manage.py crontab add
. adding cronjob: (14916de3431e91ed32d3691cfe1be719) -> ('*/1 * * * *', 'indicei3.cron.test_cron', '>> /tmp/scheduled_job.log')
crontab run
command and I copy this command to my terminal the job works: yes/noNo
I have been searching for a solution for some hours now but I couldn't find anything
This is my cron.py:
def test_cron():
print("Hello")
I start the server but nothing happens. The file under tmp/schedule_job.log does not get written.
Thanks in advance.
Old version README is making problems in pip, i cannot install it
Downloading/unpacking django-crontab
Running setup.py egg_info for package django-crontab
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "$SOME_PATH$/build/django-crontab/setup.py", line 12, in <module>
long_description=open('README.md').read(),
IOError: [Errno 2] No such file or directory: 'README.md'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "$SOME_PATH$/build/django-crontab/setup.py", line 12, in <module>
long_description=open('README.md').read(),
IOError: [Errno 2] No such file or directory: 'README.md'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in $SOME_PATH$/toopo/build/django-crontab
I'm developing a module with the crontab.
Actually, the framework I'm using is django so I did install 'django-crontab'
I did test as the instruction did and make it with localhost environment.
When I deployed("sudo service apache2 restart"
) it on AWS after doing a command 'python manage.py crontab add'
, it didn't work.
I thiknk it's working on only localhost environment, isn't it?
How can I solve this problem?
Hi guys,
this may not be an issue, but I have a great doubt on how to make the management command work in my server
I receive
django@ip-xxxxxxxxxxx:/srv/venturefund.io/venturefund$ ./manage.py crontab add
no crontab for django
adding cronjob: (254d9abcc1aefdee36b6b5d329edbb56) -> ('0 2 * * 2 *', 'projects.cron.weekly_activity_digest.send_digest')
adding cronjob: (8fb9ca9f309c97b8a278ea1b49e04d2b) -> ('0 2 * * 2 *', 'django.core.management.call_command', ['set_new_investors_count'])
"/tmp/tmpFbC0M9":0: bad command
errors in crontab file, can't install.
I don't know what I did wrong. Can you help me understand what's going on?
django-crontab
settings:CRONJOBS = [('* * * * *', 'core.enquetes.cron.func')]
/usr/src/app# python manage.py crontab show Currently active jobs in crontab: cde74bdd655f575c043ed27d9c7da793 -> ('* * * * *', 'core.enquetes.cron.func')
crontab -l
* * * * * /usr/local/bin/python3 /usr/src/app/manage.py crontab run cde74bdd655f575c043ed27d9c7da793 # django-cronjobs for base
python manage.py crontab run cde74bdd655f575c043ed27d9c7da793
(inside docker container) - WORK
But the automatic version dosent work ;/
Everything went perfectly when implementing django-crontab to my project. After executing the python manage.py crontab add, it adds the job to crontab (I checked using crontab -l) but crontab doesn't seem to be doing anything. There are no errors and a log isn't even generated. I'm using the django 1.6 with python 2.7.
Commands in the project directory:
$ python manage.py crontab add
adding cronjob: (1ac092f177e6b21c85c301d59022d7f6) -> ('* * * * *', 'roomer.cron.my_scheduled_job', [], {}, '>> /home/isimar/project/roomer/cron_log/my_scheduled_job.log 2>&1')
$ crontab -l
$ python manage.py crontab run 1ac092f177e6b21c85c301d59022d7f6
(Works - does what its suppose to do, so the problem seems to be with the crontab)
django-crontab
settings:CRONJOBS = [
('*/1 * * * *', 'bitcoin_rate_monitor.main.cron.update_rates')
]
def update_rates():
from ..main.models import Provider
provider_set = Provider.objects.all()
for provider in provider_set:
provider.do_update_rate()
crontab -l
after running python manage.py crontab add
.*/1 * * * * /usr/bin/python3 /vagrant/bitcoin_rate_monitor/manage.py crontab run efc4cde65aae2b54915c6b3d90d3a4bc # django-cronjobs for config
/usr/bin/python3 /vagrant/bitcoin_rate_monitor/manage.py crontab run efc4cde65aae2b54915c6b3d90d3a4bc
Jan 7 06:39:01 ubuntu-xenial CRON[1822]: (ubuntu) CMD (/usr/bin/python3 /vagrant/bitcoin_rate_monitor/manage.py crontab run efc4cde65aae2b54915c6b3d90d3a4bc # django-cronjobs for config)
Jan 7 06:40:01 ubuntu-xenial CRON[1837]: (ubuntu) CMD (/usr/bin/python3 /vagrant/bitcoin_rate_monitor/manage.py crontab run efc4cde65aae2b54915c6b3d90d3a4bc # django-cronjobs for config)
Hi, I'm wondering if there is a simple way to log stderr?
Recently discovered a cronjob that was silently failing for a few weeks and caused some headaches and would like to avoid this in the future.
Hi @kraiz
I scheduled a job using crontab and I would like to keep track of it in the Django site administration. I used to have a scheduled job using cron and I can see each performed task as I run
python manage.py migrate django_cron
If I try to do the same with django_crontab, I get: CommandError: App 'django_crontab' does not have migrations.
Is there a way to do something alike?
Thank you!
i set my env and script as README.rst
and my task in cron.py like:
...
...
def task1():
log.info("i 'm task 1");#log msg to a file
when i run(i'm in vritual env)
python manage.py crontab add
and there is nothing occured
i checked linux env with command "crontab -e", it shows like
*/2 * * * *ใ/myvirtualenv/bin/python /myworkpath/manage.py crontab run c3a5f648ad78e794a12c664a
then i type /myvirtualenv/bin/python /myworkpath/manage.py crontab run c3a5f648ad78e794a12c664a
directly in terminal it's shows:
...
...
Importerror :no module named myapp.cron
it's confused me ,what's root issue ?
I'm getting this error and I installed from pip.
Can you let me know how to fix this?
Thank you
django-crontab
settings:CRONJOBS = [
('* * * * *', 'student_collaboration.cron.set_open_help_request_to_pending'),
('* * * * *', 'student_collaboration.cron.close_pending_help_requests_automatically_when_expired'),
]
When I run python manage.py crontab add
adding cronjob: (7931e4f0fc70fdb88ed51de09299094a) -> ('* * * * *', 'student_collaboration.cron.set_open_help_request_to_pending')
adding cronjob: (da9d5e4cf8f5753ba16b9f786fd864b8) -> ('* * * * *', 'student_collaboration.cron.close_pending_help_requests_automatically_when_expired')
crontab -l
after running python manage.py crontab add
.* * * * * /home/jy95/Documents/oscareducation/ve/bin/python /home/jy95/Documents/oscareducation/manage.py crontab run 7931e4f0fc70fdb88ed51de09299094a # django-cronjobs for oscar
* * * * * /home/jy95/Documents/oscareducation/ve/bin/python /home/jy95/Documents/oscareducation/manage.py crontab run da9d5e4cf8f5753ba16b9f786fd864b8 # django-cronjobs for oscar
My projet tree:
/oscar (the main app)
settings.py (where the crontab schedule are set)
/student_collaboration (sub app)
cron.py (where the cron function are defined)
The github repo : https://github.com/JonathanSamelson/oscareducation/tree/prototype_2
Running cron with activated virtualenv using /usr/local/www/project/venv/bin/python /usr/local/www/project/app/manage.py crontab run a2cb3e38b81be23bf313e171a630b684
works without any error.
But in the crontab-Log there are is a FileNotFoundError
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpflqhnzil/texput.pdf'
Maybe a bug? Would be great if the cronjob in crontab behaves like when being manually executed in the virtualenv
Python 3.4
Django 1.9.8
django-crontab 0.7.1
i have two apps in same server: /home/django/app1 /home/django/app2
if i'll run python manage.py crontab add in app1-folder it will work
but if i'll run python manage.py crontab add in app2-folder after previous step, it will print error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/django_crontab/management/commands/crontab.py", line 20, in handle
crontab.remove_jobs()
File "/usr/local/lib/python2.7/dist-packages/django_crontab/crontab.py", line 118, in remove_jobs
self.__get_job_by_hash(job[0][2][job[0][2].find('crontab run') + 12:].split()[0])
File "/usr/local/lib/python2.7/dist-packages/django_crontab/crontab.py", line 173, in __get_job_by_hash
'Run "python manage.py crontab add" again to resolve this issue!' % job_hash
RuntimeError: No job with hash 6e36fac415c5f7df8cec638e7cfb9f5f found. It seems the crontab is out of sync with your settings.CRONJOBS. Run "python manage.py crontab add" again to resolve this issue!
If you have two jobs that are running in parallel at the same time, and both of them want to write to same log file, only one of the will succeed. But in most cases you don't want to separate log file for each specific job and you want to log them altogether. I think currently django-crontab
does not handle this situation, does it?
While debugging server out of memory issues on my box, it seems like the UNIX process for crontab run for my job doesn't die after the job is finished. And for the next run, a new process is spawned eventually leading to a lot of live processes for the same cron job.
My CRON settings are like this -
CRONJOBS = [ ('*/1 * * * *', 'restserver.cron.my_task') ]
CRONTAB_LOCK_JOBS = True
The job is just a couple of log statements.
And every minute I see a new UNIX process being spawned with the same command -
/usr/bin/python /path/to/my//manage.py crontab run aaade9ebea079cbbe06c202ef28c67d
Is this expected ? How to make sure the process dies after the cron run instance is finished ?
@jiangmf @kraiz am running a management command manually like this python manage.py check_celery_status
but unable to run it through this module. then command lies in a file under myapp.management.commands.command_file
class Command(BaseCommand):
def handle(self, *args, **options):
"""
The command to check if celery is up
"""
date = dt.now().date()
print str(date)
I'm interested in implementing this app on my django app (mainly because of immense difficulties using native crontab) -- is it still in active development?
I defined my task, but doesn't want show, I added a simple code:
def my_scheduled_job():
#your functionality goes right here
print('hello')
and on setting I putted this:
CRONJOBS = [
('*/2 * * * *', 'vehicle_control_system.persons.contrab.my_scheduled_job'),
]
but first I ran python manage.py contrab add and later I run django with python manage.py runserver
Hello,
i'm trying to add and run a task but i've problem having it configured.
I've an enviroment and different confs that change from machine to machine.
When it runs on the server the DJANGO_SETTING_MODULE is set by the wsgi.
So, for the crontab-django i added this:
CRONTAB_DJANGO_SETTINGS_MODULE = 'settings.ste'
i've this job
('* * * * *', 'rest.cron.test', ">> /tmp/out.txt")
def test():
print "echo"
with turns out to be
* * * * * /Users/stefano/.virtualenvs/myv/bin/python /Users/stefano/SW/aoo-rest/dj/manage.py crontab run 524562a16a9a3585f2cf9511e5cb303d --settings=settings.ste >> /tmp/out.txt # django-cronjobs for settings
if i run django-admin crontab run 524562a16a9a3585f2cf9511e5cb303d
it works (but prints the output in the console)
if i paste this in the console it works (prints in the console)
it does not work when executed by cron*
in the /var/mail/stefano
i find this every minute
Traceback (most recent call last):
File "/Users/stefano/SW/rest/dj/manage.py", line 7, in <module>
django.setup()
File "/Users/stefano/.virtualenvs/rest/lib/python2.7/site-packages/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Users/stefano/.virtualenvs/rest/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/Users/stefano/.virtualenvs/rest/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
i run "crontab -e", clear all jobs
after that i run:
python manage.py crontab add
python manage.py crontab show
Currently active jobs in crontab:
command "python manage.py crontab show" also do nothing
I have succesfully scheduled jobs that run at the start of every minute and every 5 minutes. This was accomplished by using the examples in the readme. However, when I wanted to schedule a task for the start of every hour I could not register it with cron syntax and when I added a forward slash to it it would register but NOT run.
It would be of great help if you could add these to the examples:
Run task every hour
Run task every week
Run task at midnight
Run task monthly
Run task every year
Run task on 1 st of month
Run task on last day of month
I have searched a lot on the internet to achieve my goal but there is no help regarding this repository.
Thanks in advance.
Regard,
Waleed
/myapp/lib/python2.7/site-packages/django_crontab/crontab.py:13:
RemovedInDjango19Warning: django.utils.importlib will be removed in Django 1.9.
from django.utils.importlib import import_module
Just to warn
Yesterday Django 1.9 came out and I am still getting warnings on django_crontab. Will you support django 1.9. I believe there is just this minor fix needed.
python/virtenv/lib/python2.7/site-packages/django_crontab-0.6.0-py2.7.egg/django_crontab/crontab.py:13: RemovedInDjango19Warning: django.uti$ from django.utils.importlib import import_module
Will new version of django-crontab be soon available with pip?
here is old issue - #25
Few questions -
Hello there
Running ubuntu16, django1.10 through docker.
Can anyone tell me what the path to the crontab executable is, or how I find it?
I'm getting this error running crontab add
sh: 1: /usr/bin/crontab: not found
adding cronjob: (d5fc228456872d633a9fd2f18a2ace15) -> ('*/5 * * * *', 'research.cron.update_feeds')
sh: 1: /usr/bin/crontab: not found
which crontab on the server replies with nothing
On a non docker ubuntu16 which crontab replies with /usr/bin/crontab
I think it's because I must be root on the container.
Anyone got any ideas on how to get around this?
CRONTAB_COMMAND_PREFIX = "echo 'cd {} && . venv/bin/activate &&".format(
config['pkg_path'])
Why do I have to run cd
in PREFIX when I specified absolute path to manage.py
CRONTAB_DJANGO_MANAGE_PATH
? I think it should be saved on crontab add
step
When I attempt to run job manually, I get an error:
MacBook-Pro-Aleksandr:beauty aperechnev$ python manage.py crontab run
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django_crontab/management/commands/crontab.py", line 29, in handle
Crontab().run_job(options['jobhash'])
File "/Library/Python/2.7/site-packages/django_crontab/crontab.py", line 126, in run_job
job = self.__get_job_by_hash(job_hash)
File "/Library/Python/2.7/site-packages/django_crontab/crontab.py", line 173, in __get_job_by_hash
'Run "python manage.py crontab add" again to resolve this issue!' % job_hash
RuntimeError: No job with hash None found. It seems the crontab is out of sync with your settings.CRONJOBS. Run "python manage.py crontab add" again to resolve this issue!
But the job is registered and already in sync with django-crontab
:
MacBook-Pro-Aleksandr:beauty aperechnev$ python manage.py crontab show
Currently active jobs in crontab:
2755b3a03042fdf7b9c8edbcaff737f6 -> ('0 * * * *', 'grabber.cron.retrieve_new_images')
My crontab job is running fine on development. I just cannot make it work on aws elastic beanstalk.
Hi there!
I'm wanting to use Django-Crontab with virtualenv and am running into some issues.
If I give the full package path (I.e., "myproject.myapp.cron.myjob"), I get the following error:
No module named myapp.cron
If I change the path to myapp.cron.myjob, I get the following error:
No handlers could be found for logger 'django_crontab.management.commands.crontab
The crontab being generated looks like:
*/1 * * * * /Users/aendrew/Sites/django/ENV/bin/python /Users/aendrew/Sites/django/myproject/manage.py crontab run b036bdd89a12df2d0f85d87c9c01c8d7 #django-cronjobs for myproject
Any help? Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.