Kill the scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2017 03:33 AM
Hi All
We have a scheduled job running which has to delete records from task table. It needs to delete 400000 records. Its deleting only 20K per day.
Because of the scheduled job, instance has become slow.
We want to run the scheduled job during the non business hours.
Is it possible to kill the scheduled job automctically when we business hours starts. lets say it starts at 8 am, Can we kill the scheduled job automatically.
Manually we can but is it possible to automate that.
Thanks
Sonali
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2017 05:26 AM
Technically yes, practically NO.
You can three scheduled scripts:
1. To initiate the job/script every 12 hrs.
2. To run all executions.
3. To stop the execution every 12 hrs and 1 mins.
But, remember if this is a leased instance for clients, within few hours our ServiceNow HI team would contact you and ask reasons , for high semaphores blockages on the instance with the event creator's user name. I have had personal experiences of such.
Chances are they may kill the job before contacting you..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2017 05:33 AM
Hi Sharique,
So its better to set limit and let it stop on its own ?
But i would like to know how u scripted to kill that.. incase you have handy..can you please share?
Thanks
Sonali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2017 05:08 AM
Hi Sonali,
Use the code below :
GlideTransactionManager.kill(current.session_id);
In the scheduled job
Query "v_transaction" table and iterate through the active transactions(or any other custom query you want to embed), capture the session id and pass in the code above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-20-2017 05:14 AM
Hi Ravi
The session id is getting dynamically generated. So, is there a way i can say yes this is the session id of the scheduled job. i dont want to kill other running jobs but just this one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-22-2017 11:56 PM
Hi Sonali,
While iterating through "v_transaction" table you can query with the URL to identify the transaction you want to cancel. Once you get the transaction to be cancelled you can get the Session Id in the "Session id" field as shown below. Just pass this session id to below code
GlideTransactionManager.kill(current.session_id);