Exemplo n.º 1
0
 public GearmanJob(GearmanWorkerProtocol protocol, GearmanJobInfo jobAssignment,
                   DataDeserializer <TArg> argumentDeserializer, DataSerializer <TResult> resultSerializer)
 {
     _serializer      = resultSerializer;
     _deserializer    = argumentDeserializer;
     _protocol        = protocol;
     Info             = jobAssignment;
     FunctionArgument = _deserializer(jobAssignment.FunctionArgument);
 }
Exemplo n.º 2
0
        private void CallFunction(GearmanWorkerProtocol protocol, GearmanJobInfo jobAssignment)
        {
            var functionInformation = _functionInformation[jobAssignment.FunctionName];

            object job;

            try
            {
                job = functionInformation.JobConstructor.Invoke(new object[]
                {
                    protocol,
                    jobAssignment,
                    functionInformation.ArgumentDeserializer,
                    functionInformation.ResultSerializer,
                });
            }
            catch (Exception ex)
            {
                throw new GearmanException("Failed to invoke the GearmanJob constructor", ex);
            }

            try
            {
                functionInformation.Function.DynamicInvoke(job);
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException != null)
                {
                    // Remove the TargetInvocationException wrapper that DynamicInvoke added,
                    // so we can give the user the exception from the job function.
                    throw new GearmanFunctionInternalException(
                              jobAssignment,
                              String.Format("Function '{0}' threw exception", jobAssignment.FunctionName), ex.InnerException);
                }

                // If there is no inner exception, something strange is up, so then we want to throw this exception.
                throw new GearmanException("Failed to invoke the function dynamically", ex);
            }
            catch (Exception ex)
            {
                throw new GearmanException("Failed to invoke the function dynamically", ex);
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Called when a job function throws an exception. Does nothing and returns false, to not abort the work loop.
 /// </summary>
 /// <param name="exception">The exception thrown by the job function.</param>
 /// <param name="jobAssignment">The job assignment that the job function got.</param>
 /// <returns>Return true if it should throw, or false if it should not throw after the return.</returns>
 protected override bool OnJobException(Exception exception, GearmanJobInfo jobAssignment)
 {
     // Don't throw the exception, as that would abort the work loop.
     return false;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Called when a job function throws an exception. The default implementation returns true.
 /// </summary>
 /// <param name="exception">The exception thrown by the job function.</param>
 /// <param name="jobAssignment">The job assignment that the job function got.</param>
 /// <returns>Return true if it should throw, or false if it should not throw after the return.</returns>
 protected virtual bool OnJobException(Exception exception, GearmanJobInfo jobAssignment)
 {
     return(true);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Called when a job function throws an exception. Does nothing and returns false, to not abort the work loop.
 /// </summary>
 /// <param name="exception">The exception thrown by the job function.</param>
 /// <param name="jobAssignment">The job assignment that the job function got.</param>
 /// <returns>Return true if it should throw, or false if it should not throw after the return.</returns>
 protected override bool OnJobException(Exception exception, GearmanJobInfo jobAssignment)
 {
     // Don't throw the exception, as that would abort the work loop.
     return(false);
 }