服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-03-23 5ec2816b25ccc33855c48da7f7f9305e21e6dc38
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Rhea.Common;
using Sundial;
using System;
using Tiger.IBusiness;
using Tiger.Model;
 
namespace Tiger.Business
{
    /// <summary>
    /// 作业基类
    /// </summary>
    public class TigerJobBase
    {
        public string Id { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
        public string Tag { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
        public string Name { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
 
        /// <summary>
        /// 保存日志
        /// </summary>
        public static ApiAction SaveLog(JobExecutingContext context,string remark) {
            ApiAction action = new ApiAction();
            Type type = Type.GetType(context.JobDetail.JobType, throwOnError: true);
            var job = Biz.Db.Queryable<TSK_JOB>().Where(x=>x.JobName == context.JobId && x.JobType == type.Name).First();
            var logentity = new TSK_LOG { 
                JobId = job.ID,
                TriggerType =context.JobDetail.JobType,
                AssemblyName = context.JobDetail.AssemblyName,
                Args = context.Trigger.Args,
                Operation = context.Trigger.Status.ToString(),
                Status = "Successed",
                StartTime = context.Trigger.StartTime,
                EndTime = context.Trigger.EndTime,
                ElapsedTime = context.Trigger.ElapsedTime,
                Remark = remark
            };
 
            var db = Business.Biz.Db;
            //保存到数据库
            var dbTran = db.UseTran(() =>
            {
                db.Insertable(logentity).ExecuteCommand();
            });
            if (!dbTran.IsSuccess)
            {
                action.GetResponse().CatchExceptionWithLog(dbTran.ErrorException, $"作业保存到数据库异常");
            }
            return action;
        }
 
    }
}