14 import socket |
14 import socket |
15 import struct |
15 import struct |
16 import sys |
16 import sys |
17 import time |
17 import time |
18 import traceback |
18 import traceback |
|
19 import contextlib |
19 from zlib import adler32 |
20 from zlib import adler32 |
20 |
21 |
21 |
22 |
22 class BackgroundClient(object): |
23 class BackgroundClient: |
23 """ |
24 """ |
24 Class implementing the main part of the background client. |
25 Class implementing the main part of the background client. |
25 """ |
26 """ |
26 def __init__(self, host, port, maxProcs): |
27 def __init__(self, host, port, maxProcs): |
27 """ |
28 """ |
58 """ |
59 """ |
59 sys.path.insert(1, path) |
60 sys.path.insert(1, path) |
60 try: |
61 try: |
61 importedModule = __import__(module, globals(), locals(), [], 0) |
62 importedModule = __import__(module, globals(), locals(), [], 0) |
62 self.services[fn] = importedModule.initService() |
63 self.services[fn] = importedModule.initService() |
63 try: |
64 with contextlib.suppress(AttributeError): |
64 self.batchServices["batch_" + fn] = ( |
65 self.batchServices["batch_" + fn] = ( |
65 importedModule.initBatchService() |
66 importedModule.initBatchService() |
66 ) |
67 ) |
67 except AttributeError: |
|
68 pass |
|
69 return 'ok' |
68 return 'ok' |
70 except ImportError: |
69 except ImportError as err: |
71 return 'Import Error' |
70 return 'Import Error: ' + str(err) |
|
71 except Exception as err: |
|
72 return str(err) |
72 |
73 |
73 def __send(self, fx, fn, data): |
74 def __send(self, fx, fn, data): |
74 """ |
75 """ |
75 Private method to send a job response back to the BackgroundService |
76 Private method to send a job response back to the BackgroundService |
76 server. |
77 server. |