• Atomix

    (@atomixdesign)


    We just switched this plugin over to use Cron, but it looks like the URL loads the homepage rather than outputting the results of the import. If you’re using any kind of Cron monitoring service, it’s impossible to work out whether the import is failing or not (you’ll just get hundreds of lines of HTML either way).

    We were able to fix this by modifying this part of the code:

    
    if (isset($_GET['pull-feeds']) && $_GET['pull-feeds'] == get_option(CSYN_CRON_MAGIC)) {
        if (!is_admin()) {
            require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
            csyn_update_feeds(); // Update the Feeds now instead of waiting for a shutdown hook
            echo "Feeds Updated";
        }
        exit(); // No need to continue after this point
    } else {

    This means we can check if the Cron output is “Feeds Updated”, if not we can assume it failed and trigger an alert (or an automatic retry). If the Cron import is running on the command line, there’s no need to output the homepage.

    It’s a simple change, I’d happily contribute it back as a Pull Request but I don’t think your plugin is on Github. I’ve tested it and it seems to be working, but you’ll probably want to run through your own additional testing before releasing any updates. It’s also up to you what kind of response you want to include.

    If you wanted to have even more fun with it, you could modify your csyn_update_feeds() function to accept “show_report” as an argument, and then the Cron result could include the output. This could even potentially be returned as a JSON array:

    {
    'status': 'success',
    'feeds': [
      {
        'title': 'Feed Name Here',
        'newposts': 15
      }
    }
  • The topic ‘Request – Improve Cron code’ is closed to new replies.