~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to install/helioviewer/hvpull/net/daemon.py

  • Committer: Keith Hughitt
  • Date: 2012-06-04 17:27:01 UTC
  • Revision ID: keith.hughitt@nasa.gov-20120604172701-eo2sj3ylxh4bik4l
Added support for reconnecting to MySQL if the connection fails when querying the db to determine which files are new

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import shutil
12
12
import sunpy
13
13
import Queue
 
14
import MySQLdb
14
15
from random import shuffle
15
16
from helioviewer.jp2 import process_jp2_images
16
17
from helioviewer.db  import get_db_cursor, mark_as_corrupt
25
26
        self.dbuser = conf.get('database', 'user')
26
27
        self.dbpass = conf.get('database', 'pass')
27
28
        
28
 
        self._db = get_db_cursor(self.dbname, self.dbuser, self.dbpass)
 
29
        self.downloaders = []
29
30
        
 
31
        try:
 
32
            self._db = get_db_cursor(self.dbname, self.dbuser, self.dbpass)
 
33
        except MySQLdb.OperationalError:
 
34
            logging.error("Unable to access MySQL. Is the database daemon running?")
 
35
            self.shutdown()
 
36
            self.stop()
 
37
 
30
38
        # Email notification
31
39
        self.email_server = conf.get('notifications', 'server')
32
40
        self.email_from = conf.get('notifications', 'from')
149
157
        new_urls = []
150
158
        
151
159
        for url_list in urls:
152
 
            new_urls.append(filter(self._filter_new, url_list))
 
160
            filtered = None
 
161
            
 
162
            while filtered is None:
 
163
                try:
 
164
                    filtered = filter(self._filter_new, url_list)
 
165
                except MySQLdb.OperationalError:
 
166
                    # MySQL has gone away -- try again in 5s
 
167
                    logging.error(("Unable to access database to check for file"
 
168
                                   " existence. Will try again in 5 seconds."))
 
169
                    time.sleep(5)
 
170
                    
 
171
                    # Try and reconnect
 
172
                    try:                        
 
173
                        self._db = get_db_cursor(self.dbname, self.dbuser, self.dbpass)
 
174
                    except:
 
175
                        pass
 
176
                
 
177
            new_urls.append(filtered)
153
178
 
154
179
        # acquire the data files
155
180
        self.acquire(new_urls)