SchedulerX2.0支持一次性任务

简介: SchedulerX2.0支持一次性任务

应用场景

未来固定时间点跑一次,任务自动销毁。常见场景

  • 订单超时未支付自动关闭
  • 定时日历提醒


优势

精准时刻

SchedulerX的一次性任务与延时消息相比,没有固定延迟多少时间或者在多少天内的限制,可以支持到未来任意时间点,使用简单。


丰富的任务类型

SchedulerX一次性任务可以适用所有任务类型,比如java、http、shell任务。也可以适用所有分布式模型,比如单机、广播、分片、MapReduce等。


可视化运维

SchedulerX的一次性任务,和其他任务一样,有可视化的界面可以看到和查询,甚至可以在调度时间来临之前随意修改任务参数。

支持失败自动重试等功能。


用法

通过API创建one_time任务

依赖sdk

<dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>aliyun-java-sdk-schedulerx2</artifactId>
      <version>1.0.6</version>
</dependency>


timeType设置为5,代码如下:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobRequest;
import com.aliyuncs.schedulerx2.model.v20190430.CreateJobResponse;
public class CreateJavaJob {
    public static void main(String[] args) throws Exception {
        // Open API 的接入点,具体查看上表支持地域列表以及购买机器地域填写
        String regionId = "public";
        //鉴权使用的 AccessKeyId,由阿里云官网控制台获取
        String accessKeyId = "xxxxxxxx";
        //鉴权使用的 AccessKeySecret,由阿里云官网控制台获取
        String accessKeySecret = "xxxxxxxxx";
        //产品名称
        String productName ="schedulerx2";
        //对照支持地域列表选择Domain填写
        String domain ="schedulerx.aliyuncs.com";
        //构建 OpenApi 客户端
        DefaultProfile.addEndpoint(regionId, productName, domain);
        DefaultProfile defaultProfile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
        DefaultAcsClient client = new DefaultAcsClient(defaultProfile);
        CreateJobRequest request = new CreateJobRequest();
        request.setJobType("java");
        request.setExecuteMode("standalone");
        request.setDescription("test");
        request.setName("一次性任务测试");
        request.setClassName("com.alibaba.schedulerx.test.processor.HelloWorldJob3");
        //timeType=5表示一次性任务
        request.setTimeType(5);
        //yyyy-MM-dd HH:mm:ss
        request.setTimeExpression("2021-12-15 12:11:00");
        request.setNamespace("433d8b23-06e9-408c-aaaa-90d4d1b9a4af");
        request.setGroupId("xueren_sub");
        // 监控报警
        request.setTimeoutEnable(true);
        request.setTimeoutKillEnable(true);
        request.setFailEnable(true);
        request.setTimeout(12300L);
        // 高级配置,配置失败自动重试
        request.setMaxAttempt(3);
        request.setAttemptInterval(30);
        CreateJobResponse response = client.getAcsResponse(request);
        if (response.getSuccess()) {
            System.out.println("jobId=" + response.getData().getJobId());
        } else {
            System.out.println(response.getMessage());
        }
    }   
}


控制台可视化

通过API新建任务后,可以在控制台看到一次性任务如下图


任务实现

和其他任务实现一致,任务执行完,调度平台会自动清理任务,客户端不需要删除任务

import com.alibaba.schedulerx.worker.domain.JobContext;
import com.alibaba.schedulerx.worker.processor.JavaProcessor;
import com.alibaba.schedulerx.worker.processor.ProcessResult;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
@Component
public class HelloWorldJob3 extends JavaProcessor {
    @Override
    public ProcessResult process(JobContext context) throws Exception {
        System.out.println("hello HelloWorldJob3");
        return new ProcessResult(true);
    }
}


目录
相关文章
|
2天前
|
资源调度 Java
在SchedulerX中,你可以使用`schedulerx.submitTask(taskName)`方法来提交并执行单个任务
【1月更文挑战第7天】【1月更文挑战第34篇】在SchedulerX中,你可以使用`schedulerx.submitTask(taskName)`方法来提交并执行单个任务
24 1
|
2天前
|
Java 调度 数据库管理
APScheduler自定义配置
APScheduler自定义配置
18 0
|
2天前
|
资源调度
在SchedulerX中,你可以使用`schedulerx.output()`函数来向Worker报告运行结果
【1月更文挑战第7天】【1月更文挑战第35篇】在SchedulerX中,你可以使用`schedulerx.output()`函数来向Worker报告运行结果
21 1
|
8月前
|
Java 调度 Spring
非分布式任务调度@Scheduled
@Scheduled注解是Spring Boot提供的用于定时任务控制的注解,主要用于控制任务在某个指定时间执行,或者每隔一段时间执行,默认是在单线程中执行的
65 0
|
数据可视化 Linux Python
Schedule | 轻量化的定时任务模块
Schedule | 轻量化的定时任务模块
327 0
|
资源调度 监控 数据可视化
阿里巴巴任务调度SchedulerX支持日志服务
阿里巴巴任务调度SchedulerX2.0的日志服务,可以让业务方不需要修改一行代码,只需要增加一个log4j2/logback的配置,即可将每次任务调度的框架日志和业务日志进行收集,同时提供白屏日志检索功能,可以通过任务调度平台快速定位任务失败的原因。
1088 0
|
资源调度 分布式计算 运维
阿里巴巴任务调度SchedulerX支持一次性任务
阿里巴巴任务调度SchedulerX2.0支持一次性任务
1088 2
|
运维 资源调度 调度
阿里巴巴任务调度SchedulerX兼容XXL-JOB
阿里巴巴任务调度SchedulerX2.0兼容XXL-JOB任务接口,支持@XxlJob新注解和@JobHandler老注解方式,用户不需要修改一行代码,即可以将XXL-JOB任务在SchedulerX2.0平台上托管。
3952 1
阿里巴巴任务调度SchedulerX兼容XXL-JOB
定时测试BlockingScheduler
定时测试BlockingScheduler
185 0
|
机器学习/深度学习 人工智能 Kubernetes
进击的 Kubernetes 调度系统(二):支持批任务的 Coscheduling/Gang scheduling
阿里云容器服务团队结合多年 Kubernetes 产品与客户支持经验,对 Kube-scheduler 进行了大量优化和扩展,逐步使其在不同场景下依然能稳定、高效地调度各种类型的复杂工作负载。《进击的 Kubernetes 调度系统》系列文章将把我们的经验、技术思考和实现细节全面地展现给 Kubernetes 用户和开发者,期望帮助大家更好地了解 Kubernetes 调度系统的强大能力和未来发展方向。本文为该系列文章的第二篇。
进击的 Kubernetes 调度系统(二):支持批任务的 Coscheduling/Gang scheduling