Added more stable events.
- added PIDs to all events, so they can be deleted safely. - scheduler.del_event(pid) cleanly deletes events from the scheduler - added @delevent for deleting events based on PID (@ps shows this now) - Events has a self.repeat property allowing them to only be repeated a certain time (default is infinitely many times). After the set number of repeats, the event deletes itself from the scheduler. Events are currently not persistently stored; this is left for future commits. . Griatch
This commit is contained in:
parent
642932a403
commit
5e866c6b73
5 changed files with 148 additions and 26 deletions
|
|
@ -775,3 +775,21 @@ def cmd_help(command):
|
|||
|
||||
source_object.emit_to(string)
|
||||
GLOBAL_CMD_TABLE.add_command("help", cmd_help)
|
||||
|
||||
## def cmd_testevent(command):
|
||||
## from src import events
|
||||
## from src import scheduler
|
||||
## source_object = command.source_object
|
||||
|
||||
## if not command.command_argument:
|
||||
## #event = events.IntervalEvent()
|
||||
## event = events.IntervalEvent()
|
||||
## event.repeats = 3
|
||||
## event.interval = 5
|
||||
## pid = scheduler.add_event(event)
|
||||
## source_object.emit_to("event with pid %s added." % pid)
|
||||
## else:
|
||||
## pid = command.command_argument
|
||||
## scheduler.del_event(pid)
|
||||
## source_object.emit_to("event with pid %s removed (if it existed)." % pid)
|
||||
## GLOBAL_CMD_TABLE.add_command("testevent", cmd_testevent)
|
||||
|
|
|
|||
|
|
@ -135,13 +135,18 @@ def cmd_ps(command):
|
|||
"""
|
||||
source_object = command.source_object
|
||||
|
||||
source_object.emit_to("-- Interval Events --")
|
||||
for event in scheduler.schedule:
|
||||
source_object.emit_to(" [%d/%d] %s" % (
|
||||
event.get_nextfire(),
|
||||
event.interval,
|
||||
event.description))
|
||||
source_object.emit_to("Totals: %d interval events" % (len(scheduler.schedule),))
|
||||
source_object.emit_to("Processes Scheduled:\n-- PID [time/interval] [repeats] description --")
|
||||
for event in scheduler.SCHEDULE:
|
||||
repeats = "[inf] "
|
||||
if event.repeats != None:
|
||||
repeats = "[%i] " % event.repeats
|
||||
source_object.emit_to(" %i [%d/%d] %s%s" % (
|
||||
event.pid,
|
||||
event.get_nextfire(),
|
||||
event.interval,
|
||||
repeats,
|
||||
event.description))
|
||||
source_object.emit_to("Totals: %d interval events" % (len(scheduler.SCHEDULE),))
|
||||
GLOBAL_CMD_TABLE.add_command("@ps", cmd_ps,
|
||||
priv_tuple=("genperms.process_control",), help_category="Admin")
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,9 @@ from src.helpsys import helpsystem
|
|||
from src.config.models import CommandAlias
|
||||
from src.config import edit_aliases
|
||||
from src import cache
|
||||
from src import scheduler
|
||||
|
||||
|
||||
def cmd_reload(command):
|
||||
"""
|
||||
@reload - reload game subsystems
|
||||
|
|
@ -761,3 +764,37 @@ def cmd_setcmdalias(command):
|
|||
GLOBAL_CMD_TABLE.add_command("@setcmdalias", cmd_setcmdalias,
|
||||
priv_tuple=("genperms.process_control",),
|
||||
help_category="Admin")
|
||||
|
||||
|
||||
def cmd_delevent(command):
|
||||
"""
|
||||
@delevent - remove events manually
|
||||
|
||||
Usage:
|
||||
@delevent <pid>
|
||||
|
||||
Removes an event with the given pid (process ID) from the event scheduler.
|
||||
To see all active events and their pids, use the @ps command.
|
||||
"""
|
||||
source_object = command.source_object
|
||||
|
||||
if not command.command_argument:
|
||||
source_object.emit_to("Usage: @delevent <pid>")
|
||||
return
|
||||
try:
|
||||
pid = int(command.command_argument)
|
||||
except ValueError:
|
||||
source_object.emit_to("You must supply a valid pid number.")
|
||||
return
|
||||
event = scheduler.get_event(pid)
|
||||
if event:
|
||||
desc = event.description
|
||||
scheduler.del_event(pid)
|
||||
source_object.emit_to("Event %i - '%s' removed." % (pid, desc))
|
||||
else:
|
||||
source_object.emit_to("No event found with a pid of %i. Use @ps to list process IDs." % pid)
|
||||
|
||||
GLOBAL_CMD_TABLE.add_command("@delevent", cmd_delevent,
|
||||
priv_tuple=("genperms.process_control",),
|
||||
help_category="Admin")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue