cron doesn't run

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

cron doesn't run

Post by MarkDHamill » Thu May 23, 2019 9:41 pm

Here's my services.yml file:

Code: Select all

imports:
    - { resource: parameters.yml }
services:
    phpbbservices.filterbycountry.listener:
        class: phpbbservices\filterbycountry\event\main_listener
        arguments:
            - '@language'
            - '@request'
            - '%core.root_path%'
            - '%core.php_ext%'
            - '@config'
            - '@log'
            - '@user'
        tags:
            - { name: event.listener }
    phpbbservices.filterbycountry.common:
        class: phpbbservices\filterbycountry\core\common
        arguments:
            - '@language'
            - '%core.root_path%'
            - '@config'
            - '@log'
    phpbbservices.filterbycountry.controller.acp:
        class: phpbbservices\filterbycountry\controller\acp_controller
        arguments:
            - '@config'
            - '@language'
            - '@log'
            - '@request'
            - '@template'
            - '@user'
    phpbbservices.filterbycountry.service:
        class: phpbbservices\filterbycountry\service
        arguments:
            - '@user'
            - '%phpbbservices.filterbycountry.tables.filterbycountry_table%'
    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '%core.root_path%'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [cron.task.cron_task]]
        tags:
            - { name: cron.task }
and my cron program in /cron/task/update_country_database.php:

Code: Select all

<?php
/**
 *
 * Filter by country. An extension for the phpBB Forum Software package.
 *
 * @copyright (c) 2019, Mark D. Hamill, https://www.phpbbservices.com
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 */
namespace phpbbservices\filterbycountry\cron\task;

class update_country_database extends \phpbb\cron\task\base
{

	protected $config;
	protected $phpbb_root_path;
	protected $helper;
	protected $phpbb_log;

	/**
	 * Constructor.
	 *
	 * @param \phpbb\config\config 							$config 	The config
	 * @param $phpbb_root_path								$string		Relative path to phpBB root
	 * @param \phpbbservices\filterbycountry\core\common 	$helper		Extension's helper object
	 * @param \phpbb\log\log 								$phpbb_log 	phpBB log object
	 */

	public function __construct(\phpbb\config\config $config, $phpbb_root_path, \phpbbservices\filterbycountry\core\common $helper, \phpbb\log\log $phpbb_log)
	{

		$this->config = $config;
		$this->phpbb_root_path = $phpbb_root_path;
		$this->helper = $helper;
		$this->phpbb_log = $phpbb_log;

	}

	/**
	 * Indicates to phpBB's cron utility if this task should be run.
	 *
	 * @return true if it should be run, false if it should not be run.
	 */

	public function should_run()
	{
		// The Maxmind country database is updated weekly on Tuesdays. For our purposes, we'll assume a fresh database exists on Wednesdays.
		// So to update the database, it must be on or after Wednesday and at least 7 days must have elapsed since the database was last updated.

		$todays_dow = date('w');	// 0 = Sunday, 6 = Saturday
		$days_since_last_wednesday = (int) (4 + $todays_dow);

		$debug_string = 'Todays DOW = ' . $todays_dow . ' Days since last Wednesday = ' . $days_since_last_wednesday;

		// Debugging
		$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_FBC_DEBUG', false, array('Debugging: ' . $debug_string . ' - ' . (bool) ($days_since_last_wednesday >= 7)));

		return (bool) ($days_since_last_wednesday >= 7);
	}

	public function run()
	{

		// Updates the MaxMind country database via a cron

		// Destroy current database, then download, ungzip, untar and stage an updated database.
		// Debugging
		$this->phpbb_log->add('admin', $this->user->data['user_id'], $this->user->ip, 'LOG_ACP_FBC_DEBUG', false, array('run() function attempted.'));
		$this->helper->download_maxmind(true);
		return true;

	}

}
To figure this out as you can see I write to the log. The should_run() function writes well enough to the log. I get log entries like this:
Debugging: Todays DOW = 4 Days since last Wednesday = 8 - 1
with the - 1 at the end telling me that the function is returning true.

But clearly run() is not getting executed because it's not getting trapped in the log.

I've installed the Check Cron Status extension and it doesn't show up in the list of crons.
Cron Status.png
Any ideas?

Note: system cron is disabled. The way I've tested this in the past is to go to the index. Sometimes I have to log out and in to get the cron going.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1047
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: cron doesn't run

Post by mrgoldy » Fri May 24, 2019 2:54 pm

You have the following:

Code: Select all

calls:
    - [set_name, [cron.task.cron_task]]
Which I believe has to be:

Code: Select all

calls:
    - [set_name, ['phpbbservices.filterbycountry.cron.task.cron_task']]
phpBB Studio / ''Proud member of the Studio"

User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: cron doesn't run

Post by MarkDHamill » Fri May 24, 2019 3:38 pm

