Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppendOutputTo Not working on version 2.2 #309

Closed
SalvadorCastello opened this issue Jul 9, 2020 · 10 comments
Closed

AppendOutputTo Not working on version 2.2 #309

SalvadorCastello opened this issue Jul 9, 2020 · 10 comments
Labels
Milestone

Comments

@SalvadorCastello
Copy link

Crunz version: 2.2

PHP version: 7.2.31

Operating system type and version:
Ubuntu 16.04
Description
After upgrading from Crunz 1.12, tasks stoped writing to log files.

I installed Crunz 2.1 and it is writing log again.

Is there any new configuration to use "AppendOutputTo" ?

Thanks

@PabloKowalczyk
Copy link
Collaborator

Hello,

could you paste code to reproduce the issue?

v2.2 of Crunz introduced LoggerFactoryInterface and this could break something.

@SalvadorCastello
Copy link
Author

This is the file in the "tasks" folder:

run("php index.php batch run 'Used_size calculate'"); $task ->in('/var/www/html/SA/V1') ->daily() ->at('2:00') ->description('Calcula Ocupação de espaço em disco') ->preventOverlapping() ->appendOutputTo('/var/www/html/SA/V1/Batch/logs/3_Used_size.log'); // IMPORTANT: You must return the schedule object return $schedule; In the Definition.php I changed: ->scalarNode('timezone') ->defaultValue('America/Sao_Paulo') ->info('Timezone used to calculate task run date') ->end() My CRON: # CRUNZ * * * * * root cd /var/www/html/SA/V1/Batch && vendor/bin/crunz schedule:run /var/www/html/SA/V1/Batch/tasks If you need more info please let me know. Thanks

@SalvadorCastello
Copy link
Author

Sorry by the previous comment , now I arranged the text ...

This is the file in the "tasks" folder:
'<?php
// TASK/Geração dos Indicadores Dashboard
use Crunz\Schedule;
$schedule = new Schedule();
$task = $schedule->run("php index.php batch run 'Indicadores GeraIndicadores'");
$task
->in('/var/www/html/StartArq/V1')
->everySixHours()
->description('Geração dos Indicadores Dashboard')
->preventOverlapping()
->appendOutputTo('/var/www/html/StartArq/V1/Batch/logs/2_Indicadores.log');
// IMPORTANT: You must return the schedule object
return $schedule;

In the Definition.php I changed:

            ->scalarNode('timezone')
                ->defaultValue('America/Sao_Paulo')
                ->info('Timezone used to calculate task run date')
            ->end()

My CRON:

          • root cd /var/www/html/SA/V1/Batch && vendor/bin/crunz schedule:run /var/www/html/SA/V1/Batch/tasks

If you need more info please let me know. Thanks

@SalvadorCastello
Copy link
Author

Don't mind about the folder 'SA' and 'StartArq' they are the same , I took the job from production and the cron from dev.

@jasonpartyka
Copy link

jasonpartyka commented Jul 9, 2020

We're just using crunz for the first time and ran into this as well. Had to downgrade to 2.1.0 in order to fix. We spent a while tracking down this issue.

We're not doing anything crazy at the moment yet, we were just trying to test out the logging feature to make sure it would work for us.

Here's what we're trying -- our business logic removed, however, for clarity.

$schedule = new Schedule();
$task = $schedule->run('cat foobar.yaml')
  ->daily()
  ->at('02:00')
  ->sendOutputTo('/path/to/file.log')

return $schedule;

@PabloKowalczyk PabloKowalczyk added this to the v2.2 milestone Jul 12, 2020
@PabloKowalczyk
Copy link
Collaborator

I can confirm bug in sendOutputTo and appendOutputTo, will try to fix it soon.

@drjayvee
Copy link
Contributor

@PabloKowalczyk any progress on this?

I'm running v2.3.0 and notice that EventRunner::start() seems strange:

    protected function start(Event $event): void
    {
        $this->logger = $this->loggerFactory
            ->create()
        ;

        // if sendOutputTo or appendOutputTo have been specified
        if (!$event->nullOutput()) {
            // if sendOutputTo then truncate the log file if it exists
            if (!$event->shouldAppendOutput) {
                $f = @\fopen($event->output, 'r+');
                if (false !== $f) {
                    \ftruncate($f, 0);
                    \fclose($f);
                }
            }
            // Create an instance of the Logger specific to the event
            $event->logger = $this->loggerFactory->create();
        }

        $this->consoleLogger
            ->debug("Invoke Event's ping before.");

        $this->pingBefore($event);

        // Running the before-callbacks
        $event->outputStream = ($this->invoke($event->beforeCallbacks()));
        $event->start();
    }

As of 3f7c8f5, $event->logger is not specific to that event at all.

I also can't tell how that would work with the new LoggerFactory.
LoggerFactory::create() doesn't take any parameters to override configuration, so we'd need to create a new LoggerFactory() for this event.

What's more, I don't see how we could do that, since we don't have access to the data necessary data to call LoggerFactory::__construct(ConfigurationInterface, Timezone, ConsoleLoggerInterface, ClockInterface).

@PabloKowalczyk
Copy link
Collaborator

@drjayvee did you saw #346?

@drjayvee
Copy link
Contributor

Sorry, completely missed that one!

@PabloKowalczyk
Copy link
Collaborator

Fixed by #361, thanks @SalvadorCastello.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants