|
| 1 | +""" |
| 2 | +To reload scheduler type: |
| 3 | +import pdg; pdg.TypeRegistry.types().registeredType(pdg.registeredType.Scheduler, "afanasyscheduler").reload() |
| 4 | +""" |
1 | 5 | import json
|
2 | 6 | import logging
|
3 | 7 | import os
|
| 8 | +import socket |
4 | 9 | import sys
|
5 | 10 | import traceback
|
6 | 11 |
|
|
16 | 21 | logging.basicConfig(level = logging.DEBUG)
|
17 | 22 | logger = logging.getLogger(__name__)
|
18 | 23 |
|
19 |
| - |
20 | 24 | class AfanasyScheduler(CallbackServerMixin, PyScheduler):
|
21 | 25 | """
|
22 | 26 | Scheduler implementation that interfaces with a Afanasy farm instance.
|
@@ -44,6 +48,7 @@ def _initData(self):
|
44 | 48 | self.job_id = None
|
45 | 49 | self.job_block_name_id = {}
|
46 | 50 | self.job_tasks_id_name = {}
|
| 51 | + self._local_addr = self._getLocalAddr() |
47 | 52 |
|
48 | 53 |
|
49 | 54 | def _constructJob(self):
|
@@ -109,6 +114,29 @@ def _deleteJob(self):
|
109 | 114 | self._initData()
|
110 | 115 |
|
111 | 116 |
|
| 117 | + def _getLocalAddr(self): |
| 118 | + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| 119 | + try: |
| 120 | + # doesn't even have to be reachable |
| 121 | + s.connect(('10.255.255.255', 1)) |
| 122 | + addr = s.getsockname()[0] |
| 123 | + except Exception: |
| 124 | + addr = socket.gethostbyname(socket.gethostname()) |
| 125 | + finally: |
| 126 | + s.close() |
| 127 | + """ Solution from: |
| 128 | + https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib?page=1&tab=votes#tab-top |
| 129 | + """ |
| 130 | + print(addr) |
| 131 | + return addr |
| 132 | + |
| 133 | + def workItemResultServerAddr(self): |
| 134 | + # By default it uses local host name. |
| 135 | + # On farm better to use direct IP address. |
| 136 | + addr, port = self._workItemResultServerAddr.split(':') |
| 137 | + addr = ':'.join([self._local_addr, port]) |
| 138 | + return addr |
| 139 | + |
112 | 140 | def applicationBin(self, i_app, i_work_item):
|
113 | 141 | """
|
114 | 142 | [virtual] Returns the path to the given application
|
|
0 commit comments