PasteTaskBase 25.6.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PasteTaskBase --version 25.6.1
                    
NuGet\Install-Package PasteTaskBase -Version 25.6.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PasteTaskBase" Version="25.6.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PasteTaskBase" Version="25.6.1" />
                    
Directory.Packages.props
<PackageReference Include="PasteTaskBase" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PasteTaskBase --version 25.6.1
                    
#r "nuget: PasteTaskBase, 25.6.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PasteTaskBase@25.6.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PasteTaskBase&version=25.6.1
                    
Install as a Cake Addin
#tool nuget:?package=PasteTaskBase&version=25.6.1
                    
Install as a Cake Tool

一款使用.NET6.0编写的任务调度器

如果作为单机使用,则只需要查看 Services.AddLocalTaskService()的相关说明即可!
如果作为集群使用,则需要安装对应的服务端,然后查看Services.AddRemoteTaskService()的说明!

最小的执行频率是1秒!如果任务过多的话,需要拆分!

如果是服务端模式,部署后的访问后台应该是http://xxxx.com/task/page/index.html

25.06

1.修复时间Tick的问题,之前会有重叠问题
2.采用忽略模式,减少运行占用造成的跳秒事件
3.如果任务过多,需要修改源码

25.04

1.重新整理服务端代码,之前对于密钥有很混乱的问题
2.规范全部使用timestamp_rand_temp的密钥模式,放于headers的xtoken
3.去除不需要的干扰,至于任务中心中的各个任务的隔断,由各自处理

appsettings.json中的配置说明

客户端的配置


  "TaskNodeConfig": {
    "Url": "http://192.168.2.50:36001/",//当前节点的访问地址,如果是本地模式留空
    "Group": "default",//基于这个名称进行分组,远端模式的时候任务会被发送到随机的一个节点
    "MasterUrl": "http://192.168.2.50:36000/",//远程模式中的服务端的访问域名,如果是本地模式留空
    "ClientCode": "123",//集群的时候注意修改,公用一样的会造成被下线
    "PublicToken": "88888888888888888888888888888888"//远程模式下服务端的公共密钥,防止别的任务乱入服务端
  },

远端调用的服务写法

    /// <summary>
    /// 远程服务 回收服务
    /// </summary>
    public class RemoteTaskHandler : IPasteTaskBase
    {

        public RemoteTaskHandler()
        {
            //这里可以依赖注入
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override bool IsLocationService()
        {
            //告知是远端服务,由服务端调用
            return false;
        }

        /// <summary>
        /// 具体的业务代码部分
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public override async Task<PasteTaskCallBackModel> Work(PasteTaskSharedModel info)
        {
            //以下是具体的业务代码
            var rand = new Random();
            await Task.Delay(rand.Next(100, 10000));
            var randnum = rand.Next(1, 10);

            //下方的返回内容会发送到服务端,用于统计任务执行结果,或者重试等!
            return new PasteTaskCallBackModel() { code = 200, logid = info.TaskLogId, message = "work!", taskid = info.Id };
        }

    }

本地服务的写法

    /// <summary>
    /// 本地服务 案例
    /// </summary>
    public class LocalTaskHandler : IPasteTaskBase
    {

        public LocalTaskHandler()
        {
            //这里可以依赖注入
        }

        /// <summary>
        /// 是本地服务,还是远端服务
        /// </summary>
        /// <returns></returns>
        public override bool IsLocationService()
        {
            return true;
        }

        public override string LocationTickRegex()
        {
            //轮询模式:时:分:秒 
            //表示多久执行一次,01:00:00 表示3600秒执行一次
            如果是100个小时执行一次,则为 100:00:00

            //逢点模式:(.*)00:00:00
            //表示当前时间转化成yyyy-MM-dd HH:mm:ss的格式,然后和正则匹配,如果命中则执行这个任务!
            //也支持星期模式比如星期天的早上5点42分03秒执行,则Sun(.*)05:42:03

            return "01:00:00";
        }

        public override Task<PasteTaskCallBackModel> Work(PasteTaskSharedModel info)
        {
            return base.Work(info);
        }
    }

注意如果是远端模式,需要使用到路由 /api/taskclient/xxxx


builder.Services.AddTransient<IPasteTaskBase, RemoteTaskHandler>();//看注入方式,这个是瞬时的
builder.Services.Configure<TaskNodeConfig>(_Configuration.GetSection("TaskNodeConfig"));
builder.Services.AddSingleton<IPasteTaskBase, LocalTaskHandler>();//看注入方式,这个是单例的
builder.Services.AddRemoteTaskService();//服务端模式,远程模式
builder.Services.AddLocalTaskService();//本地模式,单机模式

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
26.1.2 91 1/21/2026
26.1.1 100 1/13/2026
25.8.2 235 8/27/2025
25.8.1 231 8/27/2025
25.7.1 174 7/17/2025
25.6.3 180 6/20/2025
25.6.2 188 6/17/2025
25.6.1 186 6/5/2025
25.4.1 231 4/18/2025
24.11.1 158 12/5/2024
24.7.31.1 147 7/31/2024