pbs qdel not done jobs on rm
authorCezary Czaplewski <czarek@chem.univ.gda.pl>
Wed, 12 Feb 2020 20:47:12 +0000 (21:47 +0100)
committerCezary Czaplewski <czarek@chem.univ.gda.pl>
Wed, 12 Feb 2020 20:47:12 +0000 (21:47 +0100)
django_simple/todo/jobfiles.py
django_simple/todo/models.py
django_simple/todo/templates/details.html

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
index d11b412..622cac3 100644 (file)
@@ -104,6 +104,7 @@ class Task(models.Model):
     owner = models.ForeignKey(User,default=1)
     created_date = models.DateTimeField(default=timezone.now)
     jobdirname = models.CharField(max_length=100,default='')
+    pbsjob = models.CharField(max_length=40,default='')
     example = models.CharField(max_length=10,default='')
     damino = models.BooleanField(default=False)
     
index 3466e5c..2b926d1 100644 (file)
@@ -80,6 +80,12 @@ Created {{ task.created_date  }}
                            <div class="col-md-6"> type </div>
                            <div class="col-md-6">{{ task.type }}</div>
                        </li>           
+
+                       <li class="list-group-item task-item">
+                           <div class="col-md-6"> pbsjob </div>
+                           <div class="col-md-6">{{ task.pbsjob }}</div>
+                       </li>           
+
          
                        <li class="list-group-item task-item">
                            <div class="col-md-6"> force field </div>