private static GearmanJobRequest SubmitBackgroundJob(GearmanClientProtocol protocol, string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { var jobHandle = protocol.SubmitBackgroundJob( functionName, functionArgument, uniqueId, priority); return(new GearmanJobRequest(protocol.Connection, jobHandle)); }
public byte[] SubmitJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { var jobHandle = SubmitJob(functionName, functionArgument, false, uniqueId, priority); var result = new List<byte>(); var workDone = false; while (!workDone) { var response = Connection.GetNextPacket(); // TODO: Check that we received a response for/with the same job handle? switch (response.Type) { case PacketType.WORK_FAIL: onJobFailed(new EventArgs()); return null; case PacketType.WORK_COMPLETE: var workComplete = UnpackWorkCompleteResponse(response); onJobCompleted(workComplete); result.AddRange(workComplete.Data); workDone = true; break; case PacketType.WORK_DATA: var workData = UnpackWorkDataResponse(response); onJobData(workData); result.AddRange(workData.Data); break; case PacketType.WORK_WARNING: // Protocol specs say treat this as a DATA packet, so we do var workWarning = UnpackWorkDataResponse(response); onJobWarning(workWarning); break; case PacketType.WORK_STATUS: var workStatus = UnpackStatusResponse(response); onJobStatus(workStatus); break; case PacketType.WORK_EXCEPTION: var workException = UnpackWorkExceptionResponse(response); onJobException(workException); break; case PacketType.ERROR: throw UnpackErrorReponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } } return result.ToArray(); }
private static PacketType GetSubmitJobType(GearmanJobPriority priority, bool background) { switch (priority) { case GearmanJobPriority.High: return(background ? PacketType.SUBMIT_JOB_HIGH_BG : PacketType.SUBMIT_JOB_HIGH); case GearmanJobPriority.Normal: return(background ? PacketType.SUBMIT_JOB_BG : PacketType.SUBMIT_JOB); case GearmanJobPriority.Low: return(background ? PacketType.SUBMIT_JOB_LOW_BG : PacketType.SUBMIT_JOB_LOW); default: throw new GearmanApiException("Unknown priority and background combination for SubmitJobRequest"); } }
public byte[] SubmitJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { var jobHandle = SubmitJob(functionName, functionArgument, false, uniqueId, priority); var result = new List<byte>(); var workDone = false; while (!workDone) { var response = Connection.GetNextPacket(); // TODO: Check that we received a response for/with the same job handle? switch (response.Type) { case PacketType.WORK_FAIL: // Do what? Return null? (should not throw) return null; case PacketType.WORK_COMPLETE: var workComplete = UnpackWorkCompleteResponse(response); result.AddRange(workComplete.Data); workDone = true; break; case PacketType.WORK_DATA: var workData = UnpackWorkDataResponse(response); result.AddRange(workData.Data); break; case PacketType.WORK_WARNING: case PacketType.WORK_STATUS: case PacketType.WORK_EXCEPTION: // TODO: Do what? break; case PacketType.ERROR: throw UnpackErrorReponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } } return result.ToArray(); }
public GearmanJobRequest SubmitBackgroundJob <TArg>(string functionName, TArg functionArgument, string uniqueId, GearmanJobPriority priority, DataSerializer <TArg> argumentSerializer) where TArg : class { if (argumentSerializer == null) { throw new ArgumentNullException("argumentSerializer"); } var functionArgumentBytes = argumentSerializer(functionArgument); // Do this before calling SendClientCommand. return(SendClientCommand(protocol => SubmitBackgroundJob(protocol, functionName, functionArgumentBytes, uniqueId, priority))); }
public GearmanJobRequest SubmitBackgroundJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { return(SubmitBackgroundJob <byte[]>(functionName, functionArgument, uniqueId, GearmanJobPriority.Normal, data => (data))); }
public TResult SubmitJob <TArg, TResult>(string functionName, TArg functionArgument, string uniqueId, GearmanJobPriority priority, DataSerializer <TArg> argumentSerializer, DataDeserializer <TResult> resultDeserializer) where TArg : class where TResult : class { if (argumentSerializer == null) { throw new ArgumentNullException("argumentSerializer"); } if (resultDeserializer == null) { throw new ArgumentNullException("resultDeserializer"); } var functionArgumentBytes = argumentSerializer(functionArgument); // Do this before calling SendClientCommand. var result = SendClientCommand(protocol => protocol.SubmitJob( functionName, functionArgumentBytes, uniqueId, priority)); return(result == null ? null : resultDeserializer(result)); }
public byte[] SubmitJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { return(SubmitJob <byte[], byte[]>(functionName, functionArgument, Guid.NewGuid().ToString(), GearmanJobPriority.Normal, data => (data), data => (data))); }
private static PacketType GetSubmitJobType(GearmanJobPriority priority, bool background) { switch (priority) { case GearmanJobPriority.High: return background ? PacketType.SUBMIT_JOB_HIGH_BG : PacketType.SUBMIT_JOB_HIGH; case GearmanJobPriority.Normal: return background ? PacketType.SUBMIT_JOB_BG : PacketType.SUBMIT_JOB; case GearmanJobPriority.Low: return background ? PacketType.SUBMIT_JOB_LOW_BG : PacketType.SUBMIT_JOB_LOW; default: throw new GearmanApiException("Unknown priority and background combination for SubmitJobRequest"); } }
public string SubmitBackgroundJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { return SubmitJob(functionName, functionArgument, true, uniqueId, priority); }
private string SubmitJob(string functionName, byte[] functionArgument, bool background, string uniqueId, GearmanJobPriority priority) { if (functionName == null) throw new ArgumentNullException("functionName"); Connection.SendPacket(PackRequest( GetSubmitJobType(priority, background), functionName, uniqueId ?? "", functionArgument ?? new byte[0])); var response = Connection.GetNextPacket(); switch (response.Type) { case PacketType.JOB_CREATED: return UnpackJobCreatedResponse(response); case PacketType.ERROR: throw UnpackErrorReponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } }
public byte[] SubmitJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { var jobHandle = SubmitJob(functionName, functionArgument, false, uniqueId, priority); var result = new List <byte>(); var workDone = false; while (!workDone) { var response = Connection.GetNextPacket(); // TODO: Check that we received a response for/with the same job handle? switch (response.Type) { case PacketType.WORK_FAIL: onJobFailed(new EventArgs()); return(null); case PacketType.WORK_COMPLETE: var workComplete = UnpackWorkCompleteResponse(response); onJobCompleted(workComplete); result.AddRange(workComplete.Data); workDone = true; break; case PacketType.WORK_DATA: var workData = UnpackWorkDataResponse(response); onJobData(workData); result.AddRange(workData.Data); break; case PacketType.WORK_WARNING: // Protocol specs say treat this as a DATA packet, so we do var workWarning = UnpackWorkDataResponse(response); onJobWarning(workWarning); break; case PacketType.WORK_STATUS: var workStatus = UnpackStatusResponse(response); onJobStatus(workStatus); break; case PacketType.WORK_EXCEPTION: var workException = UnpackWorkExceptionResponse(response); onJobException(workException); break; case PacketType.ERROR: throw UnpackErrorReponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } } return(result.ToArray()); }
private string SubmitJob(string functionName, byte[] functionArgument, bool background, string uniqueId, GearmanJobPriority priority) { if (functionName == null) { throw new ArgumentNullException("functionName"); } Connection.SendPacket(PackRequest( GetSubmitJobType(priority, background), functionName, uniqueId ?? "", functionArgument ?? new byte[0])); var response = Connection.GetNextPacket(); switch (response.Type) { case PacketType.JOB_CREATED: var packet = UnpackJobCreatedResponse(response); onJobCreated(new EventArgs()); return(packet); case PacketType.ERROR: throw UnpackErrorReponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } }
public string SubmitBackgroundJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { return(SubmitJob(functionName, functionArgument, true, uniqueId, priority)); }
public byte[] SubmitJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { var jobHandle = SubmitJob(functionName, functionArgument, false, uniqueId, priority); var result = new List <byte>(); var workDone = false; while (!workDone) { var response = Connection.GetNextPacket(); // TODO: Check that we received a response for/with the same job handle? switch (response.Type) { case PacketType.WORK_FAIL: // Do what? Return null? (should not throw) return(null); case PacketType.WORK_COMPLETE: var workComplete = UnpackWorkCompleteResponse(response); result.AddRange(workComplete.Data); workDone = true; break; case PacketType.WORK_DATA: var workData = UnpackWorkDataResponse(response); result.AddRange(workData.Data); break; case PacketType.WORK_WARNING: case PacketType.WORK_STATUS: case PacketType.WORK_EXCEPTION: // TODO: Do what? break; case PacketType.ERROR: throw UnpackErrorReponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } } return(result.ToArray()); }
public byte[] SubmitJob(string functionName, byte[] functionArgument, string uniqueId, GearmanJobPriority priority) { var result = new List<byte>(); var workDone = false; lock (Connection.SyncObject) { var jobHandle = SubmitJob(functionName, functionArgument, false, uniqueId, priority); var jobStatus = GetStatus(jobHandle); while (!workDone && jobStatus.IsKnown) { try { var response = Connection.GetNextPacket(); switch (response.Type) { case PacketType.WORK_FAIL: var workFail = UnpackWorkFailResponse(response); if (jobHandle == workFail) { onJobFailed(new EventArgs()); return null; } break; case PacketType.WORK_COMPLETE: var workComplete = UnpackWorkCompleteResponse(response); if (jobHandle == workComplete.JobHandle) { onJobCompleted(workComplete); result.AddRange(workComplete.Data); workDone = true; } break; case PacketType.WORK_DATA: var workData = UnpackWorkDataResponse(response); if (jobHandle == workData.JobHandle) { onJobData(workData); result.AddRange(workData.Data); } break; case PacketType.WORK_WARNING: // Protocol specs say treat this as a DATA packet, so we do var workWarning = UnpackWorkDataResponse(response); if (jobHandle == workWarning.JobHandle) { onJobWarning(workWarning); result.AddRange(workWarning.Data); } break; case PacketType.WORK_STATUS: var workStatus = UnpackStatusResponse(response); if (jobHandle == workStatus.JobHandle) onJobStatus(workStatus); break; case PacketType.WORK_EXCEPTION: var workException = UnpackWorkExceptionResponse(response); if (jobHandle == workException.JobHandle) onJobException(workException); break; case PacketType.ERROR: throw UnpackErrorResponse(response); default: throw new GearmanApiException("Got unknown packet from server"); } } catch (GearmanConnectionException ex) { var inner = ex.InnerException as SocketException; if (inner != null && inner.SocketErrorCode == SocketError.TimedOut) jobStatus = GetStatus(jobHandle); if (inner == null || !jobStatus.IsKnown) throw; } } return result.ToArray(); } }