# HG changeset patch # User Sverre Rabbelier # Date 1240267971 0 # Node ID bfaadb6ab5593003980a81c85edb5aeff8283b4a # Parent c8697d928065efce29a0c9e9c3de58602b764aef Added reviveJobs and deidleJobs to stats.py These can be used to mark jobs as 'waiting' (meaning they will be executed again). Patch by: Sverre Rabbelier diff -r c8697d928065 -r bfaadb6ab559 scripts/stats.py --- a/scripts/stats.py Mon Apr 20 22:52:38 2009 +0000 +++ b/scripts/stats.py Mon Apr 20 22:52:51 2009 +0000 @@ -259,6 +259,9 @@ def startSpam(): + """Creates the job that is responsible for sending mails + """ + from soc.logic.models.job import logic as job_logic from soc.logic.models.priority_group import logic as priority_logic from soc.logic.models.program import logic as program_logic @@ -274,6 +277,48 @@ job_logic.updateOrCreateFromFields(job_fields) +def reviveJobs(amount): + """Sets jobs that are stuck in 'aborted' to waiting. + + Args: + amount: the amount of jobs to revive + """ + + from soc.models.job import Job + + query = Job.all().filter('status', 'aborted') + jobs = query.fetch(amount) + + if not jobs: + print "no dead jobs" + + for job in jobs: + job.status = 'waiting' + job.put() + print "restarted %d" % job.key().id() + + +def deidleJobs(amount): + """Sets jobs that are stuck in 'started' to waiting. + + Args: + amount: the amount of jobs to deidle + """ + + from soc.models.job import Job + + query = Job.all().filter('status', 'started') + jobs = query.fetch(amount) + + if not jobs: + print "no idle jobs" + + for job in jobs: + job.status = 'waiting' + job.put() + print "restarted %d" % job.key().id() + + def deleteEntities(model, step_size=25): """Deletes all entities of the specified type """ @@ -363,6 +408,8 @@ 'popSaver': popSaver, 'rawSaver': rawSaver, 'startSpam': startSpam, + 'reviveJobs': reviveJobs, + 'deidleJobs': deidleJobs, } interactive.remote(args, context)