Thanks for the suggestion. Unfortunately, it didn't work. Not sure what set_name has to do with this and how it is used.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
3Di
Former Team Member
Posts: 13773
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: cron doesn't run

Post by 3Di » Fri May 24, 2019 5:14 pm

Will be hard it can be executed if it has no reference to the two configurations needed.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: cron doesn't run

Post by MarkDHamill » Fri May 24, 2019 5:49 pm

3Di, is there something I am missing?
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
AbaddonOrmuz
Registered User
Posts: 621
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: cron doesn't run

Post by AbaddonOrmuz » Fri May 24, 2019 6:36 pm

I'm pretty sure it needs to set the right cron task name for it to work. At least I have something like this in the cron task from my Auto-lock topics extension.

Code: Select all

    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '%core.root_path%'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [cron.task.update_country_database]]
        tags:
            - { name: cron.task }
You could debug if it's actually working by commenting the following line in cron.php

Code: Select all

output_image();
And visiting the URL:

Code: Select all

http://example.com/cron.php?cron_type=cron.task.update_country_database
Some of my phpBB extensions: [ Imgur | SEO Metadata | Markdown ]
Check out all my extensions
Arch Linux user

User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: cron doesn't run

Post by MarkDHamill » Fri May 24, 2019 7:57 pm

Thanks for the suggestions. I changed services.yml as follows:

Code: Select all

    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '%core.root_path%'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [phpbbservices.filterbycountry.update_country_database]]
        tags:
            - { name: cron.task }
Commenting out the image in cron.php and using the suggested URL:

http://127.0.0.1/phpbb/cron_type=cron.t ... y_database

does render:
The requested page could not be found.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
AbaddonOrmuz
Registered User
Posts: 621
Joined: Wed Dec 25, 2013 9:06 pm
Location: /dev/null
Name: Alfredo Ramos
Contact:

Re: cron doesn't run

Post by AbaddonOrmuz » Fri May 24, 2019 8:01 pm

The URL is wrong, it should be:

Code: Select all

http://127.0.0.1/phpbb/cron.php?cron_type=cron.task.update_country_database
Some of my phpBB extensions: [ Imgur | SEO Metadata | Markdown ]
Check out all my extensions
Arch Linux user

User avatar
3Di
Former Team Member
Posts: 13773
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: cron doesn't run

Post by 3Di » Fri May 24, 2019 8:04 pm

set_name is wrong, see the above suggestion..
prepend cron.task and remove vendor.ext
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: cron doesn't run

Post by MarkDHamill » Fri May 24, 2019 8:12 pm

Thanks for the suggestions. Relevant part of services.yml is now:

Code: Select all

    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '%core.root_path%'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [update_country_database]]
        tags:
            - { name: cron.task }
Commenting out output_image(); in cron.php and using http://127.0.0.1/phpbb/cron.php?cron_ty ... y_database renders a blank page.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
3Di
Former Team Member
Posts: 13773
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: cron doesn't run

Post by 3Di » Fri May 24, 2019 8:21 pm

3Di wrote:
Fri May 24, 2019 8:04 pm
set_name is wrong, see the above suggestion..
prepend cron.task and remove vendor.ext
- [set_name, [cron.task.update_country_database]]
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: cron doesn't run

Post by MarkDHamill » Fri May 24, 2019 8:40 pm

Thank you, 3Di. This time I got the proper debug message in my error log:
run() function attempted.
Originally, services.yml was:

Code: Select all

    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '%core.root_path%'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [cron.task.cron_task]]
        tags:
            - { name: cron.task }
and now is:

Code: Select all

    phpbbservices.filterbycountry.cron.task.cron_task:
        class: phpbbservices\filterbycountry\cron\task\update_country_database
        arguments:
            - '@config'
            - '%core.root_path%'
            - '@phpbbservices.filterbycountry.common'
            - '@log'
        calls:
            - [set_name, [cron.task.update_country_database]]
        tags:
            - { name: cron.task }
So it looks like changing to update_country_database is what I needed to do. It is kind of strange though because for my digests extension I use:

Code: Select all

        calls:
- [set_name, [cron.task.cron_task]]
which calls /cron/task/digests.php and it worked. I'm guessing it has something to do with the cron program name being different than the extension name.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
3Di
Former Team Member
Posts: 13773
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: cron doesn't run

Post by 3Di » Fri May 24, 2019 8:52 pm

Seems like the digests' one is wrong IMO.

Still, you are using the config service - '@config but's unused.
You should code a migration with 2 configurations and use them with should_run() and run() instead of a custom timelapse.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
MarkDHamill
Registered User
Posts: 3805
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: cron doesn't run

Post by MarkDHamill » Fri May 24, 2019 8:57 pm

Right you are. They were used at one point but the code was since simplified. I would have removed this and '%core.root_path%' at some point during clean up.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

Post Reply

Return to “Extension Writers Discussion”

cron