The web in a box - a next generation web framework for the Perl programming language

IRC log for #mojo, 2016-11-02

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
00:01 polettix joined #mojo
00:09 disputin joined #mojo
00:27 suede $pg->db->query('SELECT id FROM accounts WHERE email = ? OR username = ?' => ($email, $username) => sub {
00:28 suede this should work, right?
00:28 suede (using Mojo::Pg)
00:43 Janos joined #mojo
00:53 Grinnz sure, what happened when you tried
00:58 aborazmeh joined #mojo
01:36 aborazmeh joined #mojo
02:03 zelda45 joined #mojo
02:04 zelda45 Hi Guys,
02:06 zelda45 I'm writing files (via mojo:upload to a watched directory) which is causing the server to restart, in my cases this is very slow, is there a way to un-watch a subdirectory of a watched directory, and then later trigger it to be watched so that the server restarts, e.g. after many different file uploads. hope htis makes sense
02:11 zelda45 or to simplfy it, is there a way to unwatch a subdirectory of a watched directory?
02:11 jberger this is of course only a problem during development
02:12 jberger I'd suggest maybe add a second static files directory?
02:12 zelda45 Whis is this only a prob. in devlopment?
02:12 jberger I'm assuming that you are intentionally putting the uploaded files in a public directory so that they can be served later
02:12 zelda45 yes
02:13 jberger morbo is the only server that restarts on changes
02:13 jberger and it is the development server
02:13 zelda45 I see
02:13 jberger you certainly wouldn't want to use a server that restarts itself in production
02:13 zelda45 Thought hynotoad did the same
02:13 jberger nope
02:13 zelda45 makes sense
02:14 jberger sri et al: Firewatch is on sale for $12
02:14 jberger is it worth that?
02:14 zelda45 What is Firewatch
02:15 jberger Game on Stea
02:15 jberger Steam
02:15 jberger got a lot of mention from the people here a few months ago, people said they liked it but that it was too short for the price they paid
02:15 jberger so I set a notification on it to wait for a sale
02:16 zelda45 :)
02:16 jberger http://store.steampowered.com/app/383870
02:17 jberger anyway, sorry, back to your question
02:17 jberger I actually would investigate adding a second static file path to use for that anyway
02:17 jberger seems to make sense to have a path for core static assets and one for uploaded assets
02:17 jberger and it would then help you in development anyway
02:18 jberger http://mojolicious.org/perldoc/Mojolicious#static
02:20 jberger zelda45 ^^
02:21 zelda45 Thats cool
02:21 zelda45 so in development, I'd just not watch that dir
02:21 zelda45 I think I do it with the -w switch
02:22 jberger I don't think you'd need to do anything for another path
02:22 jberger it only watches lib/ public/ and templates/ by default
02:23 zelda45 This does present another problem
02:23 jberger so if you added uploads/ I THINK it wouldn't be watched by default
02:23 jberger (note that you don't have to do this at all anyway)
02:23 zelda45 in my case, all my static files are cached in memory pre gzipped etc..
02:24 zelda45 this is why its a slow startup
02:24 jberger do you have a build process that does that or are you using AssetPack?
02:24 zelda45 its all part of the startup in mojo
02:25 jberger I don't think AssetPack rebuilds each time, I think there is some logic around that, though batman would know more
02:25 zelda45 so I have a hash->{filename}=data etc..
02:26 zelda45 problem is how do I make that thread visible
02:26 zelda45 In other words, before mojo forks its workers, this file cache is in place
02:27 zelda45 Just wondering if I write to that in the upload thread, it will be local to that tread would it now (like a copy on write)
02:27 jberger so this is an asset pipeline that you rolled yourself?
02:27 zelda45 yes
02:27 jberger oh you want the uploaded file to be part of the gzipped asset?!
02:28 zelda45 yes, as the server will not be restarting
02:28 zelda45 it will be save too
02:28 jberger that's a really weird requirement
02:28 zelda45 well, more performance and security
02:29 lluad joined #mojo
02:29 zelda45 e.g. client requests file, and accepts gzip (or not) and the hash entry is returned
02:29 zelda45 so once mojo is started, the file system is never touched for static files
02:30 zelda45 or any files actually
02:30 jberger that sounds like something that a front-end server would be good for
02:30 jberger nginx for example
02:30 jberger if the goal isn't to bundle it with other assets
02:30 zelda45 have not used nginx
02:30 jberger (I was thinking you were bundling it up with you application's assets)
02:30 zelda45 at the moment' its apache and reverse proxy
02:31 jberger apache should be similar
02:31 jberger it should have a way to cache/serve static assets from a given path in an optimized way
02:31 jberger meaning that request wouldn't even make it to the mojo app
02:32 zelda45 well, it also minifies css/js/html etc.. but not for development
02:32 jberger what kind of app is this?
02:32 zelda45 it caches both compress/minified and raw content in different cache
02:32 jberger a CMS?
02:32 purl i think a cms is Content Management System or Color Management System
02:32 jberger shut it purl!
02:32 * purl shuts it
02:32 zelda45 yes
02:32 zelda45 a CMS of sorts
02:33 jberger I mean, you could still accept the upload, post process them, then put the result into the apache static file server
02:34 zelda45 Well, I was not planning on using apache for production, just hynotoad
02:35 jberger heh
02:35 jberger I almost always do the opposite
02:35 jberger reverse proxy in production and none in development
02:35 jberger (though actually sometimes, depending on where I'm developing)
02:35 zelda45 Esentially if a file is not in a hash, it is not accessible
02:35 jberger but always in production
02:36 jberger you don't need it, but it can be really handy
02:36 * jberger buys Firewatch
02:38 zelda45 So the problem, is I need to update the root thread's cache's, so when it starts forking more workers, they get the latest version, not sure there is much I can do with the other treads
02:38 jberger you aren't using memcached or something for that?
02:39 zelda45 No
02:39 zelda45 So this is in the start up of mojo
02:39 zelda45 imagine a out cache={}
02:39 jberger ewwww
02:40 zelda45 during startup cache->{filename}=data
02:40 jberger seriously, consider letting your front-end server do this
02:40 jberger https://serversforhackers.com/nginx-caching
02:40 jberger varnish also can, I assume apache can somehow
02:40 jberger I haven't used apache in a long time, but it must have a plugin or something
02:41 zelda45 Well there is a lot of access control etc..
02:43 jberger https://www.nginx.com/resources/wiki/start/topics/examples/xsendfile/
02:46 jberger so the request goes to the application server and it can simply set a response header to authorize
02:46 jberger and nginx responds
02:46 jberger yes that is getting a bit more complex, but no more complex than cache invalidation across in-memory data across hypnotoad forks
02:47 zelda45 What about serving different images at the same URL for different devices
02:47 jberger that's a pretty non-standard request too, isn't it?
02:48 zelda45 I was waiting for that one
02:48 jberger but ok so lets say you have img300x300.png and img5000x5000.png
02:48 zelda45 Look, Microsoft, Apple and the rest dont do standards, why should I
02:48 zelda45 :)
02:48 jberger you would just set the X-Accel-Redirect response to the appropriate image for the size
02:49 jberger and nginx would just use that image in the response (for img.png)
02:49 zelda45 is that standard?
02:49 jberger I'm working from nginx documentation
02:50 jberger but that link I sent you seems to refer to mod_xsendfile for apache
02:50 jberger hmmm a plugin for X-Accel might be kinda fun
02:51 jberger with a fallback for development mode to serve the same file locally
02:51 zelda45 So basically when I generate my various caches at start-up, I'd store them in files to be served by apache xsendfile
02:51 zelda45 ?
02:51 jberger yeah
02:52 zelda45 And can xsendfile pre-cache files in memory
02:52 jberger and then when they are requested, you set that header (if authenticated etc) and apache sees that header and serves the file
02:52 jberger nginx can, I assume apache does the same
02:52 jberger probably something you configure (storage limits etc)
02:53 zelda45 In my case auth is via mojo session
02:53 jberger right
02:56 zelda45 So, does the file request come into mojo first or xsendfile?
02:56 jberger the request comes from the client through apache to mojo
02:57 jberger then mojo, rather than replying with a file can reply just with the header, which apache sees on the way out and handles the request from that point (rather than just acting as a relay)
02:57 zelda45 so in my cache I can (mainly for development) have switches to switch to different caches, so for example, when I'm looking at code I can look at the unminified version on the fly
02:58 jberger I'd probably abstract this out into some configurable plugin
02:58 zelda45 ok that sounds like it will work
02:58 jberger so some new reply method
02:58 jberger and depending on the configuration either reply with a file outright or else reply with the header
02:59 zelda45 so what header is it
02:59 jberger which would be a really neat CPAN plugin
02:59 jberger at this point I point you to the apache mod_xsendfile docs :-P
03:00 zelda45 So can mojo direct xsendfile to send different files for the same URL to different users based on the header response ?
03:00 jberger sure
03:00 zelda45 Wow
03:00 jberger it just serves whatever file you tell it to
03:00 zelda45 and you specifiy that in the response header?
03:01 zelda45 I assume I can manage cache control with my own additional headers
03:02 jberger I've only done this for a small personal project
03:02 jberger and I used nginx (again I suggest you read this, even if you are going to use apache) https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/
03:02 zelda45 You're a gent jberger, thanks, off to do some reading...
03:02 jberger yep, enjoy
03:24 jberger anyone have ideas for names for an abstraction layer plugin for something like this
03:24 jberger ?
03:25 jberger Mojolicious::Plugin::Sendfile is actually not a good choice because of the system call sendfile which might actually be useful in its own right
03:50 disputin joined #mojo
03:57 noganex_ joined #mojo
04:10 lluad joined #mojo
04:31 lluad joined #mojo
04:39 trwww joined #mojo
05:05 inokenty-w joined #mojo
05:14 mgrimes_ joined #mojo
05:45 hrupp joined #mojo
06:42 polettix joined #mojo
06:48 mbudde joined #mojo
07:00 Vandal joined #mojo
07:10 janl joined #mojo
07:18 dod joined #mojo
07:24 dod joined #mojo
07:24 alilles joined #mojo
07:51 dod joined #mojo
07:52 AndrewIsh joined #mojo
08:21 rshadow joined #mojo
08:38 trone joined #mojo
08:46 itaipu joined #mojo
09:03 kes joined #mojo
09:28 osfabibisi joined #mojo
09:34 jan94 joined #mojo
09:38 jan94 Hello, I have a simple script using Mojo::Subprocess and get the error "Magic number checking on storable string failed" after some seconds: http://pastebin.com/aHbDUNCz
09:42 sri jberger: firewatch is not bad, but too short, even for $12
09:54 Vandal joined #mojo
09:56 Vandal joined #mojo
10:01 ladnaV joined #mojo
10:06 polettix joined #mojo
10:10 xdg joined #mojo
10:12 stryx` joined #mojo
10:27 dotan_convos joined #mojo
10:57 polettix joined #mojo
11:12 itaipu joined #mojo
11:32 dod joined #mojo
11:34 Vandal joined #mojo
12:39 rshadow1 joined #mojo
12:55 gizmomathboy joined #mojo
12:57 kes Interesting module: https://metacpan.org/pod/Variable::Eject, It seems may be used when extracting variable from stash into template name space
13:00 Pyritic joined #mojo
13:12 ramortegui joined #mojo
13:17 rshadow joined #mojo
13:34 sri kes: no
13:42 jberger Is that module just modifying the perl stash?
13:42 jberger I don't get it
13:43 aborazmeh joined #mojo
13:55 suede jberger: it's not, but you can use it that way
13:55 suede but i personally wouldn't because of the possibility of introducing extract()-like bugs
14:11 genio That module makes me cringe a bit.
14:13 kes joined #mojo
14:15 rshadow joined #mojo
15:05 sri hahahaha, i just found out that subroutine signatures mess up your Devel::Cover stats
15:06 sri because of the arity check the current signatures implementation creates as a code branch
15:07 jberger heh
15:08 jberger you could add a @ at the end of each signature :s
15:08 jberger anyway, all the more reason for a proper signature op
15:08 sri that's already in blead right?
15:14 disputin joined #mojo
15:24 disputin joined #mojo
15:34 batman jberger: AssetPack doesn't rebuild assets that are already built, but they need to be saved to disk.
15:43 Static3 joined #mojo
15:43 Static3 hi Guys,
15:44 batman hey Static3
15:44 Static3 If I add a static path using my $static = $self->static;  push @{$self->static->paths} => "somedir"
15:44 Static3 the static file server does not gzip the content
15:45 batman Static3: it doesn't matter how you add the directories.
15:45 batman do you have a reverse proxy in front, like apache and nginx?
15:45 Static3 yes
15:45 Static3 but dont want to use that
15:45 Static3 because on my dev machine I use only morbo
15:45 batman ok
15:46 Static3 I can gzip the file myself and serve the $$content  out directly, but was hoping the builting server had a wasy to do this
15:47 Static3 builting=built-in
15:47 Static3 wasy=way
15:48 batman yes. gzip is built in, so if the browser asks for gzip, then it will get it in return.
15:48 Static3 but its no in my cases
15:49 Static3 Do I need to set the header (as if gzipped it?)
15:49 Static3 e.g. in after_static
15:50 batman hm... maybe i'm wrong. let me check
15:50 jberger Static3: are you the same person I was talking to yesterday?
15:50 Static3 :)
15:51 jberger its easier if you stick to a single username
15:51 Static3 You can see my IP :)
15:51 jberger I can, but it is easier to just make that clear
15:51 salva joined #mojo
15:51 Static3 I decided, not to use xsenfile yet, because its to much of a change right now, but maybe in a few weeks
15:51 jberger in this case it was easy enough because the topics are a clear continuation
15:57 Static3 How can this be done, I just $res->headers->content_encoding('gzip'); in after_render but still not gzipped
16:01 Static3 ok, if I send the 'Content Encoding Error'' in after static I an a broswer 'Content Encoding Error''
16:02 Static3 sorry, if I send the $res->headers->content_encoding('gzip') I get a Content Encoding Error
16:02 Static3 so is there a way to poke it to gzip
16:03 lluad joined #mojo
16:23 Static3 jberger, When I connect the client (web) uses a random username (mibbit.com)
16:23 jberger it doesn't let you pick one?
16:23 * jberger hasn't used mibbit in a very long time
16:24 Static3 You can change it, which is why I choose static3
16:24 Static3 but yesterday, I did not
16:24 jberger ah
16:24 jberger ok well, Static3 it is then
16:24 jberger :D
16:24 jberger and welcome :D
16:24 Static3 yes
16:25 Static3 so I cannot found a way to poke static server to serve gzip
16:27 Static3 jberger, what does warmup do?, I assume it preloads files
16:27 jberger yes
16:28 jberger what do you mean you can't make it serve gzip?
16:28 jberger it serves whatever file you ask it to (given the right parameters etc)
16:28 Static3 if I add a $static->path, it and serve an image, it's never gzipped,
16:30 Static3 so Client hash Accept-Encoding: gzip,deflate etc.., I would assume the static server would no to gzip the file
16:30 Static3 hash=has
16:37 suede is there a way to flatten async/callback stuff with mojo? for instance inside this callback i do other async queries
16:37 suede $pg->db->query('SELECT id FROM accounts WHERE email = ? OR username = ?' => ($email, $username) => sub {
16:38 suede which leads to nested callback hell
16:38 suede i found this http://search.cpan.org/~stevan/Promises-0.94/lib/Promises/Deferred/Mojo.pm
16:38 sri delays
16:38 pink_mist suede: delays help with it
16:39 suede oh, rad, thanks
16:40 sri every few months we want to use promises in mojolicious, but then all proposals look awful compared to delays and we stick with what we have
16:40 Static3 so it looks like Static.pm would need some sort of a callback to gzip static content
16:41 jberger Static3: I thought you were already gzipping these things?
16:42 Static3 Yes, but not all, some are changing and those are the problem
16:42 Static3 those I cannot serve, on-disk change needs to be detected
16:42 Static3 which was my next question
16:43 Static3 Can static detect changes after warmup?
16:43 jberger changes?
16:43 Static3 to a static file
16:43 jberger static doesn't detect anything
16:43 jberger I'm very confused now
16:44 jberger warmup isn't something that you need to consider
16:44 Static3 Yes, it just loads the file at start up
16:44 jberger "Prepare static files from "classes" for future use."
16:44 stryx` joined #mojo
16:45 jberger if you have static files in the __DATA__ section of a class, warmup extracts them
16:45 Static3 I assume that is a regex function
16:45 jberger this has nothing to do with serving on-disk or in-memory assets
16:45 Static3 ok
16:46 jberger Static3: I'm really starting to have my "premature optimization" meter going off in my mind
16:46 jberger how much traffic are you expecting?
16:46 Static3 lots
16:46 Static3 but that is not really the issue atm
16:47 jberger anyway here's an example of gzipping dynamic content: http://mojolicious.org/perldoc/Mojolicious/Guides/Rendering#Post-processing-dynamic-content
16:47 Static3 I already do that, even for my static content
16:47 jberger again, I think that leaning on a front-end server for serving static context gzipped and cached makes more sense
16:48 jberger then ... I'm lost again
16:48 Static3 I agree, and it looks like I've not no choice
16:48 jberger "so Client has Accept-Encoding: gzip,deflate etc.., I would assume the static server would [know] to gzip the file"
16:48 Static3 No, you are telling me what I already know.
16:48 purl okay, Static3.
16:49 Static3 will looking at Static.pm, it does not do anything or seem to provided any external hook to post process
16:50 jberger http://mojolicious.org/perldoc/Mojolicious#after_static
16:50 jberger all the hooks are documented in Mojolicious.pm
16:51 Static3 Anyway static cannot detect changes, so, its a moot point
16:51 jberger I still don't know what you mean by that
16:52 Static3 If static content changes and its been served by the static file server
16:52 jberger the static server doesn't cache anything
16:52 jberger it serves the file you tell it to
16:53 Static3 ok
16:53 jberger (yet another reason why front-end servers are better for this :-P)
16:53 Static3 does it pass the content to any hooks
16:53 jberger ?
16:54 asarch joined #mojo
16:54 Static3 In the example you listed above for dynamic content it passes ($$output)
16:54 Static3 if I remember
16:54 Static3 that output you then gzip, add header and return
16:55 jberger from the look of this hook you'd probably have to modify the response in plcae
16:56 jberger so the workflow here is, you are going to gzip this file, but if they request it before the gzipped version is ready you gzip it on the fly?
16:57 jberger you'd have to profile it, but it is probably a net performance loss to gzip it just to send it
16:58 Static3 I'll gave to bite the bullet., thanks again.
16:58 jberger you might be better to use a before_dispatch hook to detect if the gzipped version is present and if not gzip it into your cache
16:59 jberger good luck
16:59 purl You'll need it.
16:59 jberger hehe
17:20 trone joined #mojo
17:23 mgrimes_ joined #mojo
17:42 Pyritic joined #mojo
18:01 mcsnolte joined #mojo
18:26 PryMar56 joined #mojo
18:28 jabberwok the Cookbook gives an example systemd service file, but am puzzled how to make that work with perlbrew, and with the owning user's uid.
18:33 vicash jabberwok: put the stuff in a shell script and invoke shell script from systemd
18:34 hrupp joined #mojo
18:36 dod joined #mojo
18:59 Static3 joined #mojo
19:00 Static3 Jberger: Install x-sendfile, qot a few questions
19:00 Grinnz jabberwok: you can set a service to be started by a user with the User= option in the [Service] section: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
19:00 Static3 lets support I setup x-sendfile to service /var/www/html/img directory
19:01 Static3 when I set the x-sendfile header, in my before_redender handler, I assume I have to zap the body $res->body('');
19:01 Static3 or should I  $self->render(data => '') or both?
19:02 jberger you would never have wanted to set the body
19:02 jberger the whole point is not to have to deal with the file itself
19:02 Static3 also the path I send in the header is that, relative to the sendfile apache config
19:02 polettix joined #mojo
19:02 jberger and I don't know about the relative or absolute nature of the files, I believe that is server dependent and I haven't used apache for x-sendfile
19:02 Static3 It sets the content type to txt/html
19:03 jberger I believe the server takes care of the type headers, but you can do it yourself
19:03 Grinnz jabberwok: personally i like to hardcode the path to perl executables in init files, but i can see how that wouldn't necessarily work well with perlbrew
19:04 jberger jabberwok: I don't use perlbrew for deployment, because of these reasons
19:04 Static3 I get a 404 and I can see my x-sendfile header - kinda indicating there is a problem with x-sendfile
19:04 jberger I use the related Perl::Build which just builds a perl in a location
19:04 jberger did you enable mod_xsendfile?
19:04 Grinnz jabberwok: also, https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Environment%20variables%20in%20spawned%20processes indicates why finding a perlbrew perl in the path would be problematic
19:04 Static3 yes,
19:04 jberger I guess if you get a 404 then yes
19:05 jberger I'm guessing it would have to do with paths then yes
19:05 jberger but I can't help you there
19:05 jberger I'm sure there must be some examples online
19:05 Static3 When I set the header, do I also set 200 return code?
19:05 jberger doesn't matter which framework
19:05 jberger yes, 200
19:05 jberger because the server is going to replace it
19:05 jberger but you need to get past the start line and to the headers
19:06 Static3 So the 404 is coming from x-sendfile
19:07 Static3 What about the content type being set, will that be changed based on the file/mime type
19:07 Static3 by xsf
19:07 Grinnz jabberwok: you can, however, set additional environment variables for it to use with the Environment= and related options (in the same link above)
19:08 Static3 the mod_xsendfile-0.12/Readme.html does'nt give much away.
19:08 Grinnz but doing that manually for perlbrew doesn't seem like the best idea
19:14 jberger Static3 we are past my area of knowledge here
19:14 jberger I'd say set the content type header in the application if you know it
19:15 jberger but apache's static file server knows how to set the file type when it is operating alone, so I'll assume it knows how to set it when told to serve via x-sendfile
19:15 jberger but you are now to the point where you're just going to have to tinker until it works
19:16 Static3 I would have assumed it was ignore the content type
19:16 jberger I'm no expert on nginx's X-Accel-Redirect and I've literally never used apache's X-Sendfile
19:16 Static3 np, my first time:)
19:17 Static3 but from mojos side it should be the same regardless of the proxy server/x-sendmail
19:18 jberger why?
19:18 jberger this is why I was talking about abstracting the functionality into some plugin
19:19 Static3 when I don't zap the body I get a 502
19:19 jberger so that during testing (or whenever without a frontend server) the internal static server takes over
19:19 jberger what do you mean zap the body?
19:19 jberger you never should be setting a body
19:19 Static3 $res->body('');
19:20 Static3 I check the path is a sendfile path, then do $res->code(200); $res->body(''); $self->render(data => ''); $self->static_headers; return; }
19:21 Static3 after_redender is where I set the xsenfile header something like: $res->headers->header('X-Sendfile'       => $self->stash->{cachepath});
19:24 disputin joined #mojo
19:27 Static3 also if I dont zap the body I get 19:16:49 2016] [debug] Nothing has been rendered, expecting delayed response in the log
19:31 sri holy backlog batman
19:32 sri if something important has been said today i guess i'll miss it
19:39 jabberwok thanks Grinnz , jberger
19:42 janl_ joined #mojo
19:45 lluad joined #mojo
19:48 mib_kxvauw joined #mojo
19:49 mib_kxvauw hello
19:49 preaction hello
19:49 mib_kxvauw given something like https://metacpan.org/pod/Mojo::SlackRTM#SYNOPSIS, how does one start the loop and just send a message right away? instead of waiting for an event to take place
19:50 mib_kxvauw I guess I am asking "how do I insert an imediate callback into the loop" ... or something
19:51 Grinnz Mojo::IOLoop->next_tick
19:52 mib_kxvauw so... $slack->ioloop->next_tick(sub {.. }); $slack->ioloop->start; then
19:52 preaction surprised there isn't a "connect" event
19:53 preaction just $slack->start, which calls $slack->ioloop->start for you
19:54 mib_kxvauw preaction: thanks, your remark made me re-view and indeed there is an on connect, just called weird
19:54 mib_kxvauw https://api.slack.com/events/hello
19:55 preaction ... yeah. i would not have ever guessed that
19:56 preaction but the module itself could fix that as well by emitting a "connected" event or something
19:58 Static3 What is the official/preferred way/technique to send back just a header (i.e. no body)
20:02 Static3 I notice that Mojo sends back a content-length:0 when sending back just a header, is there a way not to send this back ?
20:02 vicash Static3: you can use an after_render hook to remove the header
20:03 Static3 also, when sending hack just a header, it also sends a default content_type of text/html even if you delete that header before responding
20:03 preaction why would you not want to send back a content-length header?
20:03 jberger Static3: $c->rendered(200);
20:03 Static3 If there is no body, why give the length of 0
20:04 jberger and again, I would ASSUME that X-Sendfile is going to fix up the headers for you
20:04 preaction because it doesn't know that. because http has keep-alive
20:04 jberger preaction: this is an ongoing discussion of X-Sendfile so its a bit of an odd case
20:04 preaction also, you'd want http 204 No Content
20:04 preaction unless this is part of something different
20:04 preaction right
20:04 jberger sure, $c->rendered(204)
20:05 jberger though it seems like most examples I see are actually 200, so in that case $c->render(data => '', status => 200);
20:05 jberger because you have to render something for 200 in mojo
20:05 Static3 Well, whatever sendfile prefers, its readme does not mention anything
20:09 Static3 I thnk that $c->rendered(200) may have done it, I got back an expected weird image - chrome://global/skin/media/imagedoc-darknoise.png
20:10 Static3 then it said the image cannot be displayed because it contained errors ?, don't know what is sending this message (using FF)
20:11 Static3 The content-type received by FF from MOJO/Apache is now image/jpeg, so that means x-sendfile is doing something (I assume)
20:15 Static3 So, that error is FF, and its because the JPG is 0 bytes
20:17 jberger Static3: I'm out of answers for you
20:17 jberger perhaps someone else knows, but it might be time to get cozy with google
20:18 flow joined #mojo
20:20 flow hi you all.
20:21 flow I have made an interesting observation about Mojolicious' exception handling and before_render hooks.
20:23 flow that hook does not seem to be called when my sub in $r->under(sub { ... }) throws an exception.
20:24 flow can you confirm that?
20:24 preaction that sounds right to me: you haven't entered into the controller method yet, you're still figuring out where to route the request
20:24 preaction i mean, the code would know for sure
20:25 flow before_render hook couldn't call render() itself?
20:26 Grinnz no, before_render should still be called for an exception in an under
20:26 jberger the exception handler is in the outermost around_dispatch
20:26 jberger which means that it should be exactly the same for an under as an endpoint route handler
20:26 Grinnz in fact, that's what happens when someone tries to access pages without being logged in in our app
20:26 disputin joined #mojo
20:27 Grinnz before_render should definiteley not call render()
20:27 jabberwok Success! The systemd section from Toadfarm docs, along with modifying script/myapp with the path to actual (perlbrew) perl did the trick. Should the User= and Group= modifiers for the [Service] stanza also be in that Toadfarm doc, I wonder
20:28 flow my under-sub does something equivalent
20:30 flow but my before_render code is not run. It does not determine if it is an exception what is to render, preprocess it specially, and stuff everything in json => ... if it is a REST api request.
20:32 flow there is no much use in getting excessive html response to REST requests, even in development mode ;) this is why I am struggling to get it right.
20:33 Grinnz flow: are you going by the third example in https://metacpan.org/pod/Mojolicious::Guides::Rendering ?
20:35 flow yeah, #Rendering-exception-and-not_found-pages
20:36 Grinnz whoops, thats what i meant to link
20:38 flow you said: before_render should definiteley not call render(). I meant my under(sub {...}), sorry.
20:39 Grinnz it's fine if under calls render, as long as it returns false to stop the dispatch chain
20:48 flow tested: from endpoint controllers before_render() is called alright.
20:51 Static3 If setting the content-type to  say jpg in after_render, do I need to remove the existing text/html version first or will it overwrite
21:16 sri Static3: it appears you're doing a lot of weird stuff nobody understands
21:16 sri perhaps consider taking a step back and rethink what you're really trying to achieve
21:17 sri instead of trying random things
21:24 Static3 Just try to send a file, that may be updated/uploaded
21:24 Static3 or lots of them
21:24 purl lots of them are ducted fans.
21:24 Static3 Anyway, I got x-sendfile working
21:25 Static3 the combination of things that need to be done in mojo should be documented
21:25 Static3 because its not obvious
21:25 Static3 1st it seems that mojo must set the content-type of the file being served
21:26 Static3 this does not seem right to me, because one of the main reasons for using x-sendfile is to offload static files to apache
21:26 sri that's completely false
21:26 sri you're just doing weird stuff wrong
21:28 Static3 What weird stuff
21:29 sri don't let me stop you from "doing it your way", but please don't ask for it to get docs
21:30 Static3 Do you have an example, in which you offload static file serving to x-sendfile ?
21:31 sri nobody does that anymore these days
21:31 jberger I doubt anyone here has any example of that
21:31 jberger apache is pretty rare in these parts
21:31 jberger mostly nginx or haproxy
21:32 jberger sri: here's a quick summary
21:32 zivester joined #mojo
21:32 jberger Static3: is building assets from uploads and wants them cached in memory and served
21:32 Static3 jberget: did you not say yesterday that you used nginx with x-sendfile
21:32 lluad joined #mojo
21:32 jberger I use nginx with its thing like sendfile
21:32 sri oi! don't you ping me!
21:33 * sri pokes jberger
21:33 * jberger is shamed
21:34 jberger anyway, I convinced Static3 that trying to maintain an in-memory cache in each worker is crazy (because of invalidation) and so this came to be
21:34 jberger I still think this is likely a bunch of premature optimization
21:34 jberger but c'est la vie
21:34 Static3 ok, it not about optimization, its about functionality
21:35 flow thanks concerning the before_render / under(sub{}) issue
21:35 Static3 The only reason I'm using apache is to proxy, and only because I iabe multiple instances on the same server
21:35 flow haven't solved it, yet
21:35 jberger sure, having a reverse proxy is a good idea, though most of us use nginx rather than apache
21:35 Static3 preferably I'd like to use just hynotoad
21:35 jberger this isn't a bad thing
21:36 jberger but fine, you can use hypnotoad
21:36 flow but I am confronted with different misbehaviour
21:36 jberger it is very capable
21:36 * flow is lost in debugging, so to say.
21:36 jberger but application servers aren't a great way to serve static assets
21:37 Static3 hence, x-sendfile
21:37 Static3 sri, seems to be implying that I should not be taking this approach
21:38 Static3 I'm stuck at the moment as far as changes I can make, so little change is good right now
21:38 flow bye!
21:38 jberger flow: good luck
21:38 purl You'll need it.
21:38 Static3 x-sendfile, is (when it works) non-intrusive and solves the problem
21:39 Static3 I have another question, concerning the flow of events thru the various hooks
21:40 Static3 is there any visual diagrams showing the flows of hooks,
21:40 jberger no, they are described in the documentation for Mojolicious.pm
21:40 Static3 for example, I notice that various actions cause various hooks to be by-passed or not executed
21:41 preaction x-sendfile was built for optimization though. the idea is the kernel takes over writing the file to the socket. if you don't want the optimization, just write the file yourself
21:42 jberger preaction: the other issue is that Static3 wants the application to handle access control
21:42 jberger which is the other useful feature of X-Sendfile and X-Accel-Redirect
21:43 preaction but if you just want access control, write the file yourself.
21:43 preaction that's not a feature of those at all
21:43 jberger personally I think Static3 is on the right track going in this direction, but it is going to take some exploration
21:43 Static3 Well I do have it working now
21:43 Static3 There was a few unexpected things,
21:44 Static3 for example, I have to specify the absolute path in MOJO, which I don't like
21:44 Static3 because I'd like to move those resources without changing code
21:44 preaction x-sendfile exists because usually a general-purpose, buffered-reading programming language is slower than the kernel at moving bytes between two filehandles. optimization
21:45 Static3 In my case all my fails are pre compressed /zipped, minified etc.. so when a request is made I just push data out
21:45 jberger Static3: I see that in ruby land they invented a header X-Accel-Mapping which they use to relocate the file from absolute on the system to absolute on the web server
21:45 jberger *files
21:45 Static3 My machine has TB of RAM and 128 CPUs
21:46 Static3 so trust me, I dont' care about speed, I've got that
21:46 jberger so why are you so concerned with the in memory caching?
21:46 jberger filesystem access?
21:46 Static3 because it is very dynamic
21:47 jberger you just said they are pre-build assets (yes you add them over time) but still pre-built
21:47 jberger that's not very dynamic in an application server kinda way
21:48 sri doesn't the linux page cache already keep the commonly accessed files in memory?
21:48 Static3 but obviously some areas of namespace are dynamic, so NMAP / IPC or filesystem is needed
21:49 jberger Static3: I think I need to step away too, I've given you all the help I can
21:49 jberger whether any of it has been of value is up to you to decide
21:49 jberger perhaps your first solution is fine, though I don't know how you are going to sync your cache
21:49 sri i feel like you're inveting problems, when a lot of this just works already if you let it
21:49 Static3 Thanks jberger, I really do appreciate our help and advice.
21:49 jberger np
21:50 vicash Static3: maybe you should profile it first to see where the slow stuff is
21:50 Static3 sri: the static file server does gzip, or I would use that
21:51 sri dynamic gzip is total garbage
21:51 Static3 That's what I starting asking first today, after concluding the x-sendfile was going to take to much time
21:51 sri it does not make sense if the load on the server is as heavy as you claim
21:52 sri you always gzip in advance, once, and store the compressed file
21:52 Static3 I don't dynamic gzip,
21:52 sri ok, i give up too
21:52 Static3 I gzip eveything up i.e. pregzip, so when a client wants it, its just send
21:53 sri static file servers don't pregzip, you're talking gibberish to me
21:54 Static3 No, you are misunderstanding what I am say and my requirement
21:54 Static3 Is it a reasonable request/requirement to have a static file server gzip content upon request.?
21:55 Static3 will, the mojo static file server cannot do this
21:55 Static3 This is the root cause of my problem
21:55 Static3 There may well be many reason by it does not, but that does not change my requirement
21:57 Static3 Anyway, I sorry for taking so much of your time and I am aware that almost everything I do does not make much sense to anybody.
21:57 sri allright, i want to talk about other stuff again :)
21:57 sri wqhd or uhd monitors?
21:58 preaction whichever one looks picture-perfect for one of these: http://www.instructables.com/id/Digital-Pinball-Machine/
21:58 sri lol
22:01 sri wqhd looks so nice http://imgur.com/bNddJB7
22:02 sri but the pixel density is so low
22:03 Grinnz a pokeball numpad
22:03 Grinnz amazing
22:03 jberger a friend built this, not the best picture but you get the idea
22:03 jberger http://imgur.com/a/84b6p
22:03 jberger the woodwork is stunning
22:07 sri suppose wqhd is better for windows and linux, where scaling mostly sucks
22:07 sri (although windows 10 is not too bad on the retina macbook)
22:52 polettix joined #mojo
22:54 lluad joined #mojo
23:18 disputin joined #mojo
23:27 zivester joined #mojo

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary