GithubHelp home page GithubHelp logo

Comments (12)

andrewimm avatar andrewimm commented on July 20, 2024

Is this running in cloud code, or a client?
We need to know more about how you're loading the objects as well. Objects will be re-created on the db if the objects you save don't have objectIds set on them, which can happen if you're improperly inflating the objects.

In general, we prioritize issues that have a reproducible test case. If you can write up a small block of code that causes this to happen, we can debug it; otherwise, it could be due to any variety of reasons that we don't have insight into.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

Thank you for your feedback. We prioritize issues that have clear and concise repro steps. Please see our Bug Reporting Guidelines about what information should be added to this issue.

Please try the latest SDK. Our release notes have details about what issues were fixed in each release.

In addition, you might find the following resources helpful:

from parse-sdk-js.

dennito avatar dennito commented on July 20, 2024

Yes, it's running on Cloud Code. See below the complete code.

// These two lines are required to initialize Express in Cloud Code.
 express = require('express');
 app = express();

// Global app configuration section
app.set('views', 'cloud/views');  // Specify the folder to find templates
app.set('view engine', 'ejs');    // Set the template engine
app.use(express.bodyParser());    // Middleware for reading request body

app.post('/mandrill-webhook', function(req, res){
var events = JSON.parse(req.body.mandrill_events);

var query = new Parse.Query("Vouchercode");
query.notEqualTo("sent", true);
query.equalTo("email", null);
query.limit(events.length);
query.find().then(function(codes){

    if (codes.length == 0){
        return Parse.Promise.as("No codes left");
    }

    console.log(events.length);
    for (var i=0; i<events.length; i++){

        var msg = events[i].msg;
        var email = msg.email;
        var template = msg.template;
        console.log(email);



        codes[i].set("email", email);



    }

    return Parse.Object.saveAll(codes);

}).then(function(codes){
    console.log("Code vergeben!");
    res.send(200);

}, function(error){
    console.log(error.message);
    res.send(500);
});

});

Parse.Cloud.job("sendMail", function(req, status){
    Parse.Cloud.useMasterKey();
    var emails = [];
    var codes = null;
    var query = new Parse.Query("Vouchercode");
    query.notEqualTo("sent", true);
    query.notEqualTo("email", null);
    query.limit(50);
    query.find().then(function(codesTmp){
     codes = codesTmp;

    console.log(codes.length);
    if (codes.length == 0){
        return Parse.Promise.error("No codes left");
    }

    var mergeVars = [];
    var subscribers = [];

    for (var i=0; i<codes.length; i++){
        var mv = {rcpt: codes[i].get("email"), vars: [{name: "code", content: codes[i].get("code")}]};
        var s = { email: codes[i].get("email"), name: null };
        mergeVars.push(mv);
        subscribers.push(s);
    }

    var message = {
        to: subscribers,
        //subject: subject,
        //merge_language: "handlebars",
        merge_vars: mergeVars
    };

    //console.log(subscribers);
    //console.log(JSON.stringify(codes));

    return Parse.Cloud.httpRequest({
        method: 'POST',
        headers: {
            'Content-Type': 'application/json; charset=utf-8'
        },
        url: 'https://mandrillapp.com/api/1.0/messages/send-template.json',
        body: {
            template_name: "some-template",
            template_content: null,
            key: "some-key",
            message: message,
            async: false
        }});

}).then(function(response){
    var response = JSON.parse(response.text);
    console.log(response);
    if (response[0].status == "sent" || response[0].status == "queued"){
        console.log("YEP - IS SENT");
        for (var i=0; i<codes.length; i++){
            codes[i].set("sent", true);
        }
    }

    return Parse.Object.destroyAll(codes);

}, function(response){
    //var response = JSON.parse(response.text);
    //console.log(response);
    //status.error(response);
    return Parse.Promise.error("No codes left");
}).then(function(){
    status.success("success!");
}, function(error){
    //console.log(error.message);

    //console.log(JSON.stringify(error));
    status.error(error);
});

});


// Attach the Express app to Cloud Code.
app.listen();

from parse-sdk-js.

dennito avatar dennito commented on July 20, 2024

The issue must be in the job. So you can ignore the other stuff.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

We are closing this issue due to another 7 days of inactivity. If you have additional information to help pinpoint this issue as an SDK bug, please reopen it with the additional information.Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

We are closing this issue due to another 7 days of inactivity. If you have additional information to help pinpoint this issue as an SDK bug, please reopen it with the additional information.Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

We are closing this issue due to another 7 days of inactivity. If you have additional information to help pinpoint this issue as an SDK bug, please reopen it with the additional information.Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

This issue has not been updated for 7 days. If you have additional information to help pinpoint this issue as an SDK bug, please comment on this issue. We will close this issue in 7 days if no additional information is provided. Thank you for your feedback.

from parse-sdk-js.

parse-github-bot avatar parse-github-bot commented on July 20, 2024

We are closing this issue due to another 7 days of inactivity. If you have additional information to help pinpoint this issue as an SDK bug, please reopen it with the additional information.Thank you for your feedback.

from parse-sdk-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.