Skip to content

Commit

Permalink
PDG: workItemResultServerAddr() return IP:port, not localhostname:port
Browse files Browse the repository at this point in the history
On farm artist machine can be not reachable by name.

References: #514.
  • Loading branch information
timurhai committed Jul 14, 2021
1 parent d3cc714 commit 44e5941
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion plugins/houdini/pdg/types/afanasyscheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""
To reload scheduler type:
import pdg; pdg.TypeRegistry.types().registeredType(pdg.registeredType.Scheduler, "afanasyscheduler").reload()
"""
import json
import logging
import os
import socket
import sys
import traceback

Expand All @@ -16,7 +21,6 @@
logging.basicConfig(level = logging.DEBUG)
logger = logging.getLogger(__name__)


class AfanasyScheduler(CallbackServerMixin, PyScheduler):
"""
Scheduler implementation that interfaces with a Afanasy farm instance.
Expand Down Expand Up @@ -44,6 +48,7 @@ def _initData(self):
self.job_id = None
self.job_block_name_id = {}
self.job_tasks_id_name = {}
self._local_addr = self._getLocalAddr()


def _constructJob(self):
Expand Down Expand Up @@ -109,6 +114,29 @@ def _deleteJob(self):
self._initData()


def _getLocalAddr(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.255.255.255', 1))
addr = s.getsockname()[0]
except Exception:
addr = socket.gethostbyname(socket.gethostname())
finally:
s.close()
""" Solution from:
https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib?page=1&tab=votes#tab-top
"""
print(addr)
return addr

def workItemResultServerAddr(self):
# By default it uses local host name.
# On farm better to use direct IP address.
addr, port = self._workItemResultServerAddr.split(':')
addr = ':'.join([self._local_addr, port])
return addr

def applicationBin(self, i_app, i_work_item):
"""
[virtual] Returns the path to the given application
Expand Down

0 comments on commit 44e5941

Please sign in to comment.