public async Task <ReturnT> Execute(JobExecuteContext context) { await Task.Delay(500); _logger.LogInformation("defaultJobHandler执行了-------------------------"); await Task.CompletedTask; return(ReturnT.Success()); // return ReturnT.Failed("失败原因"); }
public async Task <ReturnT> Execute(JobExecuteContext context) { var result = ReturnT.Success(); try { var url = _xxlJobOption.HttpJobhandlerUrl; if (string.IsNullOrEmpty(url)) { return(ReturnT.Failed("httpJobHandler任务请配置url")); } JObject jobParameter = JObject.Parse(context.JobParameter); string path = GetPathAndRemovePath(jobParameter); if (string.IsNullOrEmpty(path)) { return(ReturnT.Failed("httpJobHandler任务请配置path")); } // jobParameter.Add("logId", context.LogId); var header = CreateHeader(); var param = new { logId = context.LogId, jobParameter = jobParameter }; var res = await _httpClientFactory.CreateClient().PostJsonAsync <HttpJobHandlerResponse>(StringUtils.AppendUrlPath(url, path), param, header); if (res == null || res.code != HttpJobHandler.SuccessCode) { result = ReturnT.Failed(res?.msg ?? "执行http任务异常"); } } catch (Exception ex) { _logger.LogError(ex, "执行httpJobHandler异常"); result = ReturnT.Failed($"{ex.StackTrace},{ex.Message}"); } return(result); }
public Task <ReturnT> Execute(JobExecuteContext context) { var obj = JsonUtils.FromJson <T>(context.JobParameter); return(Execute(obj)); }