Package web :: Package clientjob
[hide private]
[frames] | no frames]

Source Code for Package web.clientjob

 1  ''' 
 2  Module with the server's communication. 
 3  ''' 
 4   
 5  from decorators import i18n 
 6  from main.model import Computer 
 7  import web 
 8  import threading 
9 10 11 -class Response:
12 ''' 13 A instance of this class is returned by send_job. 14 If everything is ok the code is 200. If instead the request couln't 15 be executed by the client, the code will be different to 200 and 16 explication error will be in response. 17 ''' 18
19 - def __init__(self, code, response):
20 self.code = code 21 self.response = response
22
23 24 -class ComputerNotFoundError(Exception):
25 ''' 26 Raise when you want to send a job to a computer that it's not 27 in the data base 28 ''' 29 pass
30
31 @i18n 32 -def send_job(job):
33 ''' 34 Given a job sends a http request with the command to execute 35 in the client. 36 ''' 37 38 orm = web.ctx.orm 39 orm.add(job) 40 orm.commit() 41 42 if not job.computer: 43 raise ComputerNotFoundError() 44 45 threading.Thread(target=__send_request,args=(job.id, 46 job.computer.ip, job.request)) 47 48 return True
49
50 51 #TODO 52 -def __send_request(ip, id, command):
53 ''' 54 Sends a http request to the ip with a id. 55 If something was wrong the job will be deleted from the data base. 56 ''' 57 58 return Response(200, '')
59