Wordpress cron aka schedule? - wordpress

register_activation_hook(__FILE__, 'cron_post_activation');
add_action('post_event', 'cron_post');
function cron_post_activation() {
wp_schedule_event(time(), 'hourly', 'post_event');
}
function cron_post() {
//Do stuff
}
This is not working by default - found out the hard way!
After debugging for hours I stumbled on several posts which claimed that you need to add next line to wp-config.php:
define('DISABLE_WP_CRON', true);
1) What's the logic behind that? Disabling something in order it to work doesn't make sense to me.
2) How to set it up with your own intervals? Docs states you can only use 'hourly', 'twicedaily' and 'daily'.

Yes, you do need to disable WP_CRON, however, you also need to set up your own cron job outside of WordPress to trigger the event. By default, WP's cron feature only kicks in when someone views the site, and even then it's not guaranteed that it will run exactly on time. It's not useful at all if you need something to happen at a specific time or interval.
Assuming you're on a *nix server, the best explanation I have found on how to do this is:
http://bitswapping.com/2010/10/using-cron-to-trigger-wp-cron-php/
The gist of it is that you turn off WordPress's way of triggering its own scheduler, and then access that system directly on a schedule that you set up using the cron program on your server. What this does is set up a barebones WP environment in which to execute tasks without sending any HTML back. This can result in much better performance than pinging your site homepage directly if you have the job set up to visit every minute.
And to the point about "turning it off to make it work" - yes, that seems counterintuitive. What you are actually turning off is the system that checks whether or not to execute the cron task or not. By turning that off, you essentially are building a direct pipeline to that system and telling it to do the job every single time, whenever you tell it to. You're taking the variance out of the system.

Related

Asterisk - Any way to end/cancel the queue wrap-up time?

Any way to end the queue wrap-up time?
We define a wrap-up time of 60 seconds to allow the agents to finish their notes from a call. In some cases, the full 60 seconds is not needed and our agents would like to end their wrap-up time.
Note:I dont want use pause/unpause commands, because I am tracking the pause/unpause events to track the breaks (metting, launch, break, etc) times.
No, there are no way change wrapuptime dynamicaly.
But posible create dialplan/web page support which will pause/unpause or just not allow call device while puting notes.
You also can mark pauses created by web page, so not use it for track breaks.
Bit ancient question, but there is actually a tool which allows you to manage wrap up/pause/unpause of agents and gives you many more features to control/monitor your call center so it might be worth looking at. Have a look at OrderlyStatsSE.

How to call .xqy page from other .xqy page in Marklogic?

Can I call a .xqy page from another .xqy page in Marklogic ?
There are several ways to execute another .xqy, but the most obvious is probably by using xdmp:invoke. That calls the .xqy, waits for its results and returns them on the spot in your code. You can also call a single function using the combination xdmp:function and xdmp:apply. You could also mess around with xdmp:eval, but that is usually a last resort.
Another strategy could be to use xdmp:http-get, but then the execution runs in a different transaction, so would always commit. You would also need to know the url of the other .xqy, which need some knowledge about whether, and how url are rewritten in the app server (not by default).
Running other .xqy without waiting for results is also possible with xdmp:spawn. Particularly usefull for dispatching heavy load of for instance content processing. Dispatching batches of 100 to 1000 docs is quite common. Keep an eye on the task queue size though..
HTH!

Background Task asp.net

I would like to create a background task which continuously inputs the location from a mobile to a database and in a website, I would like to get the same location immediately as it changes.
I am using an SQL Azure database. so pushing and polling are not an option. Also I am not sure if I can use a cache since the location continuously changes.
I think I have to create some infinite loop which carries on a task continuously. But how does this concept work?
Does this simply involve the create of a thread and a while(true) { ... } ?
I worked on a similar situation, and the approach I went for was to have an special page (/StartJob.aspx?AccessKey=xxxxxxxxxxxxx), that when hit with the right access key, would start a job cycle.
I then setup a "Cron Job" using www.setCronJob.com, to call this page at regular intervals. This service can notify you by email if it fails too.
Have a look at the timer control
http://msdn.microsoft.com/en-us/library/bb386404.aspx
sounds like something that could help out with achieving what you need :)

