Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
insights
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
insights
Commits
11d4a7d4
Commit
11d4a7d4
authored
Jul 12, 2013
by
Steve Komarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added celery documentation, switched to optional_parameter_call, minor fixes
parent
112d49d3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
14 deletions
+32
-14
README.md
+16
-0
src/edinsights/core/decorators.py
+8
-9
src/edinsights/core/tests.py
+2
-2
src/edinsights/settings.py
+6
-3
No files found.
README.md
View file @
11d4a7d4
...
@@ -80,6 +80,22 @@ the test module will be at:
...
@@ -80,6 +80,22 @@ the test module will be at:
http://127.0.0.1:8000/static/index.html
http://127.0.0.1:8000/static/index.html
Running periodic tasks
-------------------------------------
Periodic tasks (which are scheduled with core.decorators.cron)
rely on Celery for execution. It is the reponsability of the
client django project to ensure Celery is configured and running.
To configure, add the following to settings.py of your django
project:
from edinsights.celerysettings import
*
To start celery, run from your django project
python manage.py celery worker -B
Only tasks located in files named "tasks.py" located in the main
directory of your django project or installed django app will
be scheduled.
Building on top of the framework
Building on top of the framework
--------------------------------
--------------------------------
...
...
src/edinsights/core/decorators.py
View file @
11d4a7d4
...
@@ -21,6 +21,8 @@ from django.core.cache import cache
...
@@ -21,6 +21,8 @@ from django.core.cache import cache
from
django.conf
import
settings
from
django.conf
import
settings
from
celery.task
import
PeriodicTask
,
periodic_task
from
celery.task
import
PeriodicTask
,
periodic_task
from
util
import
optional_parameter_call
from
util
import
default_optional_kwargs
import
registry
import
registry
from
registry
import
event_handlers
,
request_handlers
from
registry
import
event_handlers
,
request_handlers
...
@@ -124,7 +126,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15, ignores = ["<class 'pymong
...
@@ -124,7 +126,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15, ignores = ["<class 'pymong
# process of computing it
# process of computing it
cached
=
cache
.
get
(
key
)
cached
=
cache
.
get
(
key
)
if
cached
:
if
cached
:
print
"Cache hit"
,
f
.
__name__
,
key
#
print "Cache hit", f.__name__, key
# If we're already computing it, wait to finish
# If we're already computing it, wait to finish
# computation
# computation
while
cached
==
'Processing'
:
while
cached
==
'Processing'
:
...
@@ -136,7 +138,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15, ignores = ["<class 'pymong
...
@@ -136,7 +138,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15, ignores = ["<class 'pymong
results
=
cached
results
=
cached
if
not
cached
:
if
not
cached
:
print
"Cache miss"
,
f
.
__name__
,
key
#
print "Cache miss",f.__name__, key
# HACK: There's a slight race condition here, where we
# HACK: There's a slight race condition here, where we
# might recompute twice.
# might recompute twice.
cache
.
set
(
key
,
'Processing'
,
timeout
)
cache
.
set
(
key
,
'Processing'
,
timeout
)
...
@@ -162,14 +164,11 @@ def cron(run_every, params=None):
...
@@ -162,14 +164,11 @@ def cron(run_every, params=None):
python manage.py celery worker -B --loglevel=INFO
python manage.py celery worker -B --loglevel=INFO
Celery beat will automatically add tasks from files named 'tasks.py'
Celery beat will automatically add tasks from files named 'tasks.py'
'''
'''
def
factory
(
f
):
def
factory
(
f
unc
):
@periodic_task
(
run_every
=
run_every
,
name
=
f
.
__name__
)
@periodic_task
(
run_every
=
run_every
,
name
=
f
unc
.
__name__
)
def
run
():
def
run
():
from
edinsights
import
core
optional_parameter_call
(
func
,
default_optional_kwargs
,
params
)
mongodb
=
core
.
util
.
get_mongo
(
f
)
return
decorator
(
run
,
func
)
fs
=
core
.
util
.
get_filesystem
(
f
)
f
(
fs
,
mongodb
,
params
)
return
decorator
(
run
,
f
)
return
factory
return
factory
def
event_property
(
name
=
None
,
description
=
None
):
def
event_property
(
name
=
None
,
description
=
None
):
...
...
src/edinsights/core/tests.py
View file @
11d4a7d4
...
@@ -14,7 +14,7 @@ from celery.task import periodic_task
...
@@ -14,7 +14,7 @@ from celery.task import periodic_task
@cron
(
run_every
=
timedelta
(
seconds
=
1
))
@cron
(
run_every
=
timedelta
(
seconds
=
1
))
def
test_cron_task
(
*
args
):
def
test_cron_task
():
""" Simple task that gets executed by the scheduler (celery beat).
""" Simple task that gets executed by the scheduler (celery beat).
The test case test_cron verifies that the execution
The test case test_cron verifies that the execution
has taken place.
has taken place.
...
@@ -28,7 +28,7 @@ def test_cron_task(*args):
...
@@ -28,7 +28,7 @@ def test_cron_task(*args):
@cron
(
run_every
=
timedelta
(
seconds
=
1
))
# cron decorators should go on top
@cron
(
run_every
=
timedelta
(
seconds
=
1
))
# cron decorators should go on top
@memoize_query
(
60
)
@memoize_query
(
60
)
def
test_cron_memoize_task
(
*
args
):
def
test_cron_memoize_task
():
""" Simple task that gets executed by the scheduler (celery beat).
""" Simple task that gets executed by the scheduler (celery beat).
The test case test_cron_and_memoize verifies that the execution
The test case test_cron_and_memoize verifies that the execution
has taken place.
has taken place.
...
...
src/edinsights/settings.py
View file @
11d4a7d4
...
@@ -194,9 +194,12 @@ LOGGING = {
...
@@ -194,9 +194,12 @@ LOGGING = {
}
}
}
}
##uncomment to provide full location of code that uses naive datetime
# # By default timezone-related warnings do not display the location in code
#import warnings
# # where they occurred. The code below will turn these warnings into
#warnings.filterwarnings(
# # exceptions with stack trace so that one can identify the offending code.
# # Uncomment to turn timezone warnings into exceptions
# import warnings
# warnings.filterwarnings(
# 'error', r"DateTimeField received a naive datetime",
# 'error', r"DateTimeField received a naive datetime",
# RuntimeWarning, r'django\.db\.models\.fields')
# RuntimeWarning, r'django\.db\.models\.fields')
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment