Best way to trigger a cron job on form submit

lcollong

FabriKant d'applications web
Hi,

I have a php script triggered once a day through Fabrik scheduling. Fine.
Under some circumstances, I'd like it to be triggered on a specific form submit (onAfterProcess) without waiting for the next cron run. I could load the php script from the php form plugin but I'd like to use the Fabrik logic to prevent it being triggered twice on the same time. Is this possible ?
 
Hmmm, interesting.

I'm about to work on those chron changes I need to make for the run gating, I'll look and see if there's a simple way to do it.

One thing I'm also going to add is per-plugin query string triggers. At the moment, we allow you to specify that a URL has to have &fabrikcron=1 to trigger the cron handling. I've meaning to extend this for some time to allow you to specify which job you want run, with something like fabrikcron_plugin=X with the numeric ID of the plugin.

That might provide a cheap and easy way of doing this, by simply adding that to whatever URL you redirect to after form submission. Whatever logic you use in the form plugin script to decide if the cron needs to run could be used in the Condition of the redirect.

-- hugh
 
Thanks for looking at this one.
May be, I'm wrong, but I thought &fabrikcron=1 was used to prevent the cron to run except if the url has this parameter. The condition I was talking about is rare so I don't want the cron miss a run (night job or first morning page hit). The idea to add &fabrikcron=1&fabrikcron_plugin=X on redirect seems excellent as far as it let the scheduled task run.
Could probably achieve all of this using the hosted cron server service but it has limitations (at least on this hosting).
 
add is per-plugin query string triggers
Great. Maybe you can add a secret word, too? (Like the free Akeeb version)

@lcollong: if you can trigger a jobwith (and only with) its ID you can set it to "run" e.g. every minute and trigger it manually.

Or maybe "just an other option": run manually only (so no time checking)?
 
By "manually" do you mean with the run button on the back door, or via query string trigger?

Sent from my HTC One using Tapatalk
 
OK, I made most of these changes:

https://github.com/Fabrik/fabrik/commit/7a027fdd077a8992735b6835f4ac0c0d69a2e8e5

So you can now enable run gating on a plugin. With this enabled, it gets unpublished before we run it, then republish when it's finished. And in the main query where we select crons to run, we only select published ones. So if a plugin is still running when the next scheduled runtime arrives, it won't get run again. I've added a PHP shutdown handler as well, so if the code in the pkugin crashes, we still republish and reschedule it.

I also added plugin specific query string secrets, so rather than just fabrik_cron=1, you can specify a 'secret' for a given plugin, which will then only run when fabrik_cron=yoursecret.

@troester - turns out that "only run manually" is not so easy, just because of the way we query for runable tasks. It's do-able, but will need some thought on how best to do it. So for now, the workaround is just to set the frequency very low (like every minute) when you want to use a query string trigger. So it won't run every minute, but will get included in the query results, so we will then check to see if it has a query string trigger.

-- hugh
 
Thanks for the update.
As it requires me to update Fabrik on a test drive, it may last few days before I can test it.
I'll keep you inform of my tests.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top