Strategies for "Pre-Warming" an ASP.NET Cache

I have an ASP.NET MVC 3 / .NET Web Application, which is heavily data-driven, mainly around the concept of "Locations" (New York, California, etc).
Anyway, we have some pretty busy database queries, which get cached after they are finished.
E.g:
public ICollection<Location> FindXForX(string x)
{
var result = _cache.Get(x.ToKey()) as Locaiton; // try cache
if (result == null) {
result = _repo.Get(x.ToKey()); // call db
_cache.Add(x.ToKey(), result); // add to cache
}
return result;
}
But i don't want to the unlucky first user to be waiting for this database call.
The database call can take anywhere from 40-60 seconds, well over the default timeout for an ASP.NET request.
I want to "pre-warm" these calls for certain "popular" locations (e.g New York, California) when my app starts up, or shortly after.
I don't want to simply do this in Global asax (Application_Start), because the app will take too long to start up. (i plan to pre-cache around 15 locations, so that's a few minutes of work).
Is there any way i can fire off this logic asynchronously? Maybe a service on the side is a better option?
The only other alternative i can think of is have an admin page which has buttons for these actions. So an administrator (e.g me) can fire off these queries once the app has started up. That would be the easiest solution.
Any advice?
The quick and dirty way would be to fire-off a Task from Application_Start
But I've found that it's nice to wrap this functionality into a bit of infrastructure so that you can create an ~/Admin/CacheInfo page to let you monitor the progress, state, and exceptions that may be in the process of loading up the cache.
Look into "Always running" app setting for IIS 7.5. What this basically do is have an app pool ready whenever the existing one is to be recycled. Of course, the very first would take the 40-60 seconds but afterwards things would be fast unless you physically restart the machine.
Before you start cache warming, I suggest you check that the query is "as fast as it can be" by first looking at how many logical reads it is doing.
Sounds like you should just dump the results in a separate table and have a scheduled task to repopulate that table periodically.
If one pre-calculated table isn't enough because it ends up with too much data that you need to search through, you could use more than one.
One solution is to launch a worker thread in your Application_Start method that does the pre-warming in the background. If you do it right, your app won't take longer to start up, because the thread will be executed asynchronously.
One option is to use a website health monitoring service. It can be used to both check website health, and if scheduled frequently enough, to invoke your common URLs.
Doing the loading in a Task from Application_Start is the way to go, as mentioned by Scott.
Just be careful - if your site restarts and 10 people try to view California, you don't want to end up with 10 instances of _repo.Get(x.ToKey()); // call db simultaneously trying to load the same data.
It might be a good idea to store a boolean value "IsPreloading" in the application state. Set it to true at the start of your preload function and false at the end. If the value is set, make sure you don't load any of your 15 preloaded locations in FindXForX.
Would suggest taking a look at auto-starting your app, especially if you are load balanced.

Can you tell if hook nodapia (or any hook) is being run from batch mode?

I have a Drupal module which performs a soap request on node save via hook_nodapi. This isn't a big performance loss on individual saves, but if thousands of nodes are being saved in batch mode this is a big bottleneck.
I would like to perform a different action when the hook is invoked from batch mode but can't see an easy way to tell this.
Does anyone have any ideas?
You could call batch_get() and check the result. If it is not empty, you are in batch mode.
(Note: Assuming Drupal-6 here)
If you're making reference to a drupal-level batch using Batch API, Henrik's suggestion is best.
If, however, you are making reference to a shell-driven batch process, which is more practical for large batches than web-based ones, you could test php_sapi_name(): if the return is "cli", then it's command-line and can be a shell batch. Depends on your context
You can use a global var that you set in the start of the script and unset / change value in the end. Then you could check for that global var in your hook and do nothing if if it's set with a certain value.

Resources