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
bee0e50f
Commit
bee0e50f
authored
Jul 22, 2013
by
Steve Komarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added not NotInCacheError
parent
776748b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
8 deletions
+17
-8
src/edinsights/core/decorators.py
+3
-2
src/edinsights/periodic/__init__.py
+10
-2
src/edinsights/periodic/tests.py
+4
-4
No files found.
src/edinsights/core/decorators.py
View file @
bee0e50f
...
...
@@ -101,7 +101,8 @@ def query(category = None, name = None, description = None, args = None):
return
query_factory
class
NotInCacheError
(
Exception
):
pass
def
mq_force_memoize
(
func
):
"""
...
...
@@ -232,7 +233,7 @@ def memoize_query(cache_time = 60*4, timeout = 60*15, ignores = ["<class 'pymong
# print "Forcing retrieve %s %s " % (f.__name__, key)
results
=
get_from_cache_if_possible
(
f
,
key
)
if
not
results
:
raise
KeyError
(
'key
%
s not found in cache'
%
key
)
# TODO better exception class?
raise
NotInCacheError
(
'key
%
s not found in cache'
%
key
)
return
results
decfun
=
decorator
(
opmode_default
,
f
)
...
...
src/edinsights/periodic/__init__.py
View file @
bee0e50f
# This module provides tests for periodic tasks using core.decorators.cron
from
edinsights.core.decorators
import
view
,
mq_force_retrieve
from
edinsights.core.decorators
import
view
,
mq_force_retrieve
,
NotInCacheError
from
edinsights.periodic.tasks
import
big_computation
,
big_computation_withfm
@view
()
...
...
@@ -10,4 +10,12 @@ def big_computation_visualizer():
@view
()
def
big_computation_visualizer_withfm
():
return
"<html>
%
s</html>"
%
mq_force_retrieve
(
big_computation_withfm
)()
try
:
# returns instantly, does not perform computation if results are not
# in cache
result
=
mq_force_retrieve
(
big_computation_withfm
)()
except
NotInCacheError
:
result
=
"The big computation has not been performed yet"
# alternatively you can display a "please wait" message
# and run big_computation_withfm() without force_retrieve
return
"<html>
%
s</html>"
%
result
src/edinsights/periodic/tests.py
View file @
bee0e50f
...
...
@@ -56,7 +56,7 @@ class SimpleTest(TestCase):
"""
truncate_tempfile
(
'test_cron_task_counter'
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Tru
e
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Fals
e
)
# verify number of calls and time of last call
ncalls
,
last_call
=
count_timestamps
(
'test_cron_task_counter'
)
...
...
@@ -74,7 +74,7 @@ class SimpleTest(TestCase):
# clear the cache from any previous executions of this test
cache
.
delete
(
'test_cron_memoize_unique_cache_key'
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Tru
e
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Fals
e
)
ncalls
,
last_call
=
count_timestamps
(
'test_cron_memoize_task'
)
self
.
assertEqual
(
ncalls
,
1
)
# after the first call all subsequent calls should be cached
self
.
assertAlmostEqual
(
last_call
,
time
.
time
(),
delta
=
100
)
...
...
@@ -91,7 +91,7 @@ class SimpleTest(TestCase):
# delete cache from previous executions of this unit test
cache
.
delete
(
'big_computation_key'
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Tru
e
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Fals
e
)
ncalls_before
,
lastcall_before
=
count_timestamps
(
'big_computation_counter'
)
self
.
assertEqual
(
ncalls_before
,
1
)
# after the first call all subsequent calls should be cached
...
...
@@ -120,7 +120,7 @@ class SimpleTest(TestCase):
truncate_tempfile
(
'big_computation_withfm_counter'
)
cache
.
delete
(
'big_computation_key_withfm'
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Tru
e
)
run_celery_beat
(
seconds
=
3
,
verbose
=
Fals
e
)
ncalls_before
,
lastcall_before
=
count_timestamps
(
'big_computation_withfm_counter'
)
self
.
assertGreaterEqual
(
ncalls_before
,
2
)
...
...
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