Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
53f41485
Commit
53f41485
authored
May 23, 2011
by
Georgios Gousios
Browse files
Cron tool and callback skeletons
parent
f6ff7a6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
logic/cron.py
0 → 100644
View file @
53f41485
from
datetime
import
datetime
,
timedelta
import
time
# Some utility classes / functions first
class
AllMatch
(
set
):
"""Universal set - match everything"""
def
__contains__
(
self
,
item
):
return
True
allMatch
=
AllMatch
()
# The actual Event class
class
Event
(
object
):
def
__init__
(
self
,
action
,
min
=
allMatch
,
hour
=
allMatch
,
day
=
allMatch
,
month
=
allMatch
,
dow
=
allMatch
,
args
=
(),
kwargs
=
{}):
self
.
mins
=
self
.
_conv_to_set
(
min
)
self
.
hours
=
self
.
_conv_to_set
(
hour
)
self
.
days
=
self
.
_conv_to_set
(
day
)
self
.
months
=
self
.
_conv_to_set
(
month
)
self
.
dow
=
self
.
_conv_to_set
(
dow
)
self
.
action
=
action
self
.
args
=
args
self
.
kwargs
=
kwargs
def
matchtime
(
self
,
t
):
"""Return True if this event should trigger at the specified datetime"""
return
((
t
.
minute
in
self
.
mins
)
and
(
t
.
hour
in
self
.
hours
)
and
(
t
.
day
in
self
.
days
)
and
(
t
.
month
in
self
.
months
)
and
(
t
.
weekday
()
in
self
.
dow
))
def
check
(
self
,
t
):
if
self
.
matchtime
(
t
):
self
.
action
(
*
self
.
args
,
**
self
.
kwargs
)
def
_conv_to_set
(
self
,
obj
):
# Allow single integer to be provided
if
isinstance
(
obj
,
(
int
,
long
)):
return
set
([
obj
])
# Single item
if
not
isinstance
(
obj
,
set
):
obj
=
set
(
obj
)
return
obj
class
CronTab
(
object
):
def
__init__
(
self
,
*
events
):
self
.
events
=
events
def
run
(
self
):
t
=
datetime
(
*
datetime
.
now
().
timetuple
()[:
5
])
while
1
:
for
e
in
self
.
events
:
e
.
check
(
t
)
t
+=
timedelta
(
minutes
=
1
)
n
=
datetime
.
now
()
while
n
<
t
:
s
=
(
t
-
n
).
seconds
+
1
time
.
sleep
(
s
)
n
=
datetime
.
now
()
logic/cron_callbacks.py
0 → 100644
View file @
53f41485
#
# Callback functions used by the cron dispatcher.
#
# Copyright 2010 Greek Research and Technology Network
#
def
send_recons_req
():
"""
Publish a reconsiliation request to the queue
"""
reconcile
=
dict
()
reconcile
[
'msg'
]
=
'reconcile'
pass
def
send_credit_calc_req
():
"""
Publish a credit calculation request to the queue
"""
pass
\ No newline at end of file
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