Ejemplo n.º 1
0
    def __init__(self, slotCount=8, environment=None):
        """
        intialize worker

        :param slotCount: maximum task slot number
        :param environment: worker environment. 'production' or 'development'
        """

        modulePath = os.path.join(os.getcwd(), DIR_TASK_MODULE)

        if not os.path.exists(modulePath):
            os.mkdir(modulePath)

        signal.signal(signal.SIGTERM, self.__signalHandler)
        signal.signal(signal.SIGINT, self.__signalHandler)

        sys.path.append(modulePath)
        sys.path.append(os.getcwd())
        sys.path.append(os.path.join(os.getcwd(), DIR_DEV_MODULE))

        self.slotCount = slotCount
        self.taskSlots = []
        self.devTaskSlots = []
        self.taskList = dict()
        self.msgQueue = Queue.Queue()

        # set excution environment
        if environment in ('production', 'development'):
            self.environment = environment
        else:
            self.environment = workerConfig.get('main', 'environment')

        # setup logging
        logPath, tmp, logFile = workerConfig.get('log', 'file').rpartition('/')
        logLevel = workerConfig.get('log', 'level') if self.environment == 'production' else 'DEBUG'
        log.setupLogger('%s/%s_%s' % (logPath, os.getpid(), logFile), logLevel, 'oceanworker')

        # join worker node
        worker = dict()
        worker['environment'] = self.environment
        worker['maxSlot'] = slotCount
        worker['tasks'] = []
        try:
            worker['ip'] = socket.gethostbyname(socket.gethostname())
        except Exception, e:
            worker['ip'] = '0.0.0.0'
Ejemplo n.º 2
0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#


import scubagear.config as config
import scubagear.logger as log

conf = config.ConfigHandler()

try:
    environment = conf.get('main', 'environment')
except Exception, e:
    log.error("cannot find 'environment' config - use 'production' environment")
    environment = 'production'

if not log.isInitialized() and conf.has_section('log'):
    filename = conf.get('log', 'file') if conf.has_option('log', 'file') else "log/henem.log"
    if environment == 'production':
        level = conf.get('log', 'level') if conf.has_option('log', 'level') else log.INFO
    else:
        level = log.DEBUG

    name = conf.get('log', 'name') if conf.has_option('log', 'name') else "Henem"

    log.setupLogger(filename, level, name)