/// <summary> /// 保持数据 /// </summary> /// <param name="dto"></param> /// <returns></returns> public string Save(hangfire_task dto) { if (dto.id.EmptyId()) { var exiteJob = Sqldb.Select <hangfire_task>() .Where(s => s.assembly_namespace == dto.assembly_namespace && s.class_name == dto.class_name).Count(); if (exiteJob > 0) { throw new Exception($"任务{dto.assembly_namespace}.{dto.class_name}已存在"); } dto.id = IdWorkerHelper.GenObjectId(); dto.excute_time = DateTime.Now; dto.excute_status = 1; int affect = Sqldb.Insert(dto).ExecuteAffrows(); if (affect < 1) { throw new Exception("任务添加失败"); } return(dto.id); } else { int affect = Sqldb.Update <hangfire_task>().SetSource(dto).IgnoreColumns(s => new { s.excute_time, s.excute_status }).ExecuteAffrows(); if (affect < 1) { throw new Exception("任务添加失败"); } return(dto.id); } }
public IActionResult Save(hangfire_task dto) { string id = _logApp.Save(dto); IJob job = ReflectionHelper.Instance <IJob>(dto.assembly_namespace.Trim(), dto.class_name.Trim()); RecurringJob.AddOrUpdate(id, () => job.Excute(_wxSetting.WeixinAppId, id), dto.cron_express, TimeZoneInfo.Local); return(Success("任务添加完成")); }
public IActionResult Save(hangfire_task dto) { string id = _logApp.Save(dto); IJob job = ReflectionHelper.Instance <IJob>(dto.assembly_namespace.Trim(), dto.class_name.Trim()); Dictionary <string, string> jobParams = new Dictionary <string, string>(); jobParams.Add("jobId", dto.id); RecurringJob.AddOrUpdate(id, () => job.Excute(jobParams), dto.cron_express, TimeZoneInfo.Local); return(Success("任务添加完成")); }