Support forums : Branches

once per day hook

Discussion about existing branches and the directions they need to go in, or, for branches that are going to happen. "Quickies" is wide open. "Branches" is more focused.

Moderator: Dracones

once per day hook

Postby EdB » Sat Feb 26, 2011 7:34 pm

Related to viewtopic.php?f=19&t=531, I'm still interested in a hook that gets triggered once per day. Hitlist::dbprune() does the "once per day" thing nicely, but I'm not sure it is triggered in all cases. It seems that is dependent on auto_prune_stats_mode being set to "page". "cron" MIGHT also do it, but "off" won't.

AppendHitLog (which is a terrible name for something that PERFORMS the hit logging) won't work due to any plugin that returns a true causes all other to die on the vine. That is, however, the right general neighborhood for what I want.

I was working on a plugin to wrap up the stats prior to pruning them so a simple summary could be emailed to the installation/blog owner. Currently I have a plugin that looks for diffs on the server and puts them on the Tools->BarnDoor tab, but I want to make it do a check once per day and email the results to the site owner if anything is found. I can't do either with AppendHitLog due to another plugin could get in there first, thus stopping anything else from playing.

I see basically 3 ways to handle this.
1) Add NewDailyHook to function shutdown() and write code that checks if we've seen a hit today or not. This has the benefit of I'm pretty sure shutdown() is always going to happen eventually :)
2) Add NewDailyHook to function dbprune() and piggyback the existing code, knowing the plugin must insist on autoprune being set to daily. This has the benefit of basically re-using existing code that covers a "once daily" mission.
3) Add NewDailyHook to function log() and again write code that checks if we've seen a hit today or not. The only benefit here is that both NewDailyHook and AppendHitLog would be neighbors.

Oh and NewDailyHook is just as bad as AppendHitLog. Maybe even worse ;) How about the new one being "OnceDailyActions" and the existing one being renamed to "PerformHitLogging"?
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: once per day hook

Postby EdB » Mon Feb 28, 2011 3:54 pm

Went with #2, and did some unrelated stylesheet work as well.

If a plugin makes a form sometimes it gets a border, other times not. Noticed it while working on a plugin that is using v0.0.0 instead of current core, so I checked it against current core admin templates. "fire" and "wind" did not outline plugin-generated forms, but "earth" and "water" did. Dunno why that was. All I know is I added that little detail to this branch.

Currently marked as 'experimental' because I dunno maybe it needs help maybe not. Almost done with "BarnDoor" plugin, so once it goes up to my real server I can see if the new hook will actually work by seeing if it sends me an email saying it found diffs.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: once per day hook

Postby Afwas » Mon Feb 28, 2011 8:10 pm

qp_plugins/test.plugin.php:259
Code: Select all
   /**
    * Execute/Handle a test/sample cronjob.
    */
   function ExecCronJob( & $params )
   {
      if( $params['ctrl'] == 'test_job' )
      {
         return array( 'code' => 1, 'message' => 'Test successful.' );
      }
   }

Calls a cronjob test_job in /qp_inc/cron/jabs/_test_job.php
Code: Select all
$result_message = T_('The TEST cron controller says hello!');

return 1; /* ok */

So that doesn't do anything and also you'd need to add the cronjob (file) manually because the plugin installer won't let you, but this is the way it's supposed to be done.
Afwas
Dracone
User avatar
 
Posts: 72
Joined: Sun Nov 22, 2009 5:28 pm
Location: Groningen, The Netherlands

Re: once per day hook

Postby EdB » Mon Feb 28, 2011 11:41 pm

Afwas wrote:...
So that doesn't do anything and also you'd need to add the cronjob (file) manually because the plugin installer won't let you
...

The whole idea of a cron job running inside that other app and ours is a joke. We really ought to strip that out OR make it work. Tween now and then I'm going with piggybacking on the daily pruning thing.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: once per day hook

Postby Tblue » Tue Mar 01, 2011 6:52 pm

The thing is that our cronjob implementation is only of use if you periodically invoke qp_srvc/cron_exec.php. Guess how you usually do that on UNIX systems? Yeah, using a cronjob -- this time, a real one. Duh.

Well, I guess cronjobs are a neat feature for plugin authors (and for speeding up page loads by cleaning out the session table using a cronjob and not on every page load)...
Tblue
Dracone
 
Posts: 340
Joined: Sat Nov 21, 2009 1:35 pm
Location: Berlin, Germany

Re: once per day hook

Postby EdB » Tue Mar 01, 2011 7:24 pm

So, if I understand correctly, what we can do with ExecCronJob is add stuff via plugins that won't get done unless the installation owner sets up a cron job to run it. Each plugin probably doesn't have control over when their bit runs because they are slaved to the real cron job, but the installation owner doesn't have to create a new cron job for each plugin that might want to do something periodically.

If I'm close then we probably need to (a) figure out how it actually works and (b) document it nicely so's plugin authors can enjoy the hook and installation owners don't have to figure it out on their own each time. For example maybe we tell peeps to make a cron job that runs qp_srvc/cron_exec.php every hour, then we tell plugin authors to pick the frequency dictated by that best suited to their purpose.

(haven't done a cron job in a million years so I forget the details of them but frequency is part of it so there you go)
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: once per day hook

Postby EdB » Tue Mar 01, 2011 7:28 pm

That might actually be better than a "once daily" thing due to the ability to have different plugins do their thing at different times ... assuming authors take advantage. With a once-daily hook it'll be all loaded up at that particular moment.
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: once per day hook

Postby EdB » Tue Mar 01, 2011 7:43 pm

BTW I had this in merge but did a "disapprove" then pulled it out of merge due to plugins don't automagically do the AfterInstall() thing when installed via the installer. They don't now and don't in the branch, but I want to fix that in the branch.

Anyway it seems I pulled it out of merge too soon after doing the disapprove because I never got the email telling me I disapproved it. So if you're wondering why you got an email saying it is in merge when it isn't now you know :)
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona

Re: once per day hook

Postby EdB » Thu Mar 03, 2011 5:17 am

Tblue wrote:... and for speeding up page loads by cleaning out the session table using a cronjob and not on every page load...

I'm pretty sure that isn't the case. I'm pretty sure it is once per day (first hit of the new day) if you have the setting for how many days worth of hits to keep set to something other than zero.

Doing a little "cronjobtest" plugin to see if this is going to add value to my world or not :)
EdB
Dracone
User avatar
 
Posts: 2072
Joined: Sun Nov 22, 2009 7:20 am
Location: Maricopa Arizona


Return to Branches

Who is online

Users browsing this forum: No registered users and 1 guest

cron