Cron Job Output different when running manually

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)
Code:
$customFields = unserialize($userProfile['custom_fields']);
$customFields['mab_mod_cr'] = $ratio;
$dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
$dw->writeRatioToProfile($userProfile,$customFields);
$changedFields = array();
$changedFields['mab_mod_cr'] = array($ratio,$ratio);
$userModel->logChanges($userId,$changedFields,'1');

Here's the function in the DataWriter that writes to the profile

Code:
public function writeRatioToProfile($userProfile, $customFields)
{
$this->setExistingData($userProfile);
$this->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
$this->setCustomFields($customFields);
$this->rebuildCustomFields();
$this->save();
return;
}

I do have my own custom _preSave in the DataWriter
Code:
protected function _preSave()
{
return;
}

IIRC I had to do that to take out the checks when saving as it was throwing up validation errors.

Any thoughts?
 
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.
 
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.
 
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:
Top Bottom