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

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

Implementation of tickets #22390

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
12
13class MigrationThread(threading.Thread):
14    """
15        Constructs a scheduler for the Moles2 to Moles3 migration.
16        @param interval: define the minimal time, in seconds, between an execution and the successive.
17        If the current migration run takes more than the defined interval the next will starts
18        as soon the previous ends.         
19    """
20    def __init__(self, interval=600):
21        threading.Thread.__init__(self)
22        self._doRun = True   
23        self.interval = interval
24   
25    def stop(self):
26        self._doRun = False
27   
28    def run(self):
29        while self._doRun:
30            startTime = (int)(time.time())
31            timer = Timer(5, self._migrate, ())
32            timer.start()
33            timer.join()
34            diffTime = startTime + self.interval - (int)(time.time()) 
35            if diffTime > 0:
36                time.sleep(diffTime)
37   
38    def _printTime(self):
39        print "From print_time", time.time()   
40
41    def _migrate(self):
42        lr = LoadResources()
43        ex = lr.process()
44        for e in ex:
45            print e
46
47        mp = MigrationProcess()
48        ex = mp.process()
49        for e in ex:
50            print e
Note: See TracBrowser for help on using the repository browser.