1

crontab.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
    <group id="default">
        <job name="test_product_import" instance="Test\ImportExport\Cron\ProductImport" method="execute">
            <schedule>* * * * *</schedule>
        </job>
    </group>
</config>

Php File that gets called by cron:

<?php

namespace Test\ImportExport\Cron;

class ProductImport
{
    protected $trace;

    public function __construct(
        \Test\Core\Model\Trace $trace
    )
    {
        $this->trace = $trace;
    }

    public function execute()
    {
        $this->trace->writeTrace("Test");
    }
}

Error message in cron_schedule table :

Warning: fopen(app/code/Test/Trace.txt): failed to open stream: No such file or directory in /var/www/www.example.com/app/code/Test/Core/Model/Trace.php on line 12

On line 12 in this file:

$tracelog = fopen("app/code/Test/Trace.txt", "a") or die("Unable to open file!");

In SSH I executed

php magento cron:run

and I got the error. Since I assume a permission problem I tried

sudo -u www-data php magento cron:run

same issue. What's wrong?

0

I was able to solve it.

$tracelog = fopen("app/code/Test/Trace.txt", "a") or die("Unable to open file!");

I had to specify the absolute path to the file instead of the relative as shown above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.