scripts/stats.py
changeset 2265 bfaadb6ab559
parent 2262 5b0576dcc107
child 2270 543f11d7b0e4
equal deleted inserted replaced
2264:c8697d928065 2265:bfaadb6ab559
   257   for proposal in proposals:
   257   for proposal in proposals:
   258     proposal_logic.updateEntityProperties(proposal, fields, silent=True)
   258     proposal_logic.updateEntityProperties(proposal, fields, silent=True)
   259 
   259 
   260 
   260 
   261 def startSpam():
   261 def startSpam():
       
   262   """Creates the job that is responsible for sending mails
       
   263   """
       
   264 
   262   from soc.logic.models.job import logic as job_logic
   265   from soc.logic.models.job import logic as job_logic
   263   from soc.logic.models.priority_group import logic as priority_logic
   266   from soc.logic.models.priority_group import logic as priority_logic
   264   from soc.logic.models.program import logic as program_logic
   267   from soc.logic.models.program import logic as program_logic
   265 
   268 
   266   program_entity = program_logic.getFromKeyName('google/gsoc2009')
   269   program_entity = program_logic.getFromKeyName('google/gsoc2009')
   270       'priority_group': priority_group,
   273       'priority_group': priority_group,
   271       'task_name': 'setupStudentProposalMailing',
   274       'task_name': 'setupStudentProposalMailing',
   272       'key_data': [program_entity.key()]}
   275       'key_data': [program_entity.key()]}
   273 
   276 
   274   job_logic.updateOrCreateFromFields(job_fields)
   277   job_logic.updateOrCreateFromFields(job_fields)
       
   278 
       
   279 
       
   280 def reviveJobs(amount):
       
   281   """Sets jobs that are stuck in 'aborted' to waiting.
       
   282 
       
   283   Args:
       
   284     amount: the amount of jobs to revive
       
   285   """
       
   286 
       
   287   from soc.models.job import Job
       
   288 
       
   289   query = Job.all().filter('status', 'aborted')
       
   290   jobs = query.fetch(amount)
       
   291 
       
   292   if not jobs:
       
   293     print "no dead jobs"
       
   294 
       
   295   for job in jobs:
       
   296      job.status = 'waiting'
       
   297      job.put()
       
   298      print "restarted %d" % job.key().id()
       
   299 
       
   300 
       
   301 def deidleJobs(amount):
       
   302   """Sets jobs that are stuck in 'started' to waiting.
       
   303 
       
   304   Args:
       
   305     amount: the amount of jobs to deidle
       
   306   """
       
   307 
       
   308   from soc.models.job import Job
       
   309 
       
   310   query = Job.all().filter('status', 'started')
       
   311   jobs = query.fetch(amount)
       
   312 
       
   313   if not jobs:
       
   314     print "no idle jobs"
       
   315 
       
   316   for job in jobs:
       
   317      job.status = 'waiting'
       
   318      job.put()
       
   319      print "restarted %d" % job.key().id()
   275 
   320 
   276 
   321 
   277 def deleteEntities(model, step_size=25):
   322 def deleteEntities(model, step_size=25):
   278   """Deletes all entities of the specified type
   323   """Deletes all entities of the specified type
   279   """
   324   """
   361       'StudentProposal': StudentProposal,
   406       'StudentProposal': StudentProposal,
   362       'slotSaver': slotSaver,
   407       'slotSaver': slotSaver,
   363       'popSaver': popSaver,
   408       'popSaver': popSaver,
   364       'rawSaver': rawSaver,
   409       'rawSaver': rawSaver,
   365       'startSpam': startSpam,
   410       'startSpam': startSpam,
       
   411       'reviveJobs': reviveJobs,
       
   412       'deidleJobs': deidleJobs,
   366   }
   413   }
   367 
   414 
   368   interactive.remote(args, context)
   415   interactive.remote(args, context)
   369 
   416 
   370 if __name__ == '__main__':
   417 if __name__ == '__main__':