Added @ps to show events and the next time they're going to fire.
This commit is contained in:
parent
53b111f4ae
commit
3ecb46f958
3 changed files with 52 additions and 3 deletions
40
scheduler.py
40
scheduler.py
|
|
@ -1,5 +1,6 @@
|
|||
import events
|
||||
import time
|
||||
from twisted.internet import task
|
||||
import events
|
||||
"""
|
||||
ADDING AN EVENT:
|
||||
* Create an event function to call.
|
||||
|
|
@ -10,7 +11,7 @@ ADDING AN EVENT:
|
|||
# Dictionary of events with a list in the form of:
|
||||
# [<function>, <interval>, <lastrantime>, <taskobject>, <description>]
|
||||
schedule = {
|
||||
'check_sessions': [events.check_sessions, 5, None, None, "Session check."]
|
||||
'check_sessions': [events.check_sessions, 60, time.time(), None, "Session consistency checks."]
|
||||
}
|
||||
|
||||
def start_events():
|
||||
|
|
@ -54,6 +55,30 @@ def get_event_interval(event_name):
|
|||
"""
|
||||
return get_event(event_name)[1]
|
||||
|
||||
def get_event_nextfire(event_name):
|
||||
"""
|
||||
Returns a value in seconds when the event is going to fire off next.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return (get_event(event_name)[2]+get_event_interval(event_name))-time.time()
|
||||
|
||||
def get_event_taskobj(event_name):
|
||||
"""
|
||||
Returns an event's task object.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[3]
|
||||
|
||||
def get_event_description(event_name):
|
||||
"""
|
||||
Returns an event's description.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
return get_event(event_name)[4]
|
||||
|
||||
def set_event_taskobj(event_name, taskobj):
|
||||
"""
|
||||
Sets an event's task object.
|
||||
|
|
@ -62,6 +87,14 @@ def set_event_taskobj(event_name, taskobj):
|
|||
"""
|
||||
get_event(event_name)[3] = taskobj
|
||||
|
||||
def set_event_lastfired(event_name):
|
||||
"""
|
||||
Sets an event's last fired time.
|
||||
|
||||
event_name: (string) The key of the event in the schedule dictionary.
|
||||
"""
|
||||
get_event(event_name)[2] = time.time()
|
||||
|
||||
def trigger_event(event_func, event_name):
|
||||
"""
|
||||
Update the last ran time and fire off the event.
|
||||
|
|
@ -69,4 +102,5 @@ def trigger_event(event_func, event_name):
|
|||
event_func: (func_reference) Reference to the event function to fire.
|
||||
eventname: (string) The name of the event (as per schedule dict).
|
||||
"""
|
||||
event_func()
|
||||
event_func()
|
||||
set_event_lastfired(event_name)
|
||||
Loading…
Add table
Add a link
Reference in a new issue