parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Cloud job update objects works sometimes

Open devKC opened this issue 9 years ago • 3 comments

We use GitHub Issues for bugs.

If you have a non-bug question, ask on Stack Overflow or Server Fault:

  • https://stackoverflow.com/questions/tagged/parse.com
  • https://serverfault.com/tags/parse

You may also search through existing issues before opening a new one: https://github.com/ParsePlatform/Parse-Server/issues?utf8=%E2%9C%93&q=is%3Aissue

--- Please use this template. If you don't use this template, your issue may be closed without comment. ---

Issue Description

Describe your issue in as much detail as possible.

I am running a cloud job from the dashboard to test whether the cloud job works or not. I am querying for records in a Class and making updates to retrieved records. The problem is the job always reports "success" status but only sometimes will the records update.

Please include a detailed list of steps that reproduce the issue. Include curl commands when applicable.

Run the following code via Parse Dashboard Jobs

Parse.Cloud.job(“example”, function(request, status) {
  var params = request.params;
  var headers = request.headers;

  // get the parse-server logger
  var log = request.log;

// Update the Job status message
  status.message(“start”);
  var _ = require('underscore');
  var query = new Parse.Query(“objectClass”);
  query.equalTo(“look”, true);
  query.equalTo(“view”, true);
  query.include("pointer”);
  query.find().then(function(results) {
  	var promise = Parse.Promise.as();
  	_.each(results, function(result) {

  		result.set(“look”, false);

  		promise = promise.then(function() {

  					return result.save(null, { useMasterKey: true }).then(function() {

				}, function(error) {
					status.error(error)
				});
  				});

  	});

  	//status.success("hi!");
  	return promise;

  }).then(function() {

  	status.success(“success”);

  }, function(error) {
  // there was some error.
  	status.error(“error”);
  });

What you expected to happen.

I expect all records that are retrieved (where look and view = true) to update "look" value to "false". The verbose logs show that look=false, but the db itself is showing the value as true.

What is happening instead.

Sometimes this update is made in the db, sometimes it's not. No change in code.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : [2.4.0]
    • Operating System: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): [Heroku]
  • Database

    • MongoDB version: [3.2.11]
    • Storage engine: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): [mLab]

Logs/Trace

Include all relevant logs. You can turn on additional logging by configuring VERBOSE=1 in your environment.

verbose: REQUEST for [GET] /parse/classes/objectClass: {  "where": {    “look”: true,  “view”: true   },  "include": "pointer" 
 } method=GET, url=/parse/classes/objectClass, host=xxxxxxxxxxxxxx, connection=close, user-agent=node-XMLHttpRequest, Parse/js1.9.2 (NodeJS 6.10.0), accept=/, content-type=text/plain, x-request-id=xxxxxxxxxxxx, x-forwarded-for=xxxxxxxxxxx, x-forwarded-proto=https, x-forwarded-port=443, via=1.1 vegur, connect-time=1, x-request-start=1495413038323, total-route-time=0, content-length=219, look=true, view=true, include=pointer

verbose: REQUEST for [PUT] /parse/classes/objectClass/xxxxxxxx: {  “look”: false 
 } method=PUT, url=/parse/classes/objectClass/xxxxxxxxxx, host=xxxxxxxxxxx, connection=close, user-agent=node-XMLHttpRequest, Parse/js1.9.2 (NodeJS 6.10.0), accept=/, content-type=text/plain, x-request-id=xxxxxxx, x-forwarded-for=xxxxx, x-forwarded-proto=https, x-forwarded-port=443, via=1.1 vegur, connect-time=0, x-request-start=1495414373419, total-route-time=0, content-length=181, look=false

verbose: RESPONSE from [PUT] /parse/classes/objectClass/xxxxxxxxxx: {   "response": {    "updatedAt": "2017-05-22T00:52:53.425Z"  } }

devKC avatar May 22 '17 01:05 devKC

Not sure the logs help really in that case, as it doesn't show the object is not saved correctly. Also, you could use query.each(function(result) {});. This method waits for returned promises.

Also, you could use result.save({look: false}, {useMasterKey: true});

Does it help?

flovilmart avatar May 22 '17 01:05 flovilmart

@flovilmart - regarding query.each- I am running a batch job and there will be 1000+ records that will be returned. From what I read, it seems like query.each has a limit at 1000 records so I think query.find would be more suitable for this purpose.

As for result.save({look: false}, I gave that a try and strangely the db updates only on the second "job" run. So after deploying the new build and clicking on "job" button to run the job, db doesn't update on first click, but rather on second click. Both times the status is "success". Also, why would result.save({look: false} be different from the original code that I had?

devKC avatar May 22 '17 02:05 devKC

If you have so many records to update, you should probably issue a mongo query directly (update where) instead of a read/write. Also, your question is somewhat vague, try batching with 100 objects and run it every minutes.

Closing as lacking proper STR.

flovilmart avatar May 22 '17 02:05 flovilmart