Example #1
0
 def set_job_servers(self, servers, pre_connect=False):
     # TODO: don't shut down dups. shut down old ones gracefully
     self.connections = []
     self.connections_by_hostport = {}
     for serv in servers:
         connection = GearmanConnection(serv,timeout=2)
         if pre_connect:
             try:
                 connection.connect()
             except connection.ConnectionError:
                 pass
         self.connections.append(connection)
         self.connections_by_hostport[connection.hostspec] = connection
Example #2
0
 def start_server(self):
     self.server_pid = os.fork()
     if not self.server_pid:
         server = GearmanServer()
         server.start()
         sys.exit()
     connection = GearmanConnection(job_servers[0])
     for i in range(10):
         try:
             connection.connect()
         except GearmanConnection.ConnectionError:
             time.sleep(0.5)
         else:
             break
     connection.close()
Example #3
0
class TestConnection(GearmanTestCase):
    def setUp(self):
        self.start_server()
        self.connection = GearmanConnection(job_servers[0])
        self.connection.connect()

    def tearDown(self):
        self.stop_server()

    def testNoArgs(self):
        self.connection.send_command_blocking("echo_req")
        cmd = self.connection.recv_blocking()
        self.failUnlessEqual(cmd[0], "echo_res")

    def testWithArgs(self):
        self.connection.send_command_blocking("submit_job", dict(func="echo", uniq="", arg="tea"))
        cmd = self.connection.recv_blocking()
        self.failUnlessEqual(cmd[0], 'job_created')
Example #4
0
 def setUp(self):
     self.start_server()
     self.connection = GearmanConnection(job_servers[0])
     self.connection.connect()