pbs qdel not done jobs on rm
[django_unres.git] / django_simple / todo / jobfiles.py
index f78b873..e7ee716 100644 (file)
@@ -72,7 +72,7 @@ def write_ssbond(ssbond):
 
 @receiver(post_save, sender=Task)
 def write_on_task_save(sender, instance, **kwargs):
-   if instance.ready and not instance.done and instance.running==0:
+   if instance.ready and not instance.done and instance.running==0 and instance.pbsjob=='':
      if (not os.path.isdir(instance.jobdirname)):
         os.mkdir(instance.jobdirname)
 #     os.chdir(instance.jobdirname)
@@ -545,14 +545,28 @@ CUTOFF=7.00000 WCORR4=0.00000"""
       os.chdir(instance.jobdirname)  
       ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs8.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
       os.chdir('..')
+      
+     output = str(ret_code.communicate()[0])
+     output=output.strip()
+     if output=='':
+       output='error'
+     logger.warning("PBS \"%s\" " % output)
+     instance.pbsjob = output
+     instance.save()
      
-     print ret_code.stdout.readlines()
+#     print ret_code.stdout.readlines()
      logger.warning("Dir \"%s\" has been saved." % instance.jobdirname)
      
 @receiver(post_delete, sender=Task)
 def delete_on_task_del(sender, instance, **kwargs):     
    if instance.jobdirname:
       if os.path.isdir(instance.jobdirname):
+         if not instance.done:
+           ret_code_qdel = subprocess.Popen(' /opt/torque/bin/qdel '+str(instance.pbsjob), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+           output = str(ret_code_qdel.communicate()[0])
+           output=output.strip()
+           logger.warning("PBS qdel \"%s\" " % instance.pbsjob)
+           logger.warning("QDEL \"%s\" " % output)
          shutil.rmtree(instance.jobdirname)
          logger.warning("Dir \"%s\" has been rm." % instance.jobdirname)         
          
\ No newline at end of file