private void RegisterAllFunctions(IGearmanConnection connection) { foreach (var functionName in _functionInformation.Keys) { RegisterFunction(connection, functionName); } }
private void AddConnection(IGearmanConnection connection) { if (connection == null) { throw new ArgumentNullException("connection"); } _connections.Add(connection); }
private void SetClientId(IGearmanConnection connection) { try { new GearmanWorkerProtocol(connection).SetClientId(_clientId); } catch (GearmanConnectionException) { connection.MarkAsDead(); } }
private static void RegisterFunction(IGearmanConnection connection, string functionName) { try { new GearmanWorkerProtocol(connection).CanDo(functionName); } catch (GearmanConnectionException) { connection.MarkAsDead(); } }
public GearmanJobRequest(IGearmanConnection connection, string jobHandle) { if (connection == null) throw new ArgumentNullException("connection"); if (jobHandle == null) throw new ArgumentNullException("jobHandle"); Connection = connection; JobHandle = jobHandle; }
protected bool Work(IGearmanConnection connection) { try { var protocol = new GearmanWorkerProtocol(connection); var jobAssignment = protocol.GrabJob(); if (jobAssignment == null) { return(false); } if (!_functionInformation.ContainsKey(jobAssignment.FunctionName)) { throw new GearmanApiException(String.Format("Received work for unknown function {0}", jobAssignment.FunctionName)); } CallFunction(protocol, jobAssignment); return(true); } catch (GearmanConnectionException) { connection.MarkAsDead(); return(false); } catch (GearmanFunctionInternalException functionException) { // The job function threw an exception. Just as with other exceptions, we disconnect // from the server because we don't want the job to be removed. See general exception // catch for more information. connection.Disconnect(); var shouldThrow = OnJobException(functionException.InnerException, functionException.JobInfo); if (shouldThrow) { throw; } return(false); } catch (Exception) { // We failed to call the function and there isn't any good response to send the server. // According to this response on the mailing list, the best action is probably to close the connection: // "A worker disconnect with no response message is currently how the server's retry behavior is triggered." // http://groups.google.com/group/gearman/browse_thread/thread/5c91acc31bd10688/529e586405ed37fe // // We can't send Complete or Fail for the job, because that would cause the job to be "done" and the server wouldn't retry. connection.Disconnect(); throw; } }
public GearmanJobRequest(IGearmanConnection connection, string jobHandle) { if (connection == null) { throw new ArgumentNullException("connection"); } if (jobHandle == null) { throw new ArgumentNullException("jobHandle"); } Connection = connection; JobHandle = jobHandle; }
protected virtual void OnConnectionConnected(IGearmanConnection connection) { }
protected GearmanProtocol(IGearmanConnection connection) { Connection = connection; }
public GearmanClientProtocol(IGearmanConnection connection) : base(connection) { }
public GearmanWorkerProtocol(IGearmanConnection connection) : base(connection) { }
private void AddConnection(IGearmanConnection connection) { if (connection == null) throw new ArgumentNullException("connection"); _connections.Add(connection); }
protected override void OnConnectionConnected(IGearmanConnection connection) { RegisterAllFunctions(connection); SetClientId(connection); }