1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Scheduled Task Firing Multiple times

Discussion in 'Community' started by davez, Dec 15, 2019.

  1. davez

    davez Member

    Level: Community
    This may be a new issue. However, it is solved by using Run Gating.

    Just a heads up. I have a couple of different scripts that are triggered once a day. They take about 10 seconds to complete processing. What seems to have been happening was that during that 10 seconds (before it was complete) the site would re-trigger the processing (I'm guessing because another visitor triggered it). So, I noticed that it would run up to 4 different times. I'm logging the events.

    The only reason this was a problem is because it fired off emails to users. So, users were getting multiple emails from the script. But I've turned on Run Gating within the cron and that seems to have solved the problem.
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    If you want to make sure a scheduled task is triggered exactly once (no matter if there's any or a lot frontend activity) you can also use "Use querystring" (and if you want to separate multiple scheduled tasks also "Query secret") and trigger the task(s) via a cron job on your server.
     
  3. davez

    davez Member

    Level: Community
    Okay. I didn't know that about triggering it via a cron job. Thank you.
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    You can use 'wget' from your OS's cron to hit a link on your server to trigger our scheduled tasks. Best done in conjunction with a "query secret" on the Fabrik task. Then in your OS cron ...

    wget http://your.site/index.php?fabrik_cron=yoursecret

    Set the OS cron to run at least as often as the settings in the Fabrik task.

    -- hugh
     
  5. davez

    davez Member

    Level: Community
    Perfect. Thank you. I hadn't noticed the new features...then again, maybe they have been new for many years.
     
  6. sunnyjey

    sunnyjey Active Member

    Level: Community
    I am planning to execute Cron once in a day, daily at 10am to send 5-20 Email notification to the users with the the help of PHP Script Plugin.

    Looking for some serious tips from the Seniors:
    • Should it be like range of 5-10 10 * * * or just * 10 * * * . ?
    • What should be the ideal run in backend of fabrik schedule: 1 per min or 5 per min ?
    • What is recommendation to avoid sending multiple Email Notifications to the same user (Email address) . Do you recommend to create an additional field (0/1 radiobutton switch) which will get updated after execution of Task ?
    Thank you in advance.
     
  7. davez

    davez Member

    Level: Community
    I had difficulty getting cron job working, so I reverted to using the Use Run Gating feature which has worked properly, but I've only been testing for a few days. The fear is that the script could fail and leave the scheduled task unpublished, and the entire tasks stops working.

    What went wrong with my Use Querystring set up? Not sure. The cron job would fire properly. It would trigger the Fabrik scheduled task script using the Require Querystring option and a Secret. The Fabrik scheduled task would reset the date ran (so it only ran once per day). But the script would not actually run. I'm wondering if had something to do with the wget command never completing the page load. I have my code entered into the "PHP Code" section of the scheduled task. It works fine if I run it any other way than the Require Querystring option. That said, it did work using the Use Querystring option, but not reliably (for me). For testing, I set the cron job to one minute and would reset the Schedule Task Date manually, when I wanted it to re-run. I also added a script that would log the start and completing of the script, just in case.

    The way I set it up was to run both the cron job and scheduled task once per day. However, I have not tried having the cron job fire more often than once a day. You could have it fire once per hour for a once a day scheduled task. Every time the scheduled task runs, it resets the date/time, so it won't fire again until the next day, even if the cron job calls the wget again using the Require querystring option. I may try this, but my scripts are live, so I need them to reliably work now.

    The original problem was that the script took long enough for it to run, that the script was being fired multiple times until the initial firing completed. Run Gating solves this, as will using Require Querystring, if you can get it to work properly.

    Oh, and I do have a radio button switch to store whether the mail was sent in a table, but the only reason I have that is just for storing the data. My scripts are time sensitive, so I send it once during a 24 hour time window.
     
    sunnyjey likes this.
  8. bclayton

    bclayton New Member

    Level: Community
    Hi Davez,

    Your post is very helpful, but I'm struggling a bit to get just what I need and hopefully, you can help.

    I am using the import csv plugin and I need it to import a file once every top of the hour. I have created a cron job on my server using wget and it runs without fail at the top of each hour. However, I'm not sure what my setting should be in the Fabrik scheduler to make sure that when the cron job runs, the plugin runs also.

    As a fall back, currently, I have the cron job running every 30 minutes and the scheduler is set to run every 30 minutes. Sometimes the plugin will run with the cron job and other times not. It appears that the Last Run time changes on its own (like 30 min later) and so it does not run with the next cron job. I'm attaching a screenshot of my settings.

    Any ideas what I am doing wrong? Is there a way for a cron job to run the plugin directly bypassing the Scheduler? I am running fully updated Joomal 3.9.15

    Thanks.
     

    Attached Files:

Share This Page