1. Olemis Lang
  2. cheesecake-service

Commits

infrared  committed 81cac5e

Storing execution time of cheesecake_index script.

  • Participants
  • Parent commits 09ef40f
  • Branches default

Comments (0)

Files changed (3)

File cheesecake_daemon.py

View file
  • Ignore whitespace
     logname = os.path.join(LOG_DIRECTORY, run.logname())
 
     # Run cheesecake_index with logfile saved into LOG_DIRECTORY.
+    execution_start = time.time()
     code, output = run_command("%s --name %s==%s --keep-log --logfile=%s" % \
                                (CHEESECAKE_INDEX_PATH,
                                 name,
                                 version,
                                 logname),
                                max_timeout=MAX_CHEESECAKE_INDEX_TIMEOUT)
+    execution_end = time.time()
+
+    # Update instance with execution time.
+    run.execution_time = int(execution_end - execution_start)
 
     # Update instance with result.
     if code == 0 and not output.startswith('Error'):
                 store.save_run(run)
 
                 if run.result == 'success':
-                    store.log("Package %s-%s scored successfully (installability: %d, documentation: %d, code kwalitee: %d)." % \
+                    store.log("Package %s-%s scored successfully (installability: %d, documentation: %d, code kwalitee: %d) in %d seconds." % \
                               (name,
                                version,
                                score.installability.relative,
                                score.documentation.relative,
-                               score.code_kwalitee.relative))
+                               score.code_kwalitee.relative,
+                               run.execution_time))
                     store.save_score(name, version, score)
                     latest_scores.append((name, version, score))
 
                 if run.result == 'failure':
-                    store.log("Failed to score package %s-%s. Details in log: %s." % \
+                    store.log("Failed to score package %s-%s in %d seconds. Details in log: %s." % \
                               (name,
                                version,
+                               run.execution_time,
                                os.path.join(LOG_DIRECTORY, run.logname())))
                     if store.number_of_failures(name, version) < MAX_NUMBER_OF_FAILURES:
                         new_releases_to_score.append((name, version))

File store.py

View file
  • Ignore whitespace
 
 
 class CheesecakeRun(object):
-    def __init__(self, number, package, version, result='running'):
+    def __init__(self, number, package, version, result='running', execution_time=0):
         if result not in ['success', 'failure', 'running']:
             raise ValueError("result should be 'success', 'failure' or 'running'")
 
         self.package = package
         self.version = version
         self.result = result
+        self.execution_time = execution_time
 
     def logname(self):
-        return '%(number)d-%(package)s==%(version)s-%(result)s.log' % obj2dict(self)
+        return '%(number)d-%(package)s==%(version)s-%(result)s-%(execution_time)d.log' % obj2dict(self)
 
 
 class Store(object):
         cheesecake_index runs.
       * When you're done with the store, remember to close() it!
     """
-    logname_regex = r'(\d+)-([^=]+)==([^=]+)-((?:failure)|(?:success))\.log'
+    logname_regex = r'(\d+)-([^=]+)==([^=]+)-((?:failure)|(?:success))-(\d+)\.log'
 
     def __init__(self, directory=None, postgres_config='dbname=cheesecake',
                  timestamp_file=os.path.join(tempfile.gettempdir(),
             try:
                 m = re.search(self.logname_regex, logname)
                 if m:
-                    number, package, version, result = m.groups()
-                    run = CheesecakeRun(int(number), package, version, result)
+                    number, package, version, result, execution_time = m.groups()
+                    run = CheesecakeRun(int(number), package, version, result, int(execution_time))
                     self.save_run(run)
             except:
                 pass

File tests/test_store.py

View file
  • Ignore whitespace
 """
 
 successive_lognames = [
-    '1-twill==0.8.5-success.log',
-    '2-PIL==1.1.5-failure.log',
-    '3-PIL==1.1.5-failure.log',
-    '4-setuptools==0.6c1-success.log',
+    '1-twill==0.8.5-success-42.log',
+    '2-PIL==1.1.5-failure-42.log',
+    '3-PIL==1.1.5-failure-42.log',
+    '4-setuptools==0.6c1-success-42.log',
 ]
 
 ################################################################################
 
     def test_set_2(self):
         lognames = [
-            '12-rope==0.2-success.log',
-            '13-ctypes==1.0.0-failure.log',
-            '101-chimera==0.4.4-failure.log',
+            '12-rope==0.2-success-42.log',
+            '13-ctypes==1.0.0-failure-42.log',
+            '101-chimera==0.4.4-failure-42.log',
         ]
         self._run_test_set(lognames, 102)
 
 
     def test_set_2(self):
         lognames = [
-            '12-rope==0.2-success.log',
-            '1-twill==0.8.5-success.log',
+            '12-rope==0.2-success-42.log',
+            '1-twill==0.8.5-success-42.log',
         ]
         self._run_test_set(lognames, [])