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或者 ...
随机推荐
- StarRC 转XRC flow
抽取寄生参数是我们工作中经常做的事情,目前来说三家EDA 都有抽取工具,分别是StarRC, XRC,QRC,其中QRC现在有个升级版本Quantus,但是由于calibre在DRC 和LVS方面太强 ...
- js导出数据为excel表
1.接口数据后端写, 2.代码如下: var params={ "filters":[ {"propertyCode":"sequenceNo&quo ...
- 华为R&W典型园区网络设计
PS:本人正在学习HCIP中,想到一个典型的园区网络就自己用ENSP搭建了一个典型拓扑分享给大家一起学习 拓扑图如下: 要求已经写在拓扑结构下下方文本框中请自行查看! 配置如下(没有专门的命令插入我就 ...
- 【BOOK】数据存储--MongoDB
MongoDB存储 1.链接MongoDB 指定数据库 指定集合 import pymongo ## 连接数据库 client = pymongo.MongoClient( ...
- 哲讯科技SAP医疗器械行业ERP解决方案
哲讯科技SAP医疗器械行业ERP解决方案主要体现在以预测为指导,计划为执行的管理理念,完全做到实时的全过程的质量管理和质量跟踪.并且通过灵活的质量管理模块大大降低因实施GMP管理给企业带来的成本压力. ...
- linux下进程通信总结
信号: 信号是通知发生了某种事件的机制,内核和进程都可能会向进程发送各种信号,进程也可以向自己发送信号.系统定义了一组标准信号类型,每种信号都拥有唯一的数值和用途.典型的信号递送是异步的,意味着进程可 ...
- Vue源码中的数据代理
直接开讲: 由于这个Vue底层封装的函数太多了,我这里只讲思路不说具体的执行了什么函数. const vm=new Vue({这里写一个data,可以是对象也可以是函数}) 在写这段代码的时候 ...
- GUI程序设计--班级信息收集系
import wx from python实验2 import classinformation class MyFrame(wx.Frame): def __init__(self,parent,i ...
- ADC采样信号RMS测量值的Verilog实现
术语"RMS"代表"Root-Mean-Squared".大多数书籍将此定义为"产生与等效直流电源相同的加热效果的交流电量",或者沿着这些线 ...
- 微信小程序JS遇到【object object 】怎么打印?js如何打印object对象
console.log(JSON.stringify(user)):或者打印的时候直接 console.log(user):不要出现'""'+这些符号