<commit_before>#-------------------------------------------------------------------------------
import multiprocessing
import os
from os import path
import subprocess
import re
import time
import config
import database

#-------------------------------------------------------------------------------
remotehost = config.REMOTEHOST
remotehome = config.REMOTEHOME
pipe_launch = config.PIPE_LAUNCH

reSLURMLINE = re.compile(r"slurmids: (?P<slurmids>\d+(,\d+)*)")
reSLURMID = re.compile(r"\,")

#-------------------------------------------------------------------------------
def startJob( user, var1 ):
    jobid = database.createJob( user )

    p = multiprocessing.Process( target=runjob, args=(user, jobid, var1) )
    print var1
    p.start()

#-------------------------------------------------------------------------------
def cancelJob( user, jobid ):
    print "CANCELING JOB " + str(jobid)
    jobinfo = database.getJobInfo( jobid )
    print jobinfo
    if jobinfo['state'] == database.JOB_COMPLETED or jobinfo['state'] == database.JOB_CANCELED:
        print "job", jobid, "already canceled"
        return true

    for slurmid in jobinfo['slurmids']:
        print "canceling slurm job", slurmid

    #database.setJobCanceled( jobid )
    return True

#-------------------------------------------------------------------------------
def getSlurmIds( output ):
    mm = reSLURMLINE.search( output )
    sids = []
    if mm:
        slurmline = mm.group('slurmids')
        slurmids = reSLURMID.split( slurmline )
        sids = map(int,slurmids)

    return sids

#-------------------------------------------------------------------------------
def runjob( user, jobid, var1):
    print "RUNNING JOB " + str(jobid)

# stagein
    if "file" in var1:
        fileid1 = int(var1["file"])
        localfile1 = database.getFileFullName( fileid1 )<commit_msg>adding "cancel job" function (mncancel and rm)<commit_after>#-------------------------------------------------------------------------------
import multiprocessing
import os
from os import path
import subprocess
import re
import time
import config
import database

#-------------------------------------------------------------------------------
remotehost = config.REMOTEHOST
remotehome = config.REMOTEHOME
pipe_launch = config.PIPE_LAUNCH
data_dir = config.DATADIR

reSLURMLINE = re.compile(r"slurmids: (?P<slurmids>\d+(,\d+)*)")
reSLURMID = re.compile(r"\,")

#-------------------------------------------------------------------------------
def startJob( user, var1 ):
    jobid = database.createJob( user )

    p = multiprocessing.Process( target=runjob, args=(user, jobid, var1) )
    print var1
    p.start()

#-------------------------------------------------------------------------------
def cancelJob( user, jobid ):
    print "CANCELING JOB " + str(jobid)
    jobinfo = database.getJobInfo( jobid )
    print jobinfo
    if jobinfo['state'] == database.JOB_COMPLETED or jobinfo['state'] == database.JOB_CANCELED:
        print "job", jobid, "already canceled"
        return true

    # Canceling Jobid:
    for slurmid in jobinfo['slurmids']:
        print "canceling slurm job", slurmid

        command = ["ssh", remotehost, "mncancel", slurmid ]
        proc = subprocess.Popen( command, stdout=subprocess.PIPE )
        #output = proc.communicate()[0]

    # Removing job folders:
    jname = jobinfo[ 'name' ]
    print "Removing outputs from Job named: ", jname
    command =  [ 'ssh', remotehost,
                 "cd", data_dir + user,
                 "rm -r", jname ]
    proc = subprocess.Popen( command, stdout=subprocess.PIPE )
    #output = proc.communicate()[0]
    
    database.setJobCanceled( jobid )
    return True

#-------------------------------------------------------------------------------
def getSlurmIds( output ):
    mm = reSLURMLINE.search( output )
    sids = []
    if mm:
        slurmline = mm.group('slurmids')
        slurmids = reSLURMID.split( slurmline )
        sids = map(int,slurmids)

    return sids

#-------------------------------------------------------------------------------
def runjob( user, jobid, var1):
    print "RUNNING JOB " + str(jobid)

# stagein
    if "file" in var1:
        fileid1 = int(var1["file"])
        localfile1 = database.getFileFullName( fileid1 )
{'fraction_non_alphanumeric': 0.31209302325581395, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 1.4451392836839114, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1616704', 'n_tokens_mistral': 1207, 'n_tokens_neox': 1211, 'n_words': 293}