Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional data to to finished tasks for delivery back to the front end #28

Open
inator opened this issue Dec 14, 2013 · 4 comments

Comments

@inator
Copy link

inator commented Dec 14, 2013

Imagine this use case. Through a hoodie task a game app front end adds points to players score and the backend picks up the task to make an update and and evaluate this addition to determine if the points result in a a level up. The backend can trigger a successful task completion like so:

hoodie.task.success( db, doc, /*opt*/callback )

which currently updates the task doc with:

'$processedAt': moment().format(),
'_deleted': true

But other than generating another doc for the front end to listen for, there's seems to be no immediate way to close the loop with additional data to let the front end know that the points resulted in a level change. Therefore, I propose:

hoodie.task.success( db, doc, doneData, /*opt*/callback )

Where 'doneData' is any additional data to deliver back to the front end.

It appears I may be able to work around this by performing a manual update that mimic the success process (along with the add-on of my own cargo data), but adding something like this would be ideal.

Also, there dose not appear to be any documentation on the use of this method so I had to look for it in the source. If I've missed something please let me know.

@inator
Copy link
Author

inator commented Dec 14, 2013

Just for reference, here's my quick backend work around until something like this might be available:

moment = require('moment');

hoodie.task.on('add:sometask', function (db, doc) {
    //do something cool

    //mimic a 'hoodie.task.success(db, doc)' but add the doneData object
    doc['$processedAt'] = moment().format();
    doc['_deleted'] = true;
    doc['doneData'] = {test:'test'};
    hoodie.database(db).update(doc.type, doc.id, doc, function(err, data){ if(err) console.log(err); });
});

@gr2m
Copy link
Contributor

gr2m commented Dec 16, 2013

Yeah we should add docs at least here:
https://github.com/hoodiehq/hoodie-plugins-api

I didn't check, but did you check if you can add properties to taskObject before you run hoodie.task.success(dbName, taskObject)?

@gr2m
Copy link
Contributor

gr2m commented Dec 16, 2013

@caolan can you review this?

@inator
Copy link
Author

inator commented Dec 16, 2013

Yes I checked that and it re-triggers the listener as I recall. I have not looked into the code behind it, but I suspect it looks for changes and if it sees any it treats it as a new event. Of course if I add properties along with the deletion all is ok.

On Dec 16, 2013, at 3:42 AM, Gregor Martynus [email protected] wrote:

Yeah we should add docs at least here:
https://github.com/hoodiehq/hoodie-plugins-api

I didn't check, but did you check if you can add properties to taskObject before you run hoodie.task.success(dbName, taskObject)?


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants