Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ env:
- DJANGO=2.0.* DJANGO_SETTINGS_MODULE='settings_sqllite'
- DJANGO=2.0.* DJANGO_SETTINGS_MODULE='settings_postgres'
- DJANGO=2.0.* DJANGO_SETTINGS_MODULE='settings_mysql'
services:
- postgresql
- mysql
addons:
- postgresql: "9.3"
postgresql: "9.6"
install:
- pip install -q Django==$DJANGO
- pip install coveralls
Expand All @@ -21,9 +24,9 @@ script:
after_success:
- coveralls
before_script:
- mysql -e 'create database travis_test;'
- psql -c 'create database travis_test;' -U postgres
- flake8 . --config=flake8
- sudo mysql -e 'create database travis_test;'
- sudo -u postgres psql -c 'create database travis_test;'
# - sudo python -m flake8 . --config=flake8
matrix:
exclude:
- python: "2.7"
Expand Down
67 changes: 67 additions & 0 deletions FORK_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

Summary of my fork changes
=======================
- Access to change CronJobManager from django settings if required.

```python
CRON_MANAGER = 'path.to.custom.MyManager'
```

---
- Add day config to CronJob schedule:

```python
day_of_month='*', # cron format: '*/10+5' '5,15,25' or list: [1] * 31
month_numbers='*', # cron format: '*/3' '0,3,6,9' or list: [1] * 12
day_of_week='*', # cron format: '*/2' '2,4,6' or list: [1] * 7
```

Example:
```python
from django_cron import CronJobBase, Schedule

class ExampleCronJob(CronJobBase):
RUN_AT_TIMES = ['10:10', '22:10']
schedule = Schedule(run_at_times=RUN_AT_TIMES, day_of_week='2')
code = 'cron.ExampleCronJob'
def do(self):
pass

```

---
- Add a method to CronJob to get future run times in future by this parameters:
`from_datetime` and `to_datetime`

---
- Move should_run_now method to CronJob to override it if required.

Example:

```python
from django_cron import CronJobBase, Schedule
from datetime import datetime


class TestCronJob(CronJobBase):
RUN_AT_TIMES = ['10:10', '22:10']
schedule = Schedule(
run_at_times=RUN_AT_TIMES,
# day_of_week='*/2',
)

code = 'demo.TestCronJob'

def do(self):
print('do TestCronJob')
return f'do TestCronJob at {datetime.now()}'

def should_run_now(self, force=False):
print('override should_run_now in cron job')
'''
if some_conditions_to_avoid_run_job:
return False
'''
return super(TestCronJob, self).should_run_now(force=force)

```
20 changes: 9 additions & 11 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
===========

django-cron
===========

.. image:: https://travis-ci.org/Tivix/django-cron.png
:target: https://travis-ci.org/Tivix/django-cron


.. image:: https://coveralls.io/repos/Tivix/django-cron/badge.png
:target: https://coveralls.io/r/Tivix/django-cron?branch=master


.. image:: https://readthedocs.org/projects/django-cron/badge/?version=latest
:target: https://readthedocs.org/projects/django-cron/?badge=latest
![https://travis-ci.org/QueraTeam/django-cron](https://travis-ci.org/QueraTeam/django-cron.png)
![https://coveralls.io/r/Tivix/django-cron?branch=master](https://coveralls.io/repos/Tivix/django-cron/badge.png)
![https://readthedocs.org/projects/django-cron/?badge=latest](https://readthedocs.org/projects/django-cron/badge/?version=latest)

Django-cron lets you run Django/Python code on a recurring basis providing basic plumbing to track and execute tasks. The 2 most common ways in which most people go about this is either writing custom python scripts or a management command per cron (leads to too many management commands!). Along with that some mechanism to track success, failure etc. is also usually necesary.

Expand All @@ -23,3 +16,8 @@ Documentation
http://django-cron.readthedocs.org/en/latest/

This open-source app is brought to you by Tivix, Inc. ( http://tivix.com/ )


Fork Documentation
=====================
you can see new features documentation from this [link](FORK_README.md)
8 changes: 8 additions & 0 deletions demo/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django_cron import CronJobManager


class MyManager(CronJobManager):

def should_run_now(self, force=False):
print(f'--- custom CronJobManager: {self}')
return super(MyManager, self).should_run_now(force)
44 changes: 43 additions & 1 deletion demo/demo/cron.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.contrib.auth.models import User

from datetime import datetime
from django_common.helper import send_mail
from django_cron import CronJobBase, Schedule

Expand All @@ -23,3 +23,45 @@ def do(self):
'[email protected]',
['[email protected]']
)


class EmailUsercountCronJob2(CronJobBase):
"""
Send an email with the user count.
"""
RUN_AT_TIMES = ['10:10', '22:10']

schedule = Schedule(run_at_times=RUN_AT_TIMES, day_of_week='2')
code = 'cron.EmailUsercountCronJob'

def do(self):
message = 'Active users: %d' % User.objects.count()
print(message)
send_mail(
'[django-cron demo] Active user count',
message,
'[email protected]',
['[email protected]']
)


class TestCronJob(CronJobBase):
RUN_AT_TIMES = ['10:10', '22:10']
schedule = Schedule(
run_at_times=RUN_AT_TIMES,
# day_of_week='*/2',
)

code = 'demo.TestCronJob'

def do(self):
print('do TestCronJob')
return f'do TestCronJob at {datetime.now()}'

def should_run_now(self, force=False):
print('override should_run_now in cron job')
'''
if some_conditions_to_avoid_run_job:
return False
'''
return super(TestCronJob, self).should_run_now(force=force)
4 changes: 4 additions & 0 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
'django_cron'
]

CRON_MANAGER = 'demo.MyManager'

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
Expand Down Expand Up @@ -126,4 +128,6 @@

CRON_CLASSES = [
"demo.cron.EmailUsercountCronJob",
"demo.cron.EmailUsercountCronJob2",
"demo.cron.TestCronJob"
]
Loading