Recurring invoices failing under Cron with Docker Container version 2.7.2

Hi All,

I have recently upgraded a Docker container image to 2.7.2.

This system has 4 recurring invoices and the system has created a draft of the first recurring invoice for this month.

The CRON container log shows the following:

2016-10-13 Running SendRecurringInvoices...
4 recurring invoice(s) found
Processing Invoice 6 - Should send YES
Sending Invoice

  Trying to get property of non-object

2016-10-13 Running SendReminders...
0 accounts found

So, any clues on how I can resolve this?

All 4 recurring invoices have been sent before manually. This is the first time CRON has been enabled & ready to send on the Docker version. Note, it was active previously when I had 2.7.1 installed and the log had shown that invoices were not yet due to be sent. Send date is 9th of the month.

Can you check storage/logs/laravel-error.log for more details.

Hi Hillel,

Here’s the error-log from the CRON container…

[2016-10-13 06:49:55] production.ERROR: Cache for currencies is not set  {"context":"PHP","user_id":0,"account_id":0,"user_name":"","method":"GET","url":"http://localhost","user_agent":"","ip":"","count":1} []

[2016-10-13 06:49:55] production.ERROR: ErrorException: Trying to get property of non-object in /var/www/app/app/Libraries/Utils.php:370 Stack trace: #0 /var/www/app/app/Libraries/Utils.php(370): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Trying to get p...', '/var/www/app/ap...', 370, Array) #1 /var/www/app/app/Models/Account.php(461): App\Libraries\Utils::formatMoney(60.5, 12, 36, false) #2 /var/www/app/app/Services/TemplateService.php(51): App\Models\Account->formatMoney('60.50', Object(App\Models\Client)) #3 /var/www/app/app/Ninja/Mailers/ContactMailer.php(191): App\Services\TemplateService->processVariables('<div>$client,</...', Array) #4 /var/www/app/app/Ninja/Mailers/ContactMailer.php(110): App\Ninja\Mailers\ContactMailer->sendInvitation(Object(App\Models\Invitation), Object(App\Models\Invoice), '<div>$client,</...', 'New invoice $in...', false, Array) #5 /var/www/app/app/Console/Commands/SendRecurringInvoices.php(79): App\Ninja\Mailers\ContactMailer->sendInvoice(Object(App\Models\Invoice)) #6 [internal function]: App\Console\Commands\SendRecurringInvoices->fire() #7 /var/www/app/bootstrap/cache/compiled.php(1257): call_user_func_array(Array, Array) #8 /var/www/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call(Array) #9 /var/www/app/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #10 /var/www/app/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #11 /var/www/app/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #12 /var/www/app/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\SendRecurringInvoices), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #13 /var/www/app/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #14 /var/www/app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #15 /var/www/app/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #16 {main} [] []

There a currency set in SETTINGs…

Let me know, thanks.

Not sure why the cache would’t be set. You can try adding ?clear_cache=true to the end of the URL to force the app to populate the cache.

Hi Hillel,

I did that via the browser but not sure if it will work since the CRON container is a separate container to APP container… not sure how to do the equivalent on CRON??

I stopped and restarted all containers to re-trigger CRON… checked the laravel-error log and the same messages have been added to existing.


Can you run them in the same container, it’s possible it’s related to the problem.

Umh… no. The CRON image is not exposing anything. Here’s the Docker Setup from Lalop.

  image: invoiceninja/invoiceninja
    - db:mysql
  user: www-data
  entrypoint: |
    bash -c 'bash -s <<EOF
    trap "break;exit" SIGHUP SIGINT SIGTERM
    sleep 30s
    while /bin/true; do
      DB_USERNAME=root DB_PASSWORD=mdp /usr/local/bin/php /var/www/app/artisan ninja:send-invoices
      DB_USERNAME=root DB_PASSWORD=mdp /usr/local/bin/php /var/www/app/artisan ninja:send-reminders
      sleep 1d

I can log into the container via BASH and do it via command line? Is there a command to clear cache?

There isn’t a command line method.

The app should automatically populate the cache, I’m not sure why it’s failing.

Hmm, not sure… i can tell you since i’ve started it 3 times now, it’s created 3 of the recurring invoices. All with status DRAFT instead of sent…

Ahhhh… I just had an idea…

The ENV file!! Remember how I said the main app would not work after the 2.7.1 update because it was wiping the ENV file and I had to move the ENV to persistent storage… since the CRON container is running independently, it does not see the ENV…the persistent storage volumes I used for the app were not copied to the CRON container… I didn’t know it needed it…I didn’t realise until now it was independent…

So… adding the APP volumes to the CRON container…

Voila… fixed!!

The 3 invoices in draft mode remained in DRAFT… I sent them manually but the fourth was created and sent automatically…

Things we learn… hopefully that helps someone else.

All makes sense now… maybe the code that checks to see if the invoice should be sent also checks if the status is sent rather than leaving them stuck in DRAFT status… mind you it should not happen if correctly configured.

Thanks for your help Hillel.

Thanks @inhv for the hint!

My working docker-compose.yml file:

Maybe it helps someone.