public Task <CoreBaseResponse <string> > Execute(JobExecuteContext context) { Console.WriteLine($"hello! :{context.JobParameter}"); Console.WriteLine($"hello! :{context.LogId}"); _logger.LogInformation("aaa"); return(Task.FromResult("ok".Success())); }
public override async Task <ReturnT> Execute(JobExecuteContext context) { context.JobLogger.Log("receive demo job handler,parameter:{0}", context.JobParameter); context.JobLogger.Log("开始休眠10秒"); await Task.Delay(10 * 1000); context.JobLogger.Log("休眠10秒结束"); return(ReturnT.SUCCESS); }
public Task <ReturnT> Execute(TriggerParam triggerParam, CancellationToken cancellationToken) { var handler = _handlerFactory.GetJobHandler(triggerParam.ExecutorHandler); if (handler == null) { return(Task.FromResult(ReturnT.Failed($"job handler [{triggerParam.ExecutorHandler} not found."))); } var context = new JobExecuteContext(this._jobLogger, triggerParam.ExecutorParams, cancellationToken); return(handler.Execute(context)); }
public override async Task <ReturnT> Execute(JobExecuteContext context) { if (string.IsNullOrEmpty(context.JobParameter)) { return(ReturnT.Failed("url is empty")); } string url = context.JobParameter; if (!UrlPattern.IsMatch(url)) { return(ReturnT.Failed("url format is not valid")); } context.JobLogger.Log("Get Request Data:{0}", context.JobParameter); using (var client = this._httpClientFactory.CreateClient(Constants.DefaultHttpClientName)) { try { var response = await client.GetAsync(url); if (response == null) { context.JobLogger.Log("call remote error,response is null"); return(ReturnT.Failed("call remote error,response is null")); } if (response.StatusCode != HttpStatusCode.OK) { context.JobLogger.Log("call remote error,response statusCode ={0}", response.StatusCode); return(ReturnT.Failed("call remote error,response statusCode =" + response.StatusCode)); } string body = await response.Content.ReadAsStringAsync(); context.JobLogger.Log("<br/> call remote success ,response is : <br/> {0}", body); return(ReturnT.SUCCESS); } catch (Exception ex) { context.JobLogger.LogError(ex); return(ReturnT.Failed(ex.Message)); } } }
public async Task <ReturnT> Execute(JobExecuteContext context) { var result = ReturnT.Success(); try { //await Task.Delay(30000); //这里执行业务逻辑 _logger.LogInformation("SecondJobHandler执行了-------------------------"); await Task.CompletedTask; } catch (BizException) //业务异常 { } catch (Exception ex) { //只有系统异常返回错误,便于重试 result = ReturnT.Failed(ex.Message); } return(result); }
public async Task <ReturnT> Execute(JobExecuteContext context) { var result = ReturnT.Success(); try { // await Task.Delay(30000); //这里执行业务逻辑 //_logger.LogInformation("firstJobHandler执行了{0}, {1}", "1", 2); _logger.LogInformation("firstJobHandler执行了{a}, {b}", "1", 2); //只占位符 //throw new Exception(" 系统异常了,要重试了吧"); await Task.CompletedTask; } catch (BizException) //业务异常 { } catch (Exception ex) { //只有系统异常返回错误,便于重试 result = ReturnT.Failed($"{ex.StackTrace},{ex.Message}"); } return(result); }
public override Task <ReturnT> Execute(JobExecuteContext context) { context.JobLogger.Log("receive demo job handler,parameter:{0}", context.JobParameter); return(Task.FromResult(ReturnT.SUCCESS)); }
public abstract Task <ReturnT> Execute(JobExecuteContext context);
public Task <ReturnT> Execute(JobExecuteContext context) { _logger.LogInformation($"Hello, {context.LogId}, {context.JobParameter}"); return(Task.FromResult(ReturnT.Success())); }