加入收藏 | 设为首页 | 会员中心 | 我要投稿 十堰站长网 (https://www.0719zz.com/)- 混合云存储、网络、视频终端、云计算、媒体处理!
当前位置: 首页 > 编程开发 > Asp > 正文

源码分析MinimalApi是如何在Swagger中展示

发布时间:2023-02-20 09:33:20 所属栏目:Asp 来源:互联网
导读:1.什么是ScheduleMaster ScheduleMaster是分布式任务调度系统,是国内的一位开发者写的。简称:集中任务调度系统,最简单的理解ScheduleMaster,就是对不同的系统里面的调度任务做统一管理的框架。 例如我们现在有多个系统,每个系统针对自己处理不同的业务场

  CronExpression string 否 cron表达式,如果RunLoop为true则必填
  StartDate DateTime 是 任务开始时间
  EndDate DateTime 否 任务停止时间,为空表示不限停止时间
  Remark string 否 任务描述说明
  HttpRequestUrl string 是 请求地址
  HttpMethod string 是 请求方式,仅支持GETPOSTPUTDELETE
  HttpContentType string 是 参数格式,仅支持application/json和application/x-www-form-urlencoded
  HttpHeaders string 否 自定义请求头,ScheduleParam列表的json字符串
  HttpBody string 是 如果是json格式参数,则是对应参数的json字符串;如果是form格式参数,则是对应ScheduleParam列表的json字符串。
  Keepers List<int> 否 监护人id
  Nexts List<guid> 否 子级任务id
  Executors List<string> 否 执行节点名称
  RunNow bool 否 创建成功是否立即启动
 
  HttpClient client = new HttpClient();
  List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>();
  args.Add(new KeyValuePair<string, string>("MetaType", "2"));
  args.Add(new KeyValuePair<string, string>("RunLoop", "true"));
  args.Add(new KeyValuePair<string, string>("CronExpression", "22 0/8 * * * ?"));
  args.Add(new KeyValuePair<string, string>("Remark", "By Xunit Tester Created"));
  args.Add(new KeyValuePair<string, string>("StartDate", DateTime.Today.ToString("yyyy-MM-dd HH:mm:ss")));
  args.Add(new KeyValuePair<string, string>("Title", "Http接口测试任务"));
  args.Add(new KeyValuePair<string, string>("HttpRequestUrl", "http://localhost:56655/api/1.0/value/jsonpost"));
  args.Add(new KeyValuePair<string, string>("HttpMethod", "POST"));
  args.Add(new KeyValuePair<string, string>("HttpContentType", "application/json"));
  args.Add(new KeyValuePair<string, string>("HttpHeaders", "[]"));
  args.Add(new KeyValuePair<string, string>("HttpBody", "{ "Posts": [{ "PostId": 666, "Title": "tester", "Content":"testtesttest" }], "BlogId": 111, "Url":"qweqrrttryrtyrtrtrt" }"));
  HttpContent reqContent = new FormUrlEncodedContent(args);
  var response = await client.PostAsync("http://localhost:30000/api/Task/Create", reqContent);
  var content = await response.Content.ReadAsStringAsync();
  Debug.WriteLine(content);
 
  4.创建延时任务
  接口地址:http://yourip:30000/api/delaytask/create
  请求类型:POST
  参数格式:application/x-www-form-urlencoded
  返回结果:创建成功返回任务id
  参数列表:
  参数名称 参数类型 是否必填 说明
  SourceApp string 是 来源
  Topic string 是 主题
  ContentKey string 是 业务关键字
  DelayTimeSpan int 是 延迟相对时间
  DelayAbsoluteTime DateTime 是 延迟绝对时间
  NotifyUrl string 是 回调地址
  NotifyDataType string 是 回调参数格式,仅支持application/json和application/x-www-form-urlencoded
  NotifyBody string 是 回调参数,json格式字符串
  
  for (int i = 0; i < 5; i++)
  {
      int rndNum = new Random().Next(20, 500);
      List<KeyValuePair<string, string>> args = new List<KeyValuePair<string, string>>();
      args.Add(new KeyValuePair<string, string>("SourceApp", "TestApp"));
      args.Add(new KeyValuePair<string, string>("Topic", "TestApp.Trade.TimeoutCancel"));
      args.Add(new KeyValuePair<string, string>("ContentKey", i.ToString()));
      args.Add(new KeyValuePair<string, string>("DelayTimeSpan", rndNum.ToString()));
      args.Add(new KeyValuePair<string, string>("DelayAbsoluteTime", DateTime.Now.AddSeconds(rndNum).ToString("yyyy-MM-dd HH:mm:ss")));
      args.Add(new KeyValuePair<string, string>("NotifyUrl", "http://localhost:56655/api/1.0/value/delaypost"));
      args.Add(new KeyValuePair<string, string>("NotifyDataType", "application/json"));
      args.Add(new KeyValuePair<string, string>("NotifyBody", "{ "Posts": [{ "PostId": 666, "Title": "tester", "Content":"testtesttest" }], "BlogId": 111, "Url":"qweqrrttryrtyrtrtrt" }"));
      HttpContent reqContent = new FormUrlEncodedContent(args);
      var response = await client.PostAsync("http://localhost:30000/api/DelayTask/Create", reqContent);
      var content = await response.Content.ReadAsStringAsync();
      Debug.WriteLine(content);
  }
 
  4.框架简单分析
 
  1.全局设计
  根据官网的设计图,以及操作的流程,简单总结一下任务全局流程为客户端—–>master——>work—–>执行任务。从大的架构方向的思想就是,将原有单个服务中业务和任务调度混合的方式做一些改变,使业务和调度分离,专门把任务调度部分剥离出来,作为一个独立的进程,来统一调用和管理任务,而原有服务只做业务处理。
 
  2.Master和Work分析
  我们主要从主节点,从节点,数据表这几个方面来简单分析,整个业务的时序流程,从本质来看并不复杂master和Work之间的关系是相互配合的,可能乍一看下面整个图有点混乱,下面来解释一下,其实Master节点将任务添加到数据中,然后work节点,去从对应的数据表中取出任务数据,然后根据任务对应的配置,生成配置信息,调用Quartz执行任务,这就是我们整个框架中最核心的业务。
 
  当然master和work除了主要承载了整个管理系统的UI可视化、后台业务操作、任务执行之外,如果从细节以及实现方式来说主要做了以下事情:
 
  Master
 
  1.分配任务执行和选择节点
  2.对work节点进行健康检查,对任务进行故障转移
  Work
 
  1.取出任务配置信息
  2.使用Quartz根据配置运行任务
  3.使用反射调用程序集
  4.使用httpclient调用http 接口

(编辑:十堰站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读