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
crawler-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 crawler-task.py
10 @author Oleksii <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 
18 import ppath
19 from ppath import sys
20 
21 # For profiling
22 import app.Profiler as Profiler
23 
24 
25 # import time
26 # s = time.time()
27 # Start profiling
28 pr = Profiler.Profiler()
29 # print "t1=" + str(time.time() - s)
30 # s = time.time()
31 if pr and pr.status > 0:
32  pr.start()
33 # print "t1=" + str(time.time() - s)
34 
35 
36 import os
37 import sys
38 from dc_crawler.CrawlerTask import CrawlerTask
39 from time import sleep
40 from sys import argv
41 import app.Consts as APP_CONSTS
42 
43 
44 # That script create main crawler application
45 
46 
47 app = None
48 exit_code = APP_CONSTS.EXIT_SUCCESS
49 
50 try:
51  # create the app
52  app = CrawlerTask()
53  # setup the application
54  app.setup()
55  app.args.add_argument('-c', '--config', action='store', metavar='config_file', help='config ini-file', required=True)
56  # run the application
57  app.run()
58  exit_code = app.exit_code
59  # log message about profiler
60  if pr.errorMsg:
61  app.logger.error(pr.errorMsg)
62 except Exception, err:
63  sys.stderr.write(str(err))
64  exit_code = APP_CONSTS.EXIT_FAILURE
65 except:
66  exit_code = APP_CONSTS.EXIT_FAILURE
67 finally:
68  # stop profiling
69  if pr:
70  pr.stop()
71  # close the app
72  if app:
73  app.close()
74 
75  sys.stdout.flush()
76  os._exit(exit_code)