Jump to content

strange error when updating user info


Frank Vèssia
 Share

Recommended Posts

I run a code with lazyCron for sending a newsletter to my users. After sending the newsletter i update a user field with the timestamp.

$lastweek  = strtotime("-1 week");
$last3days = strtotime("-3 days");
$userList = $users->find("userstatus=active,userbanned='',userdeleted='',email!='',id!=40|41,lastlogin<{$lastweek},lastnewsletter<{$last3days},sort=created,limit=5");
foreach($userList as $u){    
            // ...(herecode for sending the newsletter)...
            $u->of(false);
            $u->lastnewsletter = time();
            $u->save();
            $u->of(true);
            saveStats('newsletter');
        }


well, the code lokks ok, but sometimes i got this error:

Error:
Exception: Duplicate entry '10625-0' for key 'PRIMARY' (in /home/public_html/wire/core/Database.php line 118)

the id 10625 is the user. I just update the user page but it seems it's trying to create another user with the same id...!?


any idea?

Link to comment
Share on other sites

Are you sure this is related to that particular block of code? Could it be coming from somewhere else? Does your saveStats() function make any modifications/saves to users or any other pages? Is it always the same user 10625 or different?

Link to comment
Share on other sites

maybe i got it... I recently installed the multi language support, and i noticed all my users don't have the language set. Now i tried to edit a user via PW admin and i got the "error: missing required field..." for the language field. Can be?

edit: not, i still get errors...

Link to comment
Share on other sites

Looking closer at LazyCron within your context, I can see a potential for more than one run of the same interval in high traffic or if the LazyCron jobs take more than a few seconds to run. I've gone ahead and added a second lock file to account for it. Can you try the latest version of LazyCron (just committed to dev branch) and let me know if it makes any difference?



Btw, if your LazyCron jobs take time to execute, you might be better off using regular cron. LazyCron piggybacks on top of user web requests, so it has potential to slow down individual users (when slow tasks execute), whereas regular cron executes separately from the web requests so is not piggypacking on any users. 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...