HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
processor-task.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 
4 """
5 HCE project, Python bindings, Distributed Tasks Manager application.
6 Event objects definitions.
7 
8 @package: dc
9 @file processor-task.py
10 @author Oleksii, bgv <developers.hce@gmail.com>
11 @link: http://hierarchical-cluster-engine.com/
12 @copyright: Copyright &copy; 2013-2014 IOIX Ukraine
13 @license: http://hierarchical-cluster-engine.com/license/
14 @since: 0.1
15 """
16 
17 import ppath
18 from ppath import sys
19 
20 # For profiling
21 import app.Profiler as Profiler
22 
23 
24 # Start profiling
25 pr = Profiler.Profiler()
26 if pr and pr.status > 0:
27  pr.start()
28 
29 
30 import os
31 import sys
32 from dc_processor.ProcessorTask import ProcessorTask
33 from dc_processor.Scraper import EXIT_SUCCESS
34 from dc_processor.Scraper import EXIT_FAILURE
35 import app.Consts as APP_CONSTS
36 
37 
38 # That script create main application
39 
40 app = None
41 exit_code = EXIT_SUCCESS
42 
43 try:
44  # create the app
45  app = ProcessorTask()
46  # setup the application
47  app.setup()
48  # add support command line arguments
49  app.args.add_argument('-c', '--config', action='store', metavar='config_file', help='config ini-file', required=True)
50  # run the application
51  app.run()
52 
53  exit_code = app.getExitCode()
54 
55  # log message about profiler
56  if pr.errorMsg and app.logger:
57  app.logger.error(pr.errorMsg)
58 
59 except Exception, err:
60  sys.stderr.write(str(err) + '\n')
61  exit_code = EXIT_FAILURE
62 except:
63  exit_code = EXIT_FAILURE
64 finally:
65  # stop profiling
66  if pr:
67  pr.stop()
68  # close the app
69  if app:
70  app.close()
71 
72  sys.stdout.flush()
73  os._exit(exit_code)