2

I'm trying to use the Dropbox Datastore API with NodeJS. I can connect and use it just fine, but I can't seem to get it to stop and let the program exit gracefully. I pulled the file from https://www.dropbox.com/static/api/1/dropbox-datastores-0.1.0-b3.js and put it in my local directory.

So if you run the following (with valid creds) then it never exits.

var dropbox = new require('./dropbox.js')
var client = new dropbox.Client
({
    key:'apikey',
    secret:'apisecret',
    token:'useroauthtoken',
    uid:'useruid'
});

var datastoreManager = client.getDatastoreManager();
datastoreManager.openDefaultDatastore(function(error,datastore){
    if(error) console.log(error);

    var table = datastore.getTable('exampletable');
    table.insert({hello:'newman',inthepool:true});
});
Grummle
  • 1,364
  • 1
  • 12
  • 21
  • Maybe you should change your title in how to exit node.js gracefully, as it has - in my opinion - nothing to do with DropBox. – Kurt Pattyn Aug 12 '13 at 12:06

2 Answers2

1

Have you tried process.exit() (see http://nodejs.org/api/process.html#process_process_exit_code)?

This should shutdown your program gracefully.

Kurt Pattyn
  • 2,758
  • 2
  • 30
  • 42
  • I have. It seems like operations for the dropbox datastore api are put on a queue and handled async as they can be. So after the call to insert if you just do a process.exit() your changes will most likely not be persisted. I'm hoping there is some way to gracefully shut down the event queue that the dropbox api is using so that I can be sure its persisted everything. – Grummle Aug 12 '13 at 14:16
  • Have you tried syncStatusChanged as per https://www.dropbox.com/developers/datastore/docs/js#Dropbox.Datastore.DatastoreManager? And from the callback call process.exit(). – Kurt Pattyn Aug 12 '13 at 15:17
  • The callback provides 'null' as an argument. If I call getSyncStatus() from within the call back I can see if its still currently uploading, but it feels hacktastic. – Grummle Aug 14 '13 at 19:58
0

Untested, but how about calling datastore.close()?

user94559
  • 59,196
  • 6
  • 103
  • 103
  • I tried that. If I call datastore.close() within the call back I get an error that 'datastore is already closed'. Same with datastoreManager. If I call it outside the callback it seems to have no affect. – Grummle Aug 07 '13 at 21:30