Commit fa060a63 authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon
Browse files

FTS-546: Set job_finished if transfer isnt running

parent 173ab13a
......@@ -417,12 +417,19 @@ class JobsController(BaseController):
job.reason = 'Job canceled by the user'
# FTS3 daemon expects job_finished to be NULL in order to trigger the signal
# to fts_url_copy
Session.query(File).filter(File.job_id == job.job_id).filter(File.file_state.in_(FileActiveStates))\
# to fts_url_copy, but this only makes sense if pid is set
Session.query(File).filter(File.job_id == job.job_id)\
.filter(File.file_state.in_(FileActiveStates), File.pid != None)\
.update({
'file_state': 'CANCELED', 'reason': 'Job canceled by the user',
'finish_time': now
'finish_time': now, 'job_finished': None,
}, synchronize_session=False)
Session.query(File).filter(File.job_id == job.job_id)\
.filter(File.file_state.in_(FileActiveStates), File.pid == None) \
.update({
'file_state': 'CANCELED', 'reason': 'Job canceled by the user',
'finish_time': now, 'job_finished': now,
}, synchronize_session=False)
# However, for data management operations there is nothing to signal, so
# set job_finished
Session.query(DataManagement).filter(DataManagement.job_id == job.job_id)\
......
......@@ -58,7 +58,7 @@ def do_authentication(credentials, env):
sign = b64decode(cred['sign'])
proxy = None
try:
proxy = b64decode(cred['prx'])
proxy = b64decode(cred['prx'])
log.info("found a proxy on the request")
except:
pass
......
......@@ -83,7 +83,35 @@ class TestJobCancel(TestController):
self.assertNotEqual(None, job.finish_time)
for f in job.files:
self.assertEqual(f.file_state, 'CANCELED')
self.assertEqual(None, f.job_finished) # Actually expected like this by FTS3 to trigger the KILL
self.assertNotEqual(None, f.job_finished)
self.assertNotEqual(None, f.finish_time)
def test_cancel_running(self):
"""
Cancel a job, but the transfer is running (pid is set)
"""
job_id = self._submit()
# Add pid
transfer = Session.query(File).filter(File.job_id == job_id).first()
transfer.pid = 1234
Session.merge(transfer)
Session.commit()
job = self.app.delete(url="/jobs/%s" % job_id, status=200).json
self.assertEqual(job['job_id'], job_id)
self.assertEqual(job['job_state'], 'CANCELED')
self.assertEqual(job['reason'], 'Job canceled by the user')
# Is it in the database?
job = Session.query(Job).get(job_id)
self.assertEqual(job.job_state, 'CANCELED')
self.assertNotEqual(None, job.job_finished)
self.assertNotEqual(None, job.finish_time)
for f in job.files:
self.assertEqual(f.file_state, 'CANCELED')
self.assertEqual(None, f.job_finished)
self.assertNotEqual(None, f.finish_time)
def test_cancel_terminal(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment