Anonymous avatar Anonymous committed e0f817d

Move the logging statements into Worker class rather than having them in run_worker. This enable me to give more useful information in the log. Improve the documentation : fix some typo and improve the wording

Comments (0)

Files changed (3)

docs/overview.rst

 Once the server is started and that you have created some "Build" in django's admin interface you can open a new terminal and run the client side of the project:
 
   * cd src/worker
-  * python run_worker.py
+  * python run_worker.py --daemon=start
+  * python run_worker.py --daemon=stop
   
   Use case
   =========
   
-  Now that you have understood the layout of the project I am let us write a achieve something useful with it. We are going to create a Build that will :
+  Now that you have understood the layout of the project. Let us see how achieve something useful with it.
+  
+We are going to create a Build that will :
     * download the Fabric Factory 
     * setup the environement
     * run the test suite
     * Report the result
     
- 1> Direct your browser to that url http://192.168.1.11:8000/admin/ and key in the username/password you have chosen for your administrator.
- 2> Add this [Add link] fabfile recipe http://192.168.1.11:8000/admin/factory/fabfilerecipe/add/ and call it "fabric factory use case"
- 3> Create a Build that will download setup and run the test here http://192.168.1.11:8000/admin/factory/build/add/
+ 1> Direct your browser to that url http://127.0.0.1:8000/admin/ and key in the username/password you have chosen for your administrator.
+ 2> Add the fabfile recipe store in docs http://127.0.0.1:8000/admin/factory/fabfilerecipe/add/ and call it "fabric factory use case"
+ 3> Create a Build that will download setup and run the test here : http://127.0.0.1:8000/admin/factory/build/add/
  
- Note : This is all you will need to do once your client/server will be setup to create a new build. We are now going to configure the client to run the tasks of this server. First let see how the server publish the next task that need to be executed. Point your browser to this url : http://192.168.1.11:8000/factory/build/oldest_not_executed/ You can see here a json string describing the task.
+The fabfile recipe that we have download earlier contains a task called : 'download_setup_and_test' This task as been writen to do what we want.
+ 
+We are now going to configure the client to run this task. However before doing this let us see how the server publish the tasks that need to be executed. Point your browser to this url : http://127.0.0.1:8000/factory/build/oldest_not_executed/ You can see here a json string describing the task.
  
  """
  {"task": "download_setup_and_test", "name": "download setup and run the test", "build_package_url": "http://192.168.1.11:8000/site_media/build_packages/1_fabric-factory-use-case4fIWt6.tar.bz2", "post_back_url": "http://192.168.1.11:8000/factory/build/update/1/"}
  """
   
-  
 
 Conclusion
 ===========

src/worker/__init__.py

         self.output = None
         self.error = None
     def download_build_package(self):
+        logging.debug("try to download the build package : %s" %
+                      self.build_package_url)
         if not os.path.isdir(self.kitchen_path):
             os.mkdir(self.kitchen_path)
         try:
             web_file = urllib2.urlopen(self.build_package_url)
+            logging.debug("Build package successfully downloaded: %s" %
+                      self.build_package_url)
         except Exception, e:
             raise WorkerError("Cannot download the package to build : %s" %
                         self.build_package_url)
 
     def execute_task(self):
         #a bit of hackery there to import this particular fabfile
+        logging.debug("Worker try to execute the task : %s" %
+                      self.task)
         file = os.path.join(self.kitchen_path,
                             self.filename.split('.')[0],
                             "fabfile.py")
         file_path = os.path.join(self.kitchen_path, file)
-        self.output, self.error = self._execute_task_from_fabfile(file_path, self.task)  # We should collect this output
+        # We should collect this output
+        self.output, self.error = self._execute_task_from_fabfile(file_path,
+                                                                  self.task) 
         logging.debug('output : %s' %self.output)
         logging.debug('error : %s' %self.error)
         if self.error:
             self.success = False
+            logging.debug("Fail to execute the task")
         else:
             self.success = True
-            
+            logging.debug("Succeed to execute the task")
     def post_result(self):
         values = {
             "name": self.name,
         }
         if self.success:
             values['success'] = 'on'
+        logging.debug("Post the values : %s" %values)
         data = urllib.urlencode(values)
         request = urllib2.Request(self.post_back_url, data)
         fd=urllib2.urlopen(request)
         data=fd.read()
         
     def clean(self):
+        logging.debug('Clean the kitchen')
         for f in glob(os.path.join(self.kitchen_path,
                                         self.filename.split('.')[0]+"*")):
             if os.path.isfile(f):

src/worker/run_worker.py

 def main():
     from optparse import OptionParser
     parser = OptionParser()
-    parser.add_option("-a",
-                      "--action",
+    parser.add_option("-d",
+                      "--daemon",
                       dest="action",
                       help="Action can be : start|stop|restart",
                       default=""
         worker = worker_factory(factory_url=options.factory_url,
                        kitchen_path=options.kitchen)
         if worker is not None:
-            logging.debug("worker download the build package")
             worker.download_build_package()
-            logging.debug("Worker execute the task")
             worker.execute_task()
-            logging.debug("Worker post the result")
             worker.post_result()
             if not options.keep_builds:
-                logging.debug("Worker clean the kitchen after the build")
                 worker.clean()
     
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.