Cron task runs for only 1.5 min and stops - cron

The task loads PHP code that updates the price and availability of products in an online store.
After checking the database, I found that the process aborts after about 1.5 min without updating all products.
How can I extend the time?
Platform OpenCart 2.3.
A cron task: wget -q --spider https://mysite.om/index.php?route=extension/module... Is it correct?

Check the php.ini
ini_set('max_execution_time', 300); // 300 seconds = 5 minutes
ini_set('max_execution_time', 0); // 0=NOLIMIT
But on the most shared servers this function does not work it is not allowed.

Related

Vanilla NodeJS Cron Job?

I want to do something in node at, say, midnight each day.
I see a lot of stuff pointing me to node-cron, and I see this article configuring a docker container to execute a script per a crontab
I want to 1. not use any external packages and 2. keep the script being executed inside the server code itself (i.e. I couldn't have the docker container execute some other file on a schedule)
The use case is I want to update a cache on the server every day around midnight, and then, at more frequent intervals, use that cache for various things.
You can use setInterval to run the code every hour and check if it's around midnight
setInterval(() => {
if (new Date().getHours() === 0) {
// do stuff
}
}, 1000 * 60 * 60 * 60)

nodejs setTimeout not working when called from cron job

I am writing a nodejs program, which needs to upload local sensor information to central database every 15 seconds. since the minimum cron interval is 1 minute, i am calling the the upload routine 4 times like this
function uploadToDatabase() { /* blah blah blah */ }
setTimeout(uploadToDatabase, 1*1000);
setTimeout(uploadToDatabase, 15*1000);
setTimeout(uploadToDatabase, 30*1000);
setTimeout(uploadToDatabase, 45*1000);
this function getting called as intended when i run this in command like like
node uploader.js
but when this is called from cron job this function uploadToDatabase never called?
Any idea why?
You don't need a cron job. Just run it in node and have a loop that executes every 15 seconds.

Schedule publishing of a post in a rails 3 blog

I'm developing a website (with Rails 3.1) where limited set of 'writers' are able to write post. 'Moderators' should accept (or decline) the post and schedule the publishing. Until this moment is the development process pretty basic.
There are two publish moments each day. Accepted posts will be placed in some kind of queue. Each day at 10:00am and 4:00pm the oldest accepted post must be published. However, I need also to be able to ** manually set** a date and time when the post going live.
What's the best way to achieve the result? Cron? Background Jobs?
So...
1) have an accepted_at field, which you can also set manually; it's the 'time to go live'.
2)
class Post
scope :ready_to_be_published, lambda{ where(['accepted_at<? and not published', Time.zone.now]).order('accepted_at ASC') }
def accept!(time_to_go_live = nil)
update_attributes!(:accepted_at => time_to_go_live || Time.zone.now)
end
end
3) have a whenever job at 10am and 4pm to run a rake task
task :publish_a_post => :environment do
Post.ready_to_be_published.first.update_attributes!(:published => true)
end

Hudson SCM Polling Thread hungs while polling

We use Hudson for our continuose build environment. For some reason, the thread for SCM Polling hungs somethimes after a while. I've experiemented a lot with the settings, but nothing seems to really work. How to fix this and are there some scripts out there which can detect such a case to be able to restart hudson? Btw. restarting hudson is the only way to solve this issue for us at the moment.
That is similar to bug 5413, which should be solved since late 2010 with HUDSON 5977 (Hudson 1.380+, or now Jenkins).
You had in those thread some way to kill any thread stuck on the polling step:
very primitive (I'm too lazy to develop something better as this is not very important issue) Groovy script is bellow.
It could happened that it will kill also SCM polling which are not stuck, but we run this script automatically only once a day so it doesn't cause any troubles for us.
You can improve it e.g. by saving ids and names of SCM polling threads, check once again after some time and kill only threads which ids are on the list from previous check.
Thread.getAllStackTraces().keySet().each(){ item ->
if( item.getName().contains("SCM polling") &&
item.getName().contains("waiting for hudson.remoting")){
println "Interrupting thread " + item.getId() item.interrupt()
}
}
The other answer didn't work for me, but the following script found the the issue for this problem did:
Jenkins.instance.getTrigger("SCMTrigger").getRunners().each()
{
item ->
println(item.getTarget().name)
println(item.getDuration())
println(item.getStartTime())
long millis = Calendar.instance.time.time - item.getStartTime()
if(millis > (1000 * 60 * 3)) // 1000 millis in a second * 60 seconds in a minute * 3 minutes
{
Thread.getAllStackTraces().keySet().each()
{
tItem ->
if (tItem.getName().contains("SCM polling") && tItem.getName().contains(item.getTarget().name))
{
println "Interrupting thread " + tItem.getName();
tItem.interrupt()
}
}
}
}

Timer Job Scheduling on DataSheet Entry in SharePoint

I have a list on which I have an ItemUpdated handler.
When I edit using the datasheet view and modify every item, the ItemUpdated event will obviously run for every single item.
In my ItemUpdated event, I want it to check if there is a Timer Job scheduled to run. If there is, then extend the SPOneTimeSchedule schedule of this job to delay it by 5 seconds. If there isn't, then create the Timer Job and schedule it for 5 seconds from now.
I've tried looking to see if the job definition exists in the handler and if it does exist, then extend the schedule by 5 seconds. If it doesn't exist, then create the job definition to run in a minutes time.
MyTimerJob rollupJob = null;
foreach (SPJobDefinition job in web.Site.WebApplication.JobDefinitions)
{
if (job.Name == Constants.JOB_ROLLUP_NAME)
{
rollupJob = (MyTimerJob)job;
}
}
if (rollupJob == null)
{
rollupJob = new MyTimerJob(Constants.JOB_ROLLUP_NAME, web.Site.WebApplication);
}
SPOneTimeSchedule schedule = new SPOneTimeSchedule(DateTime.Now.AddSeconds(5));
rollupJob.Schedule = schedule;
rollupJob.Update();
When I try this out on the server, I get a lot of errors
"An update conflict has occurred, and you must re-try this action. The object MyTimerJob Name=MyTimerJobName Parent=SPWebApplication Name=SharePoint -80 is being updated by NT AUTHORITY\NETWORK SERVICE in the w3wp process
I think the job is probably running for the first time and once running, the other ItemUpdated events are coming in and finding the existing Job definition. It then tries to Update this definition even though it is currently being used. Should I make a new Job Definition name so that it doesn't step on top of the first? Or raise the time to a minute?
I solved this myself by just setting the delay to a minutes time from now regardless of whether a definition is found. This way, while it is busy, it will keep pushing back the scheduling of the job until it is done processing
This is because the event is asynchronous. You'll need to rethink exactly what you're trying to solve with this code and potentially re-factor it.
Maybe you should try using "lock" on the timer job object?

Resources