/// <summary> /// Compiles the input linqExpression into a Linq expression tree /// </summary> /// <param name="linqExpression">The linqExpression.</param> /// <returns></returns> public Func<object, object, object> CompileFunction(LinqExpressionToRun linqExpression) { using (_compileFunctionTimer.NewContext()) { return _handler.CompileFunction(linqExpression); } }
/// <summary> /// Compiles the input linqExpression into a Linq expression tree /// </summary> /// <param name="linqExpression">The linqExpression.</param> /// <returns></returns> public Action<object, object> CompileAction(LinqExpressionToRun linqExpression) { if (linqExpression.Unique) //don't bother caching { _counterActionCacheUnique.Increment(); return _handler.CompileAction(linqExpression); } var key = GenerateKey(linqExpression); var result = (Action<object, object>)_cache[key]; if (result != null) { _counterActionCacheHit.Increment(key); return result; } result = _handler.CompileAction(linqExpression); if (!_cache.Contains(key)) { _counterActionCacheMiss.Increment(key); _cache.Add(key, result, _itemPolicy); } return result; }
internal ScheduledJob(JobScheduler scheduler, string name, IJobSchedule schedule, IProducerMethodJobQueue queue, LinqExpressionToRun expressionToRun, IGetTime time, string route ) { _scheduler = scheduler; Name = name; Schedule = schedule; _queue = queue; _expressionToRun = expressionToRun; _getTime = time; Route = route; }
/// <summary> /// Compiles the input linqExpression into a Linq expression tree /// </summary> /// <param name="linqExpression">The linqExpression.</param> /// <returns></returns> public Func<object, object, object> CompileFunction(LinqExpressionToRun linqExpression) { Guard.NotNull(() => linqExpression, linqExpression); Guard.NotNullOrEmpty(() => linqExpression.Linq, linqExpression.Linq); var compiler = _objectPool.GetObject(); try { return compiler.CompileFunction(linqExpression); } catch (Exception error) { throw new CompileException($"Failed to compile linq expression [{linqExpression.Linq}]", error, linqExpression.Linq); } finally { _objectPool.ReturnObject(compiler); } }
/// <summary> /// Sends the specified linqExpression for execution. /// </summary> /// <param name="linqExpression">The linqExpression.</param> /// <param name="timeOut">The time out.</param> /// <param name="data">The data.</param> /// <returns></returns> /// <remarks>Your expression must return a type of object, or the JSON serializer may throw casting errors</remarks> public async Task<IReceivedMessage<object>> SendAsync(LinqExpressionToRun linqExpression, TimeSpan timeOut, IAdditionalMessageData data = null) { var message = new MessageExpression(MessageExpressionPayloads.FunctionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression)); return await _queue.SendAsync(message, timeOut, data).ConfigureAwait(false); }
/// <summary> /// Sends the specified linqExpression for execution. /// </summary> /// <param name="linqExpression">The linqExpression.</param> /// <param name="timeOut">The time out.</param> /// <param name="data">The data.</param> /// <returns></returns> /// <remarks>Your expression must return a type of object, or the JSON serializer may throw casting errors</remarks> public IReceivedMessage<object> Send(LinqExpressionToRun linqExpression, TimeSpan timeOut, IAdditionalMessageData data = null) { var message = new MessageExpression(MessageExpressionPayloads.FunctionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression)); return _queue.Send(message, timeOut, data); }
/// <summary> /// Sends the specified action to the specified queue. /// </summary> /// <param name="job">The job.</param> /// <param name="scheduledTime">The scheduled time.</param> /// <param name="expressionToRun">The expression to run.</param> /// <returns></returns> public async Task<IJobQueueOutputMessage> SendAsync(IScheduledJob job, DateTimeOffset scheduledTime, LinqExpressionToRun expressionToRun) { var data = SendPreChecks(job.Name, scheduledTime); if (data != null) return data; var messageData = new AdditionalMessageData(); SetMetaDataForJob(job.Name, scheduledTime, new DateTimeOffset(GetTimeFactory.Create().GetCurrentUtcDate()), job.Route, messageData); var message = await Queue.SendAsync(expressionToRun, messageData).ConfigureAwait(false); var result = ProcessResult(job, scheduledTime, message); if (result != null) return result; //try one more time result = ProcessResult(job, scheduledTime, await Queue.SendAsync(expressionToRun, messageData).ConfigureAwait(false)); return result ?? new JobQueueOutputMessage(JobQueuedStatus.Failed); }
/// <summary> /// Generates a key for the cache /// </summary> /// <param name="linqExpression">The linq expression.</param> /// <returns></returns> private string GenerateKey(LinqExpressionToRun linqExpression) { var builder = new StringBuilder(); builder.Append(linqExpression.Linq); foreach (var field in linqExpression.References) { builder.Append(field); builder.Append("|"); } foreach (var field in linqExpression.Usings) { builder.Append(field); builder.Append("|"); } return builder.ToString(); }
/// <summary> /// Sends the specified linqExpression to be executed. Additional message meta data is optional. /// </summary> /// <param name="linqExpression">The linqExpression to execute.</param> /// <param name="data">The optional additional message data.</param> /// <returns></returns> public async Task<IQueueOutputMessage> SendAsync(LinqExpressionToRun linqExpression, IAdditionalMessageData data = null) { var message = new MessageExpression(MessageExpressionPayloads.ActionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression)); return await _queue.SendAsync(message, data).ConfigureAwait(false); }
/// <summary> /// Sends the specified linqExpression to be executed. Additional message meta data is optional. /// </summary> /// <param name="linqExpression">The linqExpression to execute.</param> /// <param name="data">The optional additional message data.</param> /// <returns></returns> public IQueueOutputMessage Send(LinqExpressionToRun linqExpression, IAdditionalMessageData data = null) { var message = new MessageExpression(MessageExpressionPayloads.ActionText, _compositeSerialization.InternalSerializer.ConvertToBytes(linqExpression)); return _queue.Send(message, data); }
/// <summary> /// Sends the specified dynamic linqExpression to be executed. /// </summary> /// <param name="job">The job.</param> /// <param name="scheduledTime">The scheduled time.</param> /// <param name="linqExpression">The linqExpression to execute.</param> /// <returns></returns> public async Task<IJobQueueOutputMessage> SendAsync(IScheduledJob job, DateTimeOffset scheduledTime, LinqExpressionToRun linqExpression) { if(!_started) throw new DotNetWorkQueueException("Start must be called before sending jobs"); return await _sendJobToQueue.SendAsync(job, scheduledTime, linqExpression).ConfigureAwait(false); }
/// <summary> /// Compiles the input linqExpression into a Linq expression tree /// </summary> /// <param name="linqExpression">The linqExpression.</param> /// <returns></returns> public Func<object, object, object> CompileFunction(LinqExpressionToRun linqExpression) { _compiler.References = DefaultReferences.Union(linqExpression.References).ToArray(); _compiler.Usings = DefaultUsings.Union(linqExpression.Usings).ToArray(); return _compiler.ParseLambdaExpr<Func<object, object, object>>(linqExpression.Linq).Compile(); }