
import argparse
import socket

from gearhorn import worker


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('host', default=['localhost'],
                        help='Gearman server(s)', nargs='*')
    parser.add_argument('--sqlalchemy-dsn', help='SQLAlchemy DSN for storing'
                        ' matchmaking data')
    opts = parser.parse_args()
    w = worker.GearhornWorker(client_id='gearhorn_%s' % socket.gethostname(),
                              dsn=opts.sqlalchemy_dsn)
    for host in opts.host:
        w.addServer(host)
    try:
        while True:
            w.work()
    except Exception as e:
        print(str(e))
        return -1
    return 0


import argparse
import socket

from gearhorn import worker


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('host', default=['localhost'],
                        help='Gearman server(s)', nargs='*')
    parser.add_argument('--sqlalchemy-dsn', help='SQLAlchemy DSN for storing'
                        ' matchmaking data')
    opts = parser.parse_args()
    w = worker.GearhornWorker(client_id='gearhorn_%s' % socket.gethostname(),
                              dsn=opts.sqlalchemy_dsn)
    for host in opts.host:
        if '/' in host:
            (host, port) = host.split('/')
            w.addServer(host, port=port)
        else:
            w.addServer(host)
    try:
        while True:
            w.work()
    except Exception as e:
        print(str(e))
        return -1
    return 0

Add port specification to gearhorn CLI
Add port specification to gearhorn CLI

  
  import argparse
  import socket
  
  from gearhorn import worker
  
  
  def main():
      parser = argparse.ArgumentParser()
      parser.add_argument('host', default=['localhost'],
                          help='Gearman server(s)', nargs='*')
      parser.add_argument('--sqlalchemy-dsn', help='SQLAlchemy DSN for storing'
                          ' matchmaking data')
      opts = parser.parse_args()
      w = worker.GearhornWorker(client_id='gearhorn_%s' % socket.gethostname(),
                                dsn=opts.sqlalchemy_dsn)
      for host in opts.host:
+         if '/' in host:
+             (host, port) = host.split('/')
+             w.addServer(host, port=port)
+         else:
-         w.addServer(host)
+             w.addServer(host)
      try:
          while True:
              w.work()
      except Exception as e:
          print(str(e))
          return -1
      return 0
  
Add port specification to gearhorn CLI
## Code Before:

import argparse
import socket

from gearhorn import worker


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('host', default=['localhost'],
                        help='Gearman server(s)', nargs='*')
    parser.add_argument('--sqlalchemy-dsn', help='SQLAlchemy DSN for storing'
                        ' matchmaking data')
    opts = parser.parse_args()
    w = worker.GearhornWorker(client_id='gearhorn_%s' % socket.gethostname(),
                              dsn=opts.sqlalchemy_dsn)
    for host in opts.host:
        w.addServer(host)
    try:
        while True:
            w.work()
    except Exception as e:
        print(str(e))
        return -1
    return 0

## Instruction:
Add port specification to gearhorn CLI
## Code After:

import argparse
import socket

from gearhorn import worker


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('host', default=['localhost'],
                        help='Gearman server(s)', nargs='*')
    parser.add_argument('--sqlalchemy-dsn', help='SQLAlchemy DSN for storing'
                        ' matchmaking data')
    opts = parser.parse_args()
    w = worker.GearhornWorker(client_id='gearhorn_%s' % socket.gethostname(),
                              dsn=opts.sqlalchemy_dsn)
    for host in opts.host:
        if '/' in host:
            (host, port) = host.split('/')
            w.addServer(host, port=port)
        else:
            w.addServer(host)
    try:
        while True:
            w.work()
    except Exception as e:
        print(str(e))
        return -1
    return 0
