Plugin works in development but not in production
-
First of all, use your own version of the async library. It's bad practice to depend on someone else's dependencies. So replace
module.parent.require('async');
withrequire('async');
.Thanks. Will do
Make sure your local and server instances are on the same commit.
Definitely on the same commit.
Check for any errors in the logs.
Done. I didn't see any issues
-
@baris said in Plugin works in development but not in production:
Something looks wrong here https://github.com/myvr/nodebb-plugin-reputation-for-posting/blob/master/library.js#L42-L45.
checkConditionAndRewardUser
does not send back a callbackCould you explain a bit more about what seems off? From what I can see,
checkConditionAndRewardUser
takes an optionalcallback
parameter, but I'm not providing one because this is the last task in the waterfall. If you are referring the thecallback
parameter the the anonomous function I send for themethod
parameter ofcheckConditionAndRewardUser
, this should be filled by thecheckCondition
method thatcheckConditionAndRewardUser
calls with itsmethod
parameter as an input. Wow, that's a mouth full -
@deiden26 said in Plugin works in development but not in production:
@baris said in Plugin works in development but not in production:
Something looks wrong here https://github.com/myvr/nodebb-plugin-reputation-for-posting/blob/master/library.js#L42-L45.
checkConditionAndRewardUser
does not send back a callbackCould you explain a bit more about what seems off? From what I can see,
checkConditionAndRewardUser
takes an optionalcallback
parameter, but I'm not providing one because this is the last task in the waterfall. If you are referring the thecallback
parameter the the anonomous function I send for themethod
parameter ofcheckConditionAndRewardUser
, this should be filled by thecheckCondition
method thatcheckConditionAndRewardUser
calls with itsmethod
parameter as an input. Wow, that's a mouth fullI guess he wanted to state that the
next
callback from line 42 is not called at any time. -
@frissdiegurke said in Plugin works in development but not in production:
I guess he wanted to state that the
next
callback from line 42 is not called at any time.Ah. Thank you. Do you think this might cause an issue? I figured that because I am not providing a final callback for
async.waterfall
thenext
parameter would probably just benull
. -
@deiden26 without calling the callback, NodeBB had no idea when you've finished your task. So until you call that callback, the value is indeterminate.
Edit: you just need to add the callback parameter to your function, and then add it as an argument to the waterfall.
-
@PitaJ said in Plugin works in development but not in production:
@deiden26 without calling the callback, NodeBB had no idea when you've finished your task. So until you call that callback, the value is indeterminate.
Edit: you just need to add the callback parameter to your function, and then add it as an argument to the waterfall.
Are you suggesting that this line
plugin.awardReputation = function(postData)
should have a callback parameter, like this
plugin.awardReputation = function(postData, callback)
and that my waterfall should end in
], callback);
?
That doesn't seem right to me, because the
awardReputation
function is being called for theaction:post.save
hook. This hook only provides postData and no callback. -
@baris said in Plugin works in development but not in production:
What is not working? Did you try testing with mongodb locally?
Sorry for not being more clear. No reputation is being awarded for each post in production. Reputation is being awarded for each post locally. I haven't tried using mongodb locally, but that's the next step.
-
Ok I figured out this was a problem in the mongodb layer, with redis when you pass in a string as the increment value it is automatically converted to an int. With mongodb this was throwing an error
Uncaught AssertionError: { [MongoError: Cannot increment with non-numeric argument: {value: "11"}]
.This is fixed in https://github.com/NodeBB/NodeBB/commit/cd9e2d17a37fc19639b31c4ea4e06d14b2730cbe
You can also avoid it by just using
parseInt()
before sending the value to incrObjectFieldBy. So just changeuser.incrementUserFieldBy(postData.uid, 'reputation', settings.reputationAwardAmount, next);
touser.incrementUserFieldBy(postData.uid, 'reputation', parseInt(settings.reputationAwardAmount, 10), next);
As for that entire method, this is how I would write it. Fixing the issue I mentioned above.
plugin.awardReputation = function(postData) { async.waterfall([ function(next){ meta.settings.get('reputation-for-posting', next); }, function(settings, next) { user.incrementUserFieldBy( postData.uid, 'reputation', parseInt(settings.reputationAwardAmount, 10), next ); }, function(newreputation, next) { db.sortedSetAdd('users:reputation', newreputation, postData.uid, next); }, function(next) { rewards.checkConditionAndRewardUser(postData.uid, 'essentials/user.reputation', function(callback) { user.getUserField(postData.uid, 'reputation', callback); }, next); } ], functon(err) { if (err) { winston.error(err); } }); };
So that all errors are logged properly, in your case mongodb was sending the error but it was just ignored.