1 '''
2 Model for client's jobs.
3 '''
4
5 from db import Base
6 from sqlalchemy import Integer, Unicode, Column, DateTime, ForeignKey
7 from sqlalchemy.orm import relation, backref
8 import datetime
9 from main.model import Computer
10
11
12 metadata = Base.metadata
13
15 '''
16 A instance of this class is created when a plugin sends a job to a
17 client. The client will reply to the job with a new state and
18 with a message. When this reponse comes to the server the
19 plugin's callback_function is called. The Job instance is updated
20 and it's passed as argument. The response won't be always finished. For
21 example if a job takes a long time, it could send a response with
22 state 'in progress' and the percentage in the message.
23
24 * 'id' is the primary key.
25 * 'plugins' is the plugin that made the call.
26 * 'callback_function' is called when a response comes.
27 * 'request' is the command sent to the client.
28 * 'state' three posibilities: open, 'in progress' and close
29 * 'message' is the last 'string' sent by the client
30 * 'creation_date' is the date when the job was sent
31 * 'last_modified_date' is the date of the last response of the client
32 '''
33 __tablename__ = 'job'
34 id = Column(Integer, primary_key=True)
35 origin = Column(Unicode(128))
36 callback_function = Column(Unicode(128))
37 request = Column(Unicode(1024))
38 state = Column(Unicode(128))
39 message = Column(Unicode())
40 creation_date = Column(DateTime())
41 last_modified_date = Column(DateTime())
42
43 computer_id = Column(Integer, ForeignKey('computer.id'))
44
45 computer = relation(Computer, backref=backref('jobs', order_by=id))
46
48 '''
49 Creates a new open job
50 '''
51 self.state = u'open'
52 self.create_date = datetime.datetime.now()
53 self.last_modified_date = datetime.datetime.now()
54
56 '''
57 This function is called when a new response comes.
58 The message, the state and the modified date are updated
59 '''
60 self.last_modified_date = datetime.datetime.now()
61 self.message = message
62 self.state = state
63