Open jvdonk opened 7 years ago
Hi,
could you try sails-hook-pubsub-offshore ? just wrote it but never tested it ...
I looked for this package, apparently with my nose... Tnx!
But it doesn't look like it's working. :'( This is the code that works with the waterline pubsub:
It's an overridden blueprint function(create) to create the model(Version) and then publish the newly created model to subscribers:
create: function(req, res) {
var data = actionUtil.parseValues(req);
Version
.create(data)
.exec(function created(err, newInstance) {
// Differentiate between waterline-originated validation errors
// and serious underlying issues. Respond with badRequest if a
// validation error is encountered, w/ validation info.
if (err) return res.negotiate(err);
// If we have the pubsub hook, use the model class's publish
// method to notify all subscribers about the created item.
if (req._sails.hooks.pubsub) {
if (req.isSocket) {
Version.subscribe(req, newInstance);
Version.introduce(newInstance);
}
Version.publishCreate(newInstance, !req.options.mirror && req);
}
// Send JSONP-friendly response if it's supported
res.created(newInstance);
});
}
Both the
req._sails.hooks.pubsub // pubsub is undefined
and
req.isSocket // isSocket is undefined
are undefined. As well as:
Version.publishCreate // publishCreate is undefined
There is a "req._sails.hooks.pubsub-offshore" though, but when i test for that hook instead of "req._sails.hooks.pubsub", I get a ReferenceError:
ReferenceError: offshore is not defined
at created (c:\DEV\Test\electron-release-server\api\controllers\VersionController.js:321:37)
at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19)
at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80)
at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
at success (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\normalize.js:33:31)
at _switch (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\factory.js:58:28)
at c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:238:9
at _toString (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:52:16)
at c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:269:32
at c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:44:16
at child.schema.normalizeCallbacks.i (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\schema.js:152:44)
at fn (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\callbacksRunner.js:60:10)
at _setImmediate (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:181:20)
at iterate (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:262:13)
at Object.async.forEachOfSeries.async.eachOfSeries (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:281:9)
at Object.async.forEachSeries.async.eachSeries (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:214:22)
at Object.runner.afterCreate (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\callbacksRunner.js:63:9)
at after (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:233:17)
at c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:220:76
at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19)
at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80)
at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
at success (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\normalize.js:33:31)
at _switch (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\factory.js:58:28)
at afterwards (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\adapter\dql.js:89:19)
at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19)
at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80)
at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
try req._sails.hooks ["pubsub-offshore"]
Le 1 déc. 2016 12:29, "jvdonk" notifications@github.com a écrit :
There is a "req._sails.hooks.pubsub-offshore" though, but when i test for that hook instead of "req._sails.hooks.pubsub", I get a ReferenceError:
ReferenceError: offshore is not defined at created (c:\DEV\Test\electron-release-server\api\controllers\VersionController.js:321:37) at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19) at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80) at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18) at success (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\normalize.js:33:31) at _switch (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\factory.js:58:28) at c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:238:9 at _toString (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:52:16) at c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:269:32 at c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:44:16 at child.schema.normalizeCallbacks.i (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\schema.js:152:44) at fn (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\callbacksRunner.js:60:10) at _setImmediate (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:181:20) at iterate (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:262:13) at Object.async.forEachOfSeries.async.eachOfSeries (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:281:9) at Object.async.forEachSeries.async.eachSeries (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:214:22) at Object.runner.afterCreate (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\callbacksRunner.js:63:9) at after (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:233:17) at c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:220:76 at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19) at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80) at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18) at success (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\normalize.js:33:31) at _switch (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\factory.js:58:28) at afterwards (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\adapter\dql.js:89:19) at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19) at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80) at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Atlantis-Software/sails-hook-orm-offshore/issues/6#issuecomment-264148304, or mute the thread https://github.com/notifications/unsubscribe-auth/AF0n_HUGZLPGllPdnoA-NHQO8rHfXknXks5rDq-fgaJpZM4LALMH .
That does exists and passes. Next thing that blows up is the .publishCreate:
TypeError: Version.publishCreate is not a function
at created (c:\DEV\Test\electron-release-server\api\controllers\VersionController.js:326:19)
at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19)
at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80)
at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
at success (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\normalize.js:33:31)
at _switch (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\factory.js:58:28)
at c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:238:9
at _toString (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:52:16)
at c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:269:32
at c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:44:16
at child.schema.normalizeCallbacks.i (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\schema.js:152:44)
at fn (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\callbacksRunner.js:60:10)
at _setImmediate (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:181:20)
at iterate (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:262:13)
at Object.async.forEachOfSeries.async.eachOfSeries (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:281:9)
at Object.async.forEachSeries.async.eachSeries (c:\DEV\Test\electron-release-server\node_modules\async\lib\async.js:214:22)
at Object.runner.afterCreate (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\callbacksRunner.js:63:9)
at after (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:233:17)
at c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\query\dql\create.js:220:76
at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19)
at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80)
at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
at success (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\normalize.js:33:31)
at _switch (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\switchback\lib\factory.js:58:28)
at afterwards (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\adapter\dql.js:89:19)
at wrapper (c:\DEV\Test\electron-release-server\node_modules\offshore\node_modules\lodash\index.js:3592:19)
at applyInOriginalCtx (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:417:80)
at wrappedCallback (c:\DEV\Test\electron-release-server\node_modules\offshore\lib\offshore\utils\normalize.js:320:18)
Something new-ish that you didn't implement because it didn't exist when you created the pubsub-offshore? Same as the req.isSocket?
maybe a bug in sails-hook-orm-offshore not looking for 'pubsub-offshore' but 'pubsub', i'll have a look
Tnx!
The reason why I tried offshore is for the deeppopulate(awesome work!), but maybe Atlantis-Software/waterline#deepPopulate will be sufficient for that(read that somewhere on stackoverflow). Did you made that as well? Any guidance with integrating that together with sails/pubsub/blueprints?
this an old work a bit buggy... we would like to add it in waterline but upstream wouldn't like... offshore is the better... what kind of database do you use? if you use an sql one try offshore-sql and if you could test pubsub-offshore i'll make it work but i don't use sails...
Le 1 déc. 2016 5:55 PM, "jvdonk" notifications@github.com a écrit :
Tnx!
The reason why I tried offshore is for the deeppopulate(awesome work!), but maybe Atlantis-Software/waterline#deepPopulate will be sufficient for that(read that somewhere on stackoverflow). Did you made that as well? Any guidance with integrating that together with sails/pubsub/blueprints?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Atlantis-Software/sails-hook-orm-offshore/issues/6#issuecomment-264228314, or mute the thread https://github.com/notifications/unsubscribe-auth/AF0n_P4iLxIRAhtCp0mDvckM2XOA5QyNks5rDvv6gaJpZM4LALMH .
I'm using MongoDb here with sails-mongo and connect-mongo, the electron release server project defaults to postgresql but I changed it to MongoDb. Does offshore-sql still applies then? As an alternative to Atlantis-Software/waterline#deepPopulate?
offshore-sql only work with sql so mongoDb is not supported in. you should use sails-mongo maybe we'll write an mongoDb adapter but this not in our plan for now. you shouldn't use Atlantis-Software/waterline#deepPopulate because it's no more supported... you should use offshore with sails-hook-orm-offshore because it's supported. i wrote sails-hook-pubsub-offshore to have a pubsub alternative of pubsub but as i'm not using sails, i need some help to make it work... could you write a unit test PR?
@jvdonk i updated:
and i added some tests in pubsub, all tests from sails pubsub passed see https://travis-ci.org/Atlantis-Software/sails-hook-pubsub-offshore/jobs/181988352
Great work, tnx!
So I updated the 3 packages and did npm install:
and then npm start:
:'( It blows while registering an action?
Electron Release Server(ERS) out of the box supports only a single app. So I tried to adjust that and therefore I needed deep-population(OOTB: Versions->Assets to Apps->-Versions->Assets)
But I'm losing too much time on the deadline here, so last week I let the 'multi app' Electron Release Server(ERS) solution go, for the moment. I moved on and tried configuring a staging environment for the (single app)ERS using pm2 on a windows 2012 R2 environment to let it run forever, also after reboots. I failed to get it working, manually starting with pm2 went fine, but combined with the pm2-windows-server package I couldn't get it to start after reboot.
All in all, I'm dropping ERS completely now and I'm integrating it(electron updates) into our own platform.
I'm sorry for your wasted efforts and wish you all the best.
Kind regards!
Hey, the pubsub methods of the pubsub-offshore hook are prefixed with a '_'. So if you want to emit a create you have to use _publishCreate and so on...
@dominicrico hi, could you PR a README.md update explaining this ?
@atiertant Done! PR
thanks
@dominicrico After changing to _publishCreate and _watch, i got different error like this,
error: Sending 500 ("Server Error") response: TypeError: sails.sockets.getId is not a function at child._watch (C:\Project\littlescribe-api\node_modules\sails-hook-pubsub-offshore\index.js:1067:61) at child.wrapper [as _watch] (C:\Project\littlescribe-api\node_modules\sails-hook-pubsub-offshore\node_modules\lodash\index.js:3095:19) at Object.classroomVisibility (C:\Project\littlescribe-api\api\controllers\SocketController.js:12:24) at bound (C:\Project\littlescribe-api\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) at routeTargetFnWrapper (C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:164:37) at param (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:138:11) at pass (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:167:11) at C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:187:7 at alwaysAllow (C:\Project\littlescribe-api\node_modules\sails\lib\hooks\policies\index.js:207:11) at routeTargetFnWrapper (C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:164:37) at param (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:138:11) at pass (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:167:11) at C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:187:7 at _sendHeaders (C:\Project\littlescribe-api\node_modules\sails\lib\hooks\cors\index.js:195:7) at routeTargetFnWrapper (C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:164:37) at param (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:138:11) at pass (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:167:11) at C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:187:7 at sails.router.bind._middlewareType (C:\Project\littlescribe-api\node_modules\sails\lib\hooks\csrf\index.js:114:11) at routeTargetFnWrapper (C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:164:37) at param (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:138:11) at pass (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:167:11) at C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:187:7 at _addResViewMethod (C:\Project\littlescribe-api\node_modules\sails\lib\hooks\views\res.view.js:325:3) at routeTargetFnWrapper (C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:164:37) at param (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:138:11) at pass (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:167:11) at C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:187:7 at C:\Project\littlescribe-api\node_modules\sails\lib\hooks\i18n\index.js:35:7 at Object.i18nInit [as init] (C:\Project\littlescribe-api\node_modules\i18n\i18n.js:89:5) at addLocalizationMethod (C:\Project\littlescribe-api\node_modules\sails\lib\hooks\i18n\index.js:33:11) at routeTargetFnWrapper (C:\Project\littlescribe-api\node_modules\sails\lib\router\bind.js:179:5) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:164:37) at param (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:138:11) at pass (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:145:5) at nextRoute (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:100:7) at callbacks (C:\Project\littlescribe-api\node_modules\express\lib\router\index.js:167:11)
Can you pls help me to solve this?
could you give me code and version used ?
My code is - model._watch(req); model._publishCreate({id: 1,message: "success"});
sails verison-0.11.2
Thanks.
Hi,
I'm using this sails hook for deep populating models for a fork of a sails project(electron-release-server).
This project uses PubSub for notifications when a model is created/updated/etc but that stopped working when I used this hook. Blueprints also stopped working but that is solved with the sails-hook-blueprints-offshore hook (see issue #2).
In order to use this hook, one has to disable orm and orm and pubsub(and blueprints) the .sailsrc file.
Should the PubSub just work(same as the orm part in offshore) or do I have to reconfigure other stuff to get PubSub working?
Thanks for this hook, the deep populating is working perfect!