public async Task <CrontabJobData> GetCrontabJobData(string jobId) { var data = await _database.HashGetAllAsync(Helper.GetCrontabHashId(_options, jobId)); if (data == null || data.Length == 0) { return(null); } var dict = data.ToDictionary(); CrontabJobData result = new CrontabJobData { JobId = dict.ContainsKey(nameof(CrontabJobData.JobId)) ? dict[nameof(CrontabJobData.JobId)] : RedisValue.EmptyString, JobName = dict.ContainsKey(nameof(CrontabJobData.JobName)) ? dict[nameof(CrontabJobData.JobName)] : RedisValue.EmptyString, CrontabExpression = dict.ContainsKey(nameof(CrontabJobData.CrontabExpression)) ? dict[nameof(CrontabJobData.CrontabExpression)] : RedisValue.EmptyString, Data = dict.ContainsKey(nameof(CrontabJobData.Data)) ? dict[nameof(CrontabJobData.Data)] : RedisValue.Null, Topic = dict.ContainsKey(nameof(CrontabJobData.Topic)) ? dict[nameof(CrontabJobData.Topic)] : RedisValue.EmptyString, LastExecuteTime = NumberUtils.ToLong(dict.GetValue(nameof(CrontabJobData.LastExecuteTime))), Status = NumberUtils.ToInt(dict.GetValue(nameof(CrontabJobData.Status))) // dict.ContainsKey(nameof(CrontabJobData.LastExecuteTime)) ? dict[nameof(CrontabJobData.LastExecuteTime)] : RedisValue.EmptyString, }; if (string.IsNullOrEmpty(result.JobId)) { result = null; } return(result); }
public Task <bool> EnqueueCrontab(CrontabJobData crontabJobData) { var values = crontabJobData.ToDictionary(); var hashId = Helper.GetCrontabHashId(_options, crontabJobData.JobId); var trans = _database.CreateTransaction(); trans.KeyDeleteAsync(hashId); trans.HashSetAsync(hashId, values.ToArray()); trans.SetAddAsync(Helper.GetCrontabSetName(_options), crontabJobData.JobId); trans.PublishAsync(_crontabJobChannelSubscription.Channel, crontabJobData.JobId); var result = trans.Execute(); return(Task.FromResult(result)); }
public async Task PublishCrontabAsync(Type messageType, object message, CrontabJobInfo crontabJobInfo) { var isExsits = await _redisStorage.ExistsCrontabJob(crontabJobInfo.JobId); AssertUtils.IsTrue(isExsits == false, $"该定时任务已存在 jobId={crontabJobInfo.JobId}"); //传入redis即可 var crontabJobData = new CrontabJobData { JobId = crontabJobInfo.JobId, JobName = crontabJobInfo.JobName, CrontabExpression = crontabJobInfo.CrontabExpression, Data = _options.Serializer.Serialize(message), Topic = GetTopic(messageType), Status = (int)crontabJobInfo.Status }; var result = await _redisStorage.EnqueueCrontab(crontabJobData); AssertUtils.IsTrue(result, $"redis生产定时任务失败,topic:{crontabJobData.Topic}"); }
private async Task Enqueue(CrontabJobData crontabJobData) { var jobData = JobData.CreateJobData(crontabJobData.Topic, crontabJobData.Data); await _redisStorage.Enqueue(jobData); }