Home Forums Newsletter Plugin Support Disappearing cron event

Viewing 16 posts - 1 through 16 (of 16 total)
  • Author
    Posts
  • #15739
    szepe.viktor
    Participant

    Good morning!

    wp-cron is run from PHP CLI every half an hour.
    Addidionally the “newsletter” event every 5 minutes from wp-cli:
    /usr/local/bin/wp --quiet --url=http://www.***.hu/ --path=/home/***/public_pm2/server cron event run newsletter

    After one or two days the “newsletter” event disappears. Listing wp-cron events does not show it.
    Where could it be deleted?

    Thank you.

    #15740
    szepe.viktor
    Participant

    When logging into WP as an admin it is recreated.
    Please advise.

    #15741
    Stefano
    Keymaster

    Yes it’s recreated because Newsletter doesn’t find it. Check if wp cli has that event active.

    #15746
    szepe.viktor
    Participant

    > Check if wp cli has that event active.

    What does it mean that wp cli has it event active?

    This simply runs the “newsletter” event.

    wp cron event run "newsletter"

    I do not understand.

    #15749
    Stefano
    Keymaster

    Another user had problem with wp-cli and it told me he forgot to enable the newsletter event. I don’t know how wp cli works, anyway. The event should not disappear. Maybe another plugin is removing it? Try to install wp-control is a small plugin which shows the installed cron.

    #15753
    szepe.viktor
    Participant

    Thank you.
    The thing is wp-cli a WP console tool. It is able to list events.
    See: http://wp-cli.org/commands/cron/event/list/

    Do you have any code in your plugin that removes that event?

    #15758
    Stefano
    Keymaster

    The plugin may remove the event only on deactivation. In the past there were a couple of user having the same problem. Try to check the server error log for php fatal errors or out of memory errors.

    #15761
    szepe.viktor
    Participant

    I only have suhosin alerts (a PHP extension for security) but it is disabled for CLI.
    Do you think a PHP error could remove the event from the database?

    #15763
    Stefano
    Keymaster

    Crons are not on database are runtime rescheduled by plugins. A fatal error while executing a cron or an out of memory can block wordpress to reschedule a periodic cron. Actually only debugging wp while executing a cron can help in finding the problem…

    #15764
    szepe.viktor
    Participant

    I understand.
    Could you make the event fixed. I think it is a more WP-like approach.

    #15788
    Stefano
    Keymaster

    I use the periodic even scheduling of wp, what do you mean with make it fixed?

    #15793
    szepe.viktor
    Participant

    You just mentioned

    Crons are not on database are runtime rescheduled by plugins.

    and I’ve missunderstood as “Crons anre not on database. (period)” But they are.
    Now I understand that WP core fails to reschedule them:

    A fatal error while executing a cron or an out of memory can block wordpress to reschedule a periodic cron.

    Do you mean by “an out of memory can block wordpress to reschedule a periodic cron” that a not-rescheduled cron will disappear from the database?
    I think it will stay sceduled for a time in the past. The entry itself won’t be deleted.

    #15861
    Stefano
    Keymaster

    WordPress put into the database the next time and event (for example “newsletter” should be fired). When it fires it, since the event has a periodicity, it reschedule the event. WP has default intervals available (daily, hourly, …) and Newsletter adds it’s own.

    This information is not on database, when the plugin is active it adds its interval to the list of the intervals listening to a filter. If this interval is not added (maybe activating the cron from “cli” does not let the plugin to load completely (I don’t know), WP may fail to reschedule the event. As far as I know, wordpress tries to guess when to reschedule it even if the interval definition is missing, using some event information… to find out the bug one should log what happens in the wp-cron.php and related function when the event is rescheduled.

    #16328
    szepe.viktor
    Participant

    If someone is loking for a workaround

    
    #!/bin/bash
    #
    # Keep sending newsletters. Restore schedule if missing.
    
    export WP_CLI_CONFIG_PATH="/home/***/public_pm2/wp-cli.yml"
    
    if ! /usr/local/bin/wp --quiet cron event run newsletter \
        && ! /usr/local/bin/wp eval "wp_schedule_event(time() + 5*60, 'newsletter', 'newsletter');"; then
        echo "cron-newsletter ERROR." >&2
        exit 1
    fi
    
    #16329
    szepe.viktor
    Participant

    If someone is looking for a workaround.

    
    #!/bin/bash
    #
    # Keep sending newsletters. Restore schedule if missing.
    
    export WP_CLI_CONFIG_PATH="/home/user/public_pm2/wp-cli.yml"
    
    if ! /usr/local/bin/wp --quiet cron event run newsletter \
        && ! /usr/local/bin/wp eval "wp_schedule_event(time() + 5*60, 'newsletter', 'newsletter');"; then
        echo "cron-newsletter ERROR." >&2
        exit 1
    fi
    
    #16330
    szepe.viktor
    Participant

    My post vanishes.

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.