Plugin works in development but not in production


  • Plugin & Theme Dev

    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'); with require('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


  • Plugin & Theme Dev

    @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 callback

    Could you explain a bit more about what seems off? From what I can see, checkConditionAndRewardUser takes an optional callback parameter, but I'm not providing one because this is the last task in the waterfall. If you are referring the the callback parameter the the anonomous function I send for the method parameter of checkConditionAndRewardUser, this should be filled by the checkCondition method that checkConditionAndRewardUser calls with its method parameter as an input. Wow, that's a mouth full


  • GNU/Linux

    @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 callback

    Could you explain a bit more about what seems off? From what I can see, checkConditionAndRewardUser takes an optional callback parameter, but I'm not providing one because this is the last task in the waterfall. If you are referring the the callback parameter the the anonomous function I send for the method parameter of checkConditionAndRewardUser, this should be filled by the checkCondition method that checkConditionAndRewardUser calls with its method parameter as an input. Wow, that's a mouth full

    I guess he wanted to state that the next callback from line 42 is not called at any time.


  • Plugin & Theme Dev

    @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 the next parameter would probably just be null.


  • Global Moderator

    @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.


  • Admin

    What is not working? Did you try testing with mongodb locally?


  • Plugin & Theme Dev

    @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 the action:post.save hook. This hook only provides postData and no callback.


  • Plugin & Theme Dev

    @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.


  • Admin

    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 change user.incrementUserFieldBy(postData.uid, 'reputation', settings.reputationAwardAmount, next); to user.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.


  • Plugin & Theme Dev

    @baris Thanks! You and the rest of the NodeBB team / community rock.


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.