public void Deserialize_WrapsAnException_WithTheJobLoadException() { var serializedData = new InvocationData(null, null, null, null); Assert.Throws<JobLoadException>( () => serializedData.Deserialize()); }
public void Deserialize_ThrowsAnException_WhenMethodCanNotBeFound() { var serializedData = new InvocationData( typeof(InvocationDataFacts).AssemblyQualifiedName, "NonExistingMethod", JobHelper.ToJson(new [] { typeof(string) }), ""); Assert.Throws<JobLoadException>( () => serializedData.Deserialize()); }
public void Deserialize_ThrowsAnException_WhenTypeCanNotBeFound() { var serializedData = new InvocationData( "NonExistingType", "Perform", "", ""); Assert.Throws<JobLoadException>( () => serializedData.Deserialize()); }
public void Deserialize_CorrectlyDeserializes_AllTheData() { var type = typeof(InvocationDataFacts); var methodInfo = type.GetMethod("Sample"); var serializedData = new InvocationData( type.AssemblyQualifiedName, methodInfo.Name, JobHelper.ToJson(new [] { typeof(string) }), JobHelper.ToJson(new [] { "Hello" })); var job = serializedData.Deserialize(); Assert.Equal(type, job.Type); Assert.Equal(methodInfo, job.Method); Assert.Equal("Hello", job.Arguments[0]); }
private static List <RecurringJobDto> GetRecurringJobDtos(IStorageConnection connection, IEnumerable <string> ids) { var result = new List <RecurringJobDto>(); foreach (var id in ids) { var hash = connection.GetAllEntriesFromHash($"recurring-job:{id}"); if (hash == null) { result.Add(new RecurringJobDto { Id = id, Removed = true }); continue; } var dto = new RecurringJobDto { Id = id, Cron = hash["Cron"] }; try { if (hash.TryGetValue("Job", out var payload) && !String.IsNullOrWhiteSpace(payload)) { var invocationData = InvocationData.DeserializePayload(payload); dto.Job = invocationData.DeserializeJob(); } } catch (JobLoadException ex) { dto.LoadException = ex; } if (hash.ContainsKey("NextExecution")) { dto.NextExecution = JobHelper.DeserializeNullableDateTime(hash["NextExecution"]); } if (hash.ContainsKey("LastJobId") && !string.IsNullOrWhiteSpace(hash["LastJobId"])) { dto.LastJobId = hash["LastJobId"]; var stateData = connection.GetStateData(dto.LastJobId); if (stateData != null) { dto.LastJobState = stateData.Name; } } if (hash.ContainsKey("Queue")) { dto.Queue = hash["Queue"]; } if (hash.ContainsKey("LastExecution")) { dto.LastExecution = JobHelper.DeserializeNullableDateTime(hash["LastExecution"]); } if (hash.ContainsKey("TimeZoneId")) { dto.TimeZoneId = hash["TimeZoneId"]; } if (hash.ContainsKey("CreatedAt")) { dto.CreatedAt = JobHelper.DeserializeNullableDateTime(hash["CreatedAt"]); } if (hash.TryGetValue("Error", out var error)) { dto.Error = error; } dto.IsActive = !hash.TryGetValue("IsActive", out var status) || bool.Parse(status); result.Add(dto); } return(result); }
public override JobData GetJobData(string id) { var storedData = Redis.HashGetAll(string.Format(RedisStorage.Prefix + "job:{0}", id)); if (storedData.Length == 0) return null; string type = null; string method = null; string parameterTypes = null; string arguments = null; string createdAt = null; if (storedData.ContainsKey("Type")) { type = storedData.First(x => x.Name == "Type").Value; } if (storedData.ContainsKey("Method")) { method = storedData.First(x => x.Name == "Method").Value; } if (storedData.ContainsKey("ParameterTypes")) { parameterTypes = storedData.First(x => x.Name == "ParameterTypes").Value; } if (storedData.ContainsKey("Arguments")) { arguments = storedData.First(x => x.Name == "Arguments").Value; } if (storedData.ContainsKey("CreatedAt")) { createdAt = storedData.First(x => x.Name == "CreatedAt").Value; } Job job = null; JobLoadException loadException = null; var invocationData = new InvocationData(type, method, parameterTypes, arguments); try { job = invocationData.Deserialize(); } catch (JobLoadException ex) { loadException = ex; } return new JobData { Job = job, State = storedData.ContainsKey("State") ? (string)storedData.First(x => x.Name == "State").Value : null, CreatedAt = JobHelper.DeserializeNullableDateTime(createdAt) ?? DateTime.MinValue, LoadException = loadException }; }
public JobData GetJobData(string id) { var storedData = Redis.GetAllEntriesFromHash( String.Format(RedisStorage.Prefix + "job:{0}", id)); if (storedData.Count == 0) return null; string type = null; string method = null; string parameterTypes = null; string arguments = null; string createdAt = null; if (storedData.ContainsKey("Type")) { type = storedData["Type"]; } if (storedData.ContainsKey("Method")) { method = storedData["Method"]; } if (storedData.ContainsKey("ParameterTypes")) { parameterTypes = storedData["ParameterTypes"]; } if (storedData.ContainsKey("Arguments")) { arguments = storedData["Arguments"]; } if (storedData.ContainsKey("CreatedAt")) { createdAt = storedData["CreatedAt"]; } Job job = null; JobLoadException loadException = null; var invocationData = new InvocationData(type, method, parameterTypes, arguments); try { job = invocationData.Deserialize(); } catch (JobLoadException ex) { loadException = ex; } return new JobData { Job = job, State = storedData.ContainsKey("State") ? storedData["State"] : null, CreatedAt = JobHelper.DeserializeNullableDateTime(createdAt) ?? DateTime.MinValue, LoadException = loadException }; }