044_Schedule Job 间隔时间自动执行
需求:系统上的标准功能是能够设置间隔一天的执行,或者是写完代码着急测试我们写个5分钟后执行的;
但是遇到要求没间隔一小时或者十分钟执行,该怎么处理呢?
global class **_RetrieveInquiryBatchtest implements Database.Batchable<sObject>, Database.AllowsCallouts, Database.Stateful, Schedulable {
String query = 'SELECT Id, Inquiry_Type__c, Status__c, Interaction_Number__c, Interaction_Id__c FROM **_Inquirys__c limit 1';
private **_SOA_Settings__c SOASettings = **_SOA_Settings__c.getOrgDefaults();
private List<**_Inquiry.Interaction> interactions;
public **_RetrieveInquiryBatchtest() {
}
public static void runBatch() {
**_SOA_Settings__c SOASettings = **_SOA_Settings__c.getOrgDefaults();
**_RetrieveInquiryBatchtest retrieveBatch = new **_RetrieveInquiryBatchtest();
Id jobId = Database.executeBatch(retrieveBatch, 1);
//Id jobId = Database.executeBatch(retrieveBatch, (Integer)SOASettings.Get_MIR_Statuses_Batch_Limit__c);
}
global void execute(SchedulableContext scMain) {
**_RetrieveInquiryBatchtest retrieveBatch = new **_RetrieveInquiryBatchtest();
Id jobId = Database.executeBatch(retrieveBatch, (Integer)SOASettings.Get_MIR_Statuses_Batch_Limit__c);
}
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<**_Inquirys__c> scope) {
System.debug('----------------------------------');
}
global void finish(Database.BatchableContext BC) {
Datetime now = System.now().addMinutes(1);
String month = string.valueOf(now.month());
String hour = string.valueOf(now.hour());
String day = string.valueOf(now.day());
String minute = string.valueOf(now.minute());
String second = string.valueOf(now.second());
String year = string.valueOf(now.year());
String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
try {
String strJobName = 'Retrieve GMIP Status ' + System.now().format();
System.schedule(strJobName , strSchedule, new **_RetrieveInquiryBatchtest());
} catch (AsyncException e) {
System.debug(e.getMessage());
// create by ** 2016-06-21 -------- monitor the Batch ----------------------------START
}
List<CronTrigger> cronList = [SELECT Id, State FROM CronTrigger WHERE State = 'DELETED'];
for (CronTrigger cron : cronList){
System.abortJob(cron.Id);
}
// Get the ID of the AsyncApexJob representing this batch job
// from Database.BatchableContext.
// Query the AsyncApexJob object to retrieve the current job's information.
// Send an email to the Apex job's submitter notifying of job completion.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'**@**.com'};
mail.setToAddresses(toAddresses);
mail.setSubject('Apex Sharing Recalculation ');
mail.setPlainTextBody('The batch Apex job processed ' );
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
主要是在finish方法中设置的一段 时间 执行代码。
CronTrigger delete 是执行一个schedul 剩下在Scheduled Jobs 上的记录,所以我们要删除已经处理ok的Schedule。
代码执行:
**_SOA_Settings__c SOASettings = **_SOA_Settings__c.getOrgDefaults();
**_RetrieveInquiryBatchtest retrieveBatch = new **_RetrieveInquiryBatchtest();
Id jobId = Database.executeBatch(retrieveBatch, 5);
044_Schedule Job 间隔时间自动执行的更多相关文章
- setTimeout() 实现程序每隔一段时间自动执行
定义和用法 setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式. 语法 setTimeout(code,millisec) 参数 描述 code 必需.要调用的函数后要执行的 Ja ...
- Timer定时方法(间隔时间后执行)
Timer time = new Timer(); time.schedule(new TimerTask() { @Override public void run() { // TODO Auto ...
- 每隔一秒自动执行函数(JavaScript)
http://www.cnblogs.com/xlx0210/archive/2010/03/19/1689497.html 1. setInterval() ——每隔一秒自动执行方法,setInte ...
- Python3.x:简单时间调度Timer(间隔时间执行)
Python3.x:简单时间调度Timer(间隔时间执行) threading模块中的Timer能够帮助实现定时任务,而且是非阻塞的: 代码: import threading import time ...
- 如何让PHP程序自动执行(后台)
如何让php程序自动执行,这个就需要用到一个函数了: int ignore_user_abort ( [bool setting] ) 定义和用法 ignore_user_abort() 函数设置与 ...
- 在CMD下启动vmware、Xshell连接虚拟机以及控制Chrome浏览器自动执行js登录校园网
标题有点长,主要是写个bat出来玩玩, (1)不用每次都手动关闭mysql服务(我不想把它设为手动启动,有强迫症) (2)然后希望每次vmware能自动连上虚拟机 (3)以及每次Xshell都能自动启 ...
- 启动tomcat服务器自动执行一个方法
第一步:配置web.xml文件 添加如下代码 <servlet> <servlet-name>Timer</servlet-name> <servlet-cl ...
- Asp.Net(C#)自动执行计划任务的程序实例分析
在业务复杂的应用程序中,有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行,比如定时备份或同步数据库,定时发送电子邮件等,我们称之为计划任务.实现计划任务的方法也有很多,可以采用SQ ...
- 小记:Quartz 当 Job 执行时间超过触发间隔时间时所发生的情况
一个普通的 Job 实现如下: public class Job1 : IJob { public void Execute(IJobExecutionContext context) { Conso ...
- 使用php作linux自动执行脚本
使用php作linux自动执行脚本 [来源] 达内 [编辑] 达内 [时间]2013-03-21 在作社区时, 时常需要统计上线人数等数据. 一般做法是, 把这段代码放在用户 login或者 ...
随机推荐
- .NET CORE-IIS发布.netcore项目时报错:HTTP错误500.19-Internal Server Error
最近IIS发布Core3.1项目的时候遇到下面问题,发现是缺少ASP.NET Core Runtime 解决方法:安装.netcore host 版本
- git修改远程分支
git remote -v 查看远程仓库 git remote rm origin 删除远程分支 git remote add git remote add origin git@codeup.ali ...
- 教你快速理解Linux虚拟化网络的全脉络,正确配置网络联通性。
https://www.bilibili.com/video/BV1iy4y177f4?p=12 实用的干货快先码起来,说不定以后会用到哟
- 4、Normal Equation 的向量投影解法与几何和直觉解释
参考:https://zhuanlan.zhihu.com/p/269232332 在线性回归的正交方程 ( Normal Equation )推导一文中提到使用 向量投影 的方法一步就能推导出 正交 ...
- 使用NSIS打包软件
平台和所需软件 平台: Windows 使用软件: NSIS https://nsis.sourceforge.io/Download HM NIS Edit https://sourceforge. ...
- 【杂项】瞎玩——suhr RIOT单块制作流程
难得的周末,在家上课似乎丝毫没有轻松多少,然而专业课任务的ddl远在天边,上午赶赶进度似乎稍微闲下来了点,正好前几天找电路的时候看到一个非常nice的效果器制作网站,国内少有深入研究效果器电路的文章, ...
- 个人css样式_2: 渐变色
css的魅惑力 css渐变色用途还是 比较广的. ---------------------------- 效果图: html代码(三个div): <div class="div1&q ...
- moduleNotFoundError:No module named 'exceptions'
如果pip install docx 过请先卸载,输入如下指令: pip uninstall docx 方法一: pip install python-docx 方法二: 下载: python_doc ...
- java将Word转换成PDF方法
转载1:java将Word转换成PDF三种方法_pdfoptions_Zhsh-7的博客-CSDN博客 转载2:POI 实现 word转成pdf - 挽留匆匆的美丽 - 博客园 (cnblogs.co ...
- LocalDateTime与LocalDate
时间新特性 新生事物出现,必定是对旧事物的完善或者是缺陷的弥补. 本文章介绍LocalDate.LocalDateTime.在多线程的情况,相比较于Date.Calendar.SimpleDateFo ...