Frank Vèssia Posted November 9, 2013 Share Posted November 9, 2013 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 More sharing options...
ryan Posted November 9, 2013 Share Posted November 9, 2013 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 More sharing options...
Frank Vèssia Posted November 9, 2013 Author Share Posted November 9, 2013 The errors started when i uploaded this code, saveStats just perfoms a database update on a table not managed by PW. the user 10625 it's just an example, every time is different... Link to comment Share on other sites More sharing options...
Frank Vèssia Posted November 9, 2013 Author Share Posted November 9, 2013 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 More sharing options...
Frank Vèssia Posted November 9, 2013 Author Share Posted November 9, 2013 I changed the interval of LazyCron from eveyMinute to every4Minutes, it looks i don't get any errors now...i have several connected users, can be this the cause, LazyCron called multiple times at the same moment? Link to comment Share on other sites More sharing options...
ryan Posted November 11, 2013 Share Posted November 11, 2013 LazyCron – I bet you are right and that's it. Though LazyCron shouldn't get called multiple times for the same maintenance. What scale of traffic are you serving there? 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted November 11, 2013 Author Share Posted November 11, 2013 Well, i have always between 20-60 connected users, posting stuff, sending private messages, commenting etc, around 4-5k unique per day. Link to comment Share on other sites More sharing options...
ryan Posted November 14, 2013 Share Posted November 14, 2013 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. 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted November 18, 2013 Author Share Posted November 18, 2013 Just read the message, I'll try with the new module, btw i'm using regular cron right now 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now