1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cron Job Output different when running manually

Discussion in 'XenForo Development Discussions' started by Marcel, Sep 10, 2015.

  1. Marcel

    Marcel Active Member

    I have a daily cron job that calculates a user's postings in one set of forums over another to work out a ratio.
    There's a daily cron job that runs calculating this, and then writing the resulting integer to the user's profile in a custom field.

    During the automatic run, most users get updated. However some don't. They just don't get recalculated and the profiles updated.
    If I then run the cron job manually it calculates the postcount correctly.

    I can't understand why it would be different if I'm running the cron job manually? Which part would be in question, would it be the actual cron code, the model code, datawriter?

    Here's the relevant part of the cron code (This bit is per user, it's inside a loop)
    $customFields = unserialize($userProfile['custom_fields']);
    $customFields['mab_mod_cr'] = $ratio;
    $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
    $changedFields = array();
    $changedFields['mab_mod_cr'] = array($ratio,$ratio);
    Here's the function in the DataWriter that writes to the profile

    public function writeRatioToProfile($userProfile, $customFields)
    $this->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
    I do have my own custom _preSave in the DataWriter
    protected function _preSave()
    IIRC I had to do that to take out the checks when saving as it was throwing up validation errors.

    Any thoughts?
  2. katsulynx

    katsulynx Well-Known Member

    Depending on how many users and posts there are, could it be that the cron job simply takes too long to be executed and is aborted? Just a thought.
  3. Marcel

    Marcel Active Member

    I don't think so. It always runs successfully and doesn't time out when I run it manually and it's the same amount of users and posts (with only a slight variance). It also runs at 4 to 5 am, the quietest time for our forum.

    Im just wondering if there's something I missed in the code that runs when I run the job manually, that doesn't run when it's automatically executed.
  4. Marcel

    Marcel Active Member

    Nope, it's definitely still not running right. Does anyone have any ideas?
    Thanks :)

    I think I'm missing something in my own code. Something that's automatically called when running the cron job from the Admin Panel. Be it an authentication issue, or a pre or post save, something like that?
    Last edited: Oct 4, 2015

Share This Page