1 | ''' |
---|
2 | Created on 9 Nov 2011 |
---|
3 | |
---|
4 | @author: mnagni |
---|
5 | ''' |
---|
6 | from libs.migration.processor.loadResources import LoadResources |
---|
7 | from libs.migration.processor.migrationProcess import MigrationProcess |
---|
8 | |
---|
9 | import threading |
---|
10 | import time |
---|
11 | from threading import Timer |
---|
12 | from libs.migration.db.classes import MigrationObject |
---|
13 | from libs.migration.processor.commons import DS_pUBLISHED, DO_BADC |
---|
14 | |
---|
15 | |
---|
16 | |
---|
17 | class MigrationThread(threading.Thread): |
---|
18 | """ |
---|
19 | Constructs a scheduler for the Moles2 to Moles3 migration. |
---|
20 | @param interval: define the minimal time, in seconds, between an execution and the successive. |
---|
21 | If the current migration run takes more than the defined interval the next will starts |
---|
22 | as soon the previous ends. |
---|
23 | """ |
---|
24 | def __init__(self, interval=600): |
---|
25 | threading.Thread.__init__(self) |
---|
26 | self._doRun = True |
---|
27 | self.interval = interval |
---|
28 | |
---|
29 | def stop(self): |
---|
30 | self._doRun = False |
---|
31 | |
---|
32 | def run(self): |
---|
33 | while self._doRun: |
---|
34 | startTime = (int)(time.time()) |
---|
35 | timer = Timer(5, self._migrate, ()) |
---|
36 | timer.start() |
---|
37 | timer.join() |
---|
38 | diffTime = startTime + self.interval - (int)(time.time()) |
---|
39 | if diffTime > 0: |
---|
40 | time.sleep(diffTime) |
---|
41 | |
---|
42 | def _printTime(self): |
---|
43 | print "From print_time", time.time() |
---|
44 | |
---|
45 | def _migrate(self): |
---|
46 | lr = LoadResources() |
---|
47 | lr.process() |
---|
48 | |
---|
49 | mp = MigrationProcess() |
---|
50 | mp.process() |
---|
51 | |
---|
52 | #record = Moles3EPB.search(CEDA_Observation, 12) |
---|
53 | #print DJEncoder().encode(record) |
---|
54 | |
---|
55 | lr = LoadResources() |
---|
56 | mp = MigrationProcess() |
---|
57 | |
---|
58 | dataEntity = MigrationObject() |
---|
59 | dataEntity.doc_status = DS_pUBLISHED |
---|
60 | dataEntity.doc_owner = DO_BADC |
---|
61 | dataEntity.doc_name = 'dataent_csip.atom' |
---|
62 | |
---|
63 | lr.process() |
---|
64 | mp.process(dataEntity) |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | |
---|