source: mauRepo/MolesManager/trunk/src/libs/migration/client.py @ 8325

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/mauRepo/MolesManager/trunk/src/libs/migration/client.py@8325
Revision 8325, 1.6 KB checked in by mnagni, 7 years ago (diff)

Great improvement on how SA alchemy session is managed

Line 
1'''
2Created on 9 Nov 2011
3
4@author: mnagni
5'''
6from libs.migration.processor.loadResources import LoadResources
7from libs.migration.processor.migrationProcess import MigrationProcess
8
9import threading
10import time
11from threading import Timer
12from libs.migration.processor.EPBRepo import EPBRepo
13
14class MigrationThread(threading.Thread):
15    """
16        Constructs a scheduler for the Moles2 to Moles3 migration.
17        Only one instance should be running for each python interpreter
18        @param interval: define the minimal time, in seconds, between an execution and the successive.
19        If the current migration run takes more than the defined interval the next will starts
20        as soon the previous ends.         
21    """
22   
23    def __init__(self, moles3EPB, migrationEPB, interval=600):
24        EPBRepo.moles3EPB = moles3EPB
25        EPBRepo.migrationEPB = migrationEPB
26       
27        threading.Thread.__init__(self)
28        self._doRun = True   
29        self.interval = interval
30   
31    def stop(self):
32        self._doRun = False
33   
34    def run(self):
35        while self._doRun:
36            startTime = (int)(time.time())
37            timer = Timer(5, self._migrate, ())
38            timer.start()
39            timer.join()
40            diffTime = startTime + self.interval - (int)(time.time()) 
41            if diffTime > 0:
42                time.sleep(diffTime)
43   
44    def _printTime(self):
45        print "From print_time", time.time()   
46
47    def _migrate(self):
48        lr = LoadResources()
49        ex = lr.process()
50        for e in ex:
51            print e
52
53        mp = MigrationProcess()
54        ex = mp.process()
55        for e in ex:
56            print e
Note: See TracBrowser for help on using the repository browser.