public async Task EnqueueAsync(Expression <Action> methodCall) { if (methodCall == null) { throw new ArgumentNullException(nameof(methodCall)); } var method = MethodInvocation.FromExpression(methodCall); await EnqueueCore(null, method); _server.Pulse(PulseKind.BackgroundJobEnqueued); }
private async Task EnqueueCore(DateTime?due, MethodInvocation method) { var data = InvocationData.Serialize(method); var job = new Job(data.Serialize()) { Due = due }; await _connection.StoreJobAsync(job); if (job.Due == null) { _server.Pulse(); } }
private async Task EnqueueCore(DateTime?due, MethodInvocation method) { var data = InvocationData.Serialize(method); var serializedData = data.Serialize(); var job = new Job(serializedData) { Due = due }; await _connection.StoreJobAsync(job); if (_logger.IsEnabled(LogLevel.Debug)) { var methodCall = string.Format( "{0}.{1}({2})", method.Type.Name, method.Method.Name, string.Join(", ", method.Args.Select(arg => Helper.ToJson(arg)))); if (due == null) { _logger.LogDebug( "Enqueuing a job to be executed immediately: {MethodCall}", methodCall); } else { var diff = due.Value - DateTime.UtcNow; var after = diff.TotalSeconds < 60 ? $"{Math.Round(diff.TotalSeconds, 2)} secs" : (diff.TotalMinutes < 60 ? $"{Math.Round(diff.TotalMinutes, 2)} minutes" : (diff.TotalHours < 24 ? $"{Math.Round(diff.TotalHours, 2)} hours" : ($"{Math.Round(diff.TotalDays, 2)} days"))); _logger.LogDebug( "Enqueuing a job to be executed after {After}: {MethodCall}", after, methodCall); } } if (job.Due == null) { _server.Pulse(); } }