Fixed Schedule task problem

dimoss

Well-Known Member
Hi,

it has been reported in the past: https://fabrikar.com/forums/index.php?threads/problem-fabrik-scheduled-tasks.54184/ by @bonghetti

I encounter the same problem with php plugin enabled and the code directly in the PHP code section as below:

PHP:
use Joomla\CMS\Factory;
$db = \Joomla\CMS\Factory::getContainer()->get('DatabaseDriver');
$config = Factory::getConfig();
$queryString = "SELECT GROUP_CONCAT(CONCAT(name, ' - #', player_id) ORDER BY name ASC SEPARATOR '\n') AS combined_name, assoc, email FROM vw_expired_passports WHERE assoc REGEXP '^[M-Z]' GROUP by assoc";
$db->setQuery($queryString);
$rows = $db->loadAssocList();

$successCount = 0;
$failureCount = 0;

foreach ($rows as $row) {
    $playerName = $row['combined_name'];
    $playerAssoc = $row['assoc'];
    $playerEmail = $row['email'];
   
    $to = $playerEmail;
    $subject = "xxx";
    $msg = "xxx"";

    $res = FabrikWorker::sendMail(
        $config->get('mailfrom'),
        $config->get('fromname'),
        $to,
        $subject,
        $msg
    );

    if ($res) {
        $successCount++;
    } else {
        $failureCount++;
    }
}

// Send email notification
$notificationSubject = "xxx";
$notificationMessage = "Emails sent successfully: $successCount\nEmails failed: $failureCount";

$notificationRes = FabrikWorker::sendMail(
    $config->get('mailfrom'),
    $config->get('fromname'),
    "xxx@xxx.com",  // Specify your email address here
    $notificationSubject,
    $notificationMessage
);

if ($notificationRes) {
    echo "Notification email sent successfully.<br>";
} else {
    echo "Failed to send notification email.<br>";
}

Require querystring is set to YES with a secret word. I tried with wget from my server and from webcron.org. Doesnt work from both. No email send and no log is recorded on #__fabrik_log. Time frequency tested with 1 muinute and 1 hour but nothing changed.

If I run it from the backend clicking the run button it works as expected and send the emails correctly.

I have latest Fabrik and Joomla version and PHP 8.1.x

Any idea is very much welcome.
Thanks.
 
Echo something in a cron won't help.

Is it working without require querystring? (You may comment out the emailing to users for testing).

Is this really your complete code? This query won't do.
Try step by step starting with the notification email only. This part of your code is working on my site.

BTW: You can test the "frontend" cron with querystring just by calling any frontend I! site and appending &fabrik_cron=1 (resp ?fabrik_cron=1)
 
Last edited:
Echo something in a cron won't help.

Is it working without require querystring? (You may comment out the emailing to users for testing).

Is this really your complete code? This query won't do.
Try step by step starting with the notification email only. This part of your code is working on my site.

BTW: You can test the "frontend" cron with querystring just by calling any frontend I! site and appending &fabrik_cron=1 (resp ?fabrik_cron=1)
Hi @troester

The query works fine. I have tested it as is and returns the result I want. This is the complete code.
I haven't tested it without Require Querystring.
 
Hi again,

without Require Querystring works fine. I followed your advise and removed the emailing to users and kept only the notification email.
I changed to 1 minute and started to receive notification emails.
Although i have Log Events enabled nothing recorded in the #___fabric_logs
 
Something is definitely wrong.

Setting Require querystring is set to YES leaving the Query Secret to nothing and setting the webcron.org to run the https://mysite.com/index.php?fabrik_cron=1 does nothing.

It doesnt work even if I run the link from the browser.

Putting Require querystring is set to NO works but it runs repeatedly (eg. frequency 5 min)
 
Last edited:
With Require Querystring = no the cron is triggered by every frontend activity (any guest etc) and running if the frequency was over, so webcron isn't relevant in this case.

Running webcron or using the browser link manually should be identical.

Can you try to set Query secret a.g. abc, require = yes and run
https://mysite.com/index.php?fabrik_cron=abc
(it shouldn't make a difference, but you never know...)

SEF on/ SEF off...

Did you define a (dummy) list in the plugin settings? Is this list public accessible?

I tried different settings on my site but all is working...
 
I dont know if this is related but i noticed when I set Require Querystring = YES regardless if I set a Quert secret or not, the last run date/time changing without the cron runs according to the frequence i have set. So for example if i set 1 minute it will change accordingly. This way how is possible to have overdue to run the schedule task?

I haven't put any list in the plugin settings because as per the WiKi is optional. I tried with dummy list, didnt work.

SEF is on but no URL rewrite.

I tried with `abc` as suggested but didnt work as expected.

I think the issue is on Require Querystring. I dont know whatelse to do.
 
Last edited:
I think this is it. It seems it's setting the last run time as soon as it's triggered, not after it has run. On my test site there's no 'public' frontend activity so I didn't realize.
 
I think this is it. It seems it's setting the last run time as soon as it's triggered, not after it has run. On my test site there's no 'public' frontend activity so I didn't realize.
The activity on my site is quite frequent :)
 
Can you try in \plugins\system\fabrikcron\fabrikcron.php line 123ff

Code:
    public function shutdownHandler()
    {
        if (@is_array($e = @error_get_last())) {
            $code = isset($e['type']) ? $e['type'] : 0;
            $msg = isset($e['message']) ? $e['message'] : '';
            $file = isset($e['file']) ? $e['file'] : '';
            $line = isset($e['line']) ? $e['line'] : '';

            if ($code == 1) {
                $this->log->message = "$code,$msg,$file,$line";
                $this->log->store();
                $this->reschedule();
            }
        }
    }

So only log and reschedule in case of fatal errors, not in case of any error.
 
Can you try in \plugins\system\fabrikcron\fabrikcron.php line 123ff

Code:
    public function shutdownHandler()
    {
        if (@is_array($e = @error_get_last())) {
            $code = isset($e['type']) ? $e['type'] : 0;
            $msg = isset($e['message']) ? $e['message'] : '';
            $file = isset($e['file']) ? $e['file'] : '';
            $line = isset($e['line']) ? $e['line'] : '';

            if ($code == 1) {
                $this->log->message = "$code,$msg,$file,$line";
                $this->log->store();
                $this->reschedule();
            }
        }
    }

So only log and reschedule in case of fatal errors, not in case of any error.
That's it! Now works as expected with Require Querystring = YES and Query secret = anything via webcron. I will try adding a cron task to my server to confirm also with wget.

Thanks a lot @troester
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top