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
db-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 db-task.py
10 @author igor
11 @link: http://hierarchical-cluster-engine.com/
12 @copyright: Copyright © 2013-2014 IOIX Ukraine
13 @license: http://hierarchical-cluster-engine.com/license/
14 @since: 0.1
15 """
16 import ppath
17 from ppath import sys
18 
19 # For profiling
20 import app.Profiler as Profiler
21 
22 
23 # Start profiling
24 pr = Profiler.Profiler()
25 if pr and pr.status > 0:
26  pr.start()
27 
28 
29 from dc_db.DBTask import DBTask
30 import dc_db.DBTask
31 import os
32 
33 from app.Consts import EXIT_SUCCESS
34 from app.Consts import EXIT_FAILURE
35 import app.Consts as APP_CONSTS
36 
37 
38 app = None
39 exit_code = EXIT_SUCCESS
40 
41 try:
42  # create the app
43  app = DBTask()
44  # setup the application
45  app.setup()
46  # add support command line arguments
47  app.args.add_argument("-c", "--config", action="store", required=True)
48 
49  # run the application
50  app.run()
51 
52  exit_code = app.errorCode
53 
54  # log message about profiler
55  if pr.errorMsg and dc_db.DBTask.logger:
56  dc_db.DBTask.logger.error(pr.errorMsg)
57 
58 except Exception as err:
59  if dc_db.DBTask.logger:
60  dc_db.DBTask.logger.error(str(err))
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)
74 
75 #-------------------------------------------------------------