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

Cron documentation example contains files which I don't have #778

Closed
pantaoran opened this issue Aug 3, 2016 · 21 comments
Closed

Cron documentation example contains files which I don't have #778

pantaoran opened this issue Aug 3, 2016 · 21 comments

Comments

@pantaoran
Copy link

This page:

https://github.com/magento/devdocs/blob/develop/guides/v2.0/config-guide/cli/config-cli-subcommands-cron.md

contains instructions that don't work for me. There are three lines in the example:

* * * * * /usr/bin/php /var/www/magento2/bin/magento cron:run | grep -v "Ran jobs by schedule" >> /var/www/magento2/var/log/magento.cron.log
* * * * * /usr/bin/php /var/www/magento2/update/cron.php >> /var/www/magento2/var/log/update.cron.log
* * * * * /usr/bin/php /var/www/magento2/bin/magento setup:cron:run >> /var/www/magento2/var/log/setup.cron.log

However, for the second line, I don't have a directory {magento2_root}/update.
And for the third line, when I run that, in the log I get setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file.

As my installation method I cloned the Magento2 repository and ran the installer. Is this why the regular instructions don't apply to me? Should this case be added to the documentation?

@ghost ghost self-assigned this Aug 3, 2016
@ghost
Copy link

ghost commented Aug 3, 2016

Thanks for pointing it out. I'll confirm the answer and get back to you ASAP.

magento-cicd2 pushed a commit that referenced this issue Aug 4, 2016
Internal issues #134, 180. Public issue #778. Various improvements to install documentation
@ghost
Copy link

ghost commented Aug 4, 2016

@pantaoran You are correct. I updated the cron documentation here. Please take a look and close this issue if you're happy with the resolution.

@pantaoran
Copy link
Author

Thanks for adding that.

Please note the following quote from my first post:

And for the third line, when I run that, in the log I get setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file.

You didn't address that part. Is that not supposed to happen?

@ghost
Copy link

ghost commented Aug 8, 2016

Would you mind pasting your current crontab and verifying that magento/magento2-base/composer.json exists?

@pantaoran
Copy link
Author

I cannot find any directory called "magento2-base". Isn't this the same reason as the first problem?

@pantaoran
Copy link
Author

pantaoran commented Aug 12, 2016

To be more specific, the following command returns zero hits:

find myMagentoRoot -name "magento2-base" -type d

I now created a module with a crontab.xml that's supposed to execute something every minute, but it never gets executed. My cron job only runs bin/magento cron:run but I guess that is not enough?

How do I get this to work?

To fully answer your previous question, here is my cron command, which runs as the magento user (the variables are filled):

* * * * * cd /src/${PROJECT} && ${PHP} bin/magento cron:run | grep -v 'Ran jobs by schedule.' || true >> var/log/magento.cron.log

@ghost
Copy link

ghost commented Aug 12, 2016

I'll try to answer your questions but please let me know whether or not this helps and I can try to get additional assistance.

If you don't have a magento2-base directory, then the error "Could not locate.." is normal.

Your crontab looks OK although I think you need a second line. Assuming that the environment variable $PHP is defined for the Magento file system user, it should work.

EDIT You also need to run bin/magento setup:cron:run because it's used to enable or disable modules using the Web Setup Wizard.

If your crontab.xml is located in the correct directory, and your module is enabled, it should work. Suggest you use the default group to start because it's easiest. I'm sure you've seen this page already.

Let me know if you have any better results with your custom module and I can look for additional help.

@pantaoran
Copy link
Author

In your EDIT you recommend to also run bin/magento setup:cron:run, but that's exactly what I've been asking about because I don't think this works for me. I first run that command without cron just to see what it does, and its only result is the message setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file.

You said that message was normal if I don't have that folder, but that seems to contradict your insisting on me running bin/magento setup:cron:run.

Anyway, you say that that is necessary to run the Web Setup Wizard which I don't use at all, so maybe I don't actually need it?

The rest of your assumptions are correct. My etc/crontab.xml looks like this (slightly anonymized) and I would expect it to run every minute, but after waiting for several minutes I cannot see the expected log messages (which I do see when I run it manually through a CLI command that I created to call the scheduleUpdate method):

<?xml version="1.0" encoding="UTF-8"?>
<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="custom_update_order_statuses" instance="MyCompany\MyModule\Model\StatusUpdater" method="scheduledUpdate">
            <schedule>* * * * *</schedule>
        </job>
    </group>
</config>

So in summary I still need help because my custom crontab doesn't seem to be working. Your advice at first seems contradictory and didn't really help :-(

@ghost
Copy link

ghost commented Aug 15, 2016

I referred this question to engineering. Meanwhile, if you haven't done so already, you can ask this to a lot bigger audience by posting it on stackoverflow or magento.stackexchange.com.

@shiftedreality
Copy link
Member

shiftedreality commented Aug 15, 2016

Hi @pantaoran

This looks like a bug in the documentation and seems to be already fixed.
In your case (git clone) you will not have /update folder because it's separate repository and is not available for git-cloned version of Magento.

Update: magento/magento2-base is also available only for Composer-based installation.

@ghost
Copy link

ghost commented Aug 15, 2016

@shiftedreality Thank you. Can you provide any guidance to his crontab.xml question?

@ghost
Copy link

ghost commented Aug 15, 2016

@pantaoran Updated the cron setup page to remove the setup cron job for those that cloned GitHub.

@shiftedreality
Copy link
Member

@pantaoran I would like to ask you about few clarifications:

  1. Did you clean cache?
  2. Is your custom module registered in Magento
  3. Are basic cron tasks works fine for you?

@pantaoran
Copy link
Author

Thank you both for confirming that only the first line in crontab should apply and that all cron functionality should still work correctly based on only bin/magento cron:run.

Answers:

  1. As a "contributing developer" as you call it, I am cleaning or even disabling caches extremely frequently.
  2. The module shows as "enabled" in the output of bin/magento module:status if that's what you mean. It also offers its own CLI command to trigger the very thing that I'm trying to automate with cron.
  3. Here I'm not sure because I don't really know what exactly the "basic cron tasks" are. Could you give me some example and tell me how to test that?

@ghost
Copy link

ghost commented Aug 16, 2016

Basic cron tasks are listed here. One of the most common is indexing.

@pantaoran
Copy link
Author

So I turned all indexers from "Update on save" to "Update by schedule". Then I tried to so some action which would require reindexing, but I failed, the indexers are always green.

What I tried are two things: Registering a new customer (which I expected to invalidate the customer grid index) and changing the stock of a product (which I expected to invalidate the Stock index), but like I said they remained green.

Why did these actions not bring the expected results? How can I easily invalidate an index to confirm that cron is running the indexers? Starting to feel really stupid with these questions :-(

@ghost
Copy link

ghost commented Aug 18, 2016

The user guide has a list of actions that should cause reindexing. (Read the entire page.)

Don't worry about it, we'll do what we can to help you.

@pantaoran
Copy link
Author

Alright, @shiftedreality I can now confirm that basic cron tasks seem to work fine. I had an outdated index, and once I scheduled my system's cronjob it took 2min and the index was refreshed.

@ghost
Copy link

ghost commented Oct 16, 2016

Closing, feel free to reopen if you still have questions.

@ghost ghost closed this as completed Oct 16, 2016
@IvanRybakov
Copy link

I've installed Magetnto 2.1.9 via composer.
Cronjob line item like

* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log

In var/log/setup.cron.log I see next messages every minute:

[2017-10-15 09:49:02] setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file. [] [
]
[2017-10-15 09:50:01] setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file. [] [
]
[2017-10-15 09:51:01] setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file. [] [
]

Please advise if I should keep only 1 line in a crontab.

@witmeng
Copy link

witmeng commented Oct 19, 2018

I have the same error. in Magento2.2.6
[2018-10-19 13:55:04] setup-cron.ERROR: Could not locate magento/magento2-base/composer.json file. [] []

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

No branches or pull requests

4 participants