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

Lifting with watch task in production results in timeout #6834

Open
Smoenybfan opened this issue Aug 7, 2019 · 4 comments
Open

Lifting with watch task in production results in timeout #6834

Smoenybfan opened this issue Aug 7, 2019 · 4 comments
Labels
try this out please uploads Related to file uploads (sails-hook-uploads, skipper, skipper adapters, streaming, transloading,etc)

Comments

@Smoenybfan
Copy link

Smoenybfan commented Aug 7, 2019

Node version: 11.10.1
Sails version (sails): 1.1.0
ORM hook version (sails-hook-orm): 2.1.1
Sockets hook version (sails-hook-sockets): 1.5.5
Organics hook version (sails-hook-organics): -
Grunt hook version (sails-hook-grunt): 3.1.1
Uploads hook version (sails-hook-uploads): -
DB adapter & version (e.g. sails-mysql@5.55.5): sails-mysql@1.0.1
Skipper adapter & version (e.g. skipper-s3@5.55.5): skipper-disk@0.5.12


In tasks/register/prod.js I want to add the 'watch' task to the array that shoud get registered. But if I do this, then lifting the app in production will result in a timeout. I've already set the hookTimeout to 1000000, but that did not help. Is it even possible to use the watch task in production?

I've seen issue #3894, but the answer was to up the timeout (did not help) and it is nearly three years old.

To demonstrate my use case: I want to upload files from a user and then save them in the filesystem in the assets folder. Now I also want to be able to access these files directly from the fronted via a "a href download" link. The problem is that when run in production, the assets folder does not get synced to the .tmp/public folder. For this I wanted to use the watch task.

@sailsbot
Copy link

sailsbot commented Aug 7, 2019

@Smoenybfan Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. (Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)
  • tell us why this issue is important to you and your team. What are you trying to accomplish? (Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. (Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. (Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. (Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

@navicstein
Copy link

Assuming you have succeeded in uploading the files to your sails server https://github.com/mikermcneil/ration/blob/master/api/controllers/things/upload-thing.js you need to create another action responsible for downloading the files to the browser, check this -> https://github.com/mikermcneil/ration/blob/master/api/controllers/things/download-photo.js
you don't need to keep uploading things in assets as sails will eventually move them to .tmp you can also point your dirname to /srv if using linux

in your config/route.js

...
'GET   /api/v1/things/:id/photo':                   { action: 'things/download-photo', skipAssets: false },

then in your view you can use:

<!-- Depending on your structure -->
<div v-for="(thing, i) in things" :key="i">
<!-- ${thing.id} refers to the identity of the photo we uploaded via the action-->
<img :src="`/api/v1/things/${thing.id}/photo`"/>
<!-- or ${thing.imageSrc}, it depends -->
</div>

You don't need to be worried where your images are uploaded to, sails has so many skipper adapters to use and they are production ready - trust me.

One more thing, checkout the Ration APP as it have helped me in the past to master sails - good luck

@johnabrams7 johnabrams7 added the uploads Related to file uploads (sails-hook-uploads, skipper, skipper adapters, streaming, transloading,etc) label Aug 7, 2019
@Smoenybfan
Copy link
Author

Thank you for the quick response!

I think you might have misunderstood me. My goal is to do the download explicitly without writing an action by using the download attribute of the anchor html tag

<a href="assets/uploads/myfile.xlsx" download>Click to download</a>

As far as I understand, there is a grunt task "watch" that observes the assets folder for any changes that happen there and if any happen, the tasks defined in the tasks/config/watch.js are executed. One of these tasks is the "syncAssets" task that would sync the assets and the .tmp folder. This would mean that any files I have uploaded successfully and stored in the assets folder would be synced to the .tmp folder and would then be available to the download anchor described above. That way, no action is needed and the file can be directly downloaded from the served assets.

I got this working in development environment as the watch task is registered in the tasks/register/default.js Now I want to have this behavior too in production but when I register the "watch" task in tasks/register/prod.js, then sails is not able to lift anymore due to the timeout described above.

Currently my workaround is to either copy the file manually from the assets folder to the .tmp folder or to write a download action as you described, but if possible I'd prefer to use the grunt task just as I already have in development.

Also, I will check out the Ration APP once I've got some time on my hands, thank you.

@navicstein
Copy link

i don't know if this would work, have you tried to change your sails.config.paths.tmp path? maybe you might set it to assets directly 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
try this out please uploads Related to file uploads (sails-hook-uploads, skipper, skipper adapters, streaming, transloading,etc)
Development

No branches or pull requests

4 participants