RE: [Catalyst] Using URIs for my app in another program
Tomas Doran wrote on 2008-06-06: On 7 Jun 2008, at 01:17, Byron Young wrote: Is there any way to fake a request when my app starts? It seems like a bit of a catch-22 -- I need to know a URL in order to fake the request, but in order to generate the URL I need to have a request... The problem which you have here is that the application doesn't know what URLs it's attached to until run time. Remember - you can have multiple virtual hosts pointing to the same application instance, therefore catalyst *can't* know in advance where it is going to be served from. True. All I need to know in this case is just one valid URL, though. The simple perl HTTP engine which script/myapp_server.pl uses prints a nice message with the app URL - but that's because it's a toy compared to what you might do in real deployment. Am I doomed to storing the URL for my 'populate database with urls' action in a config file and updating it by hand when I move the web app? I think so, but I think that you *want* to do this. Otherwise, how do you deal with testing the app? And also testing your thing which requests the app. Surely you're gonna want to be able to test against demo servers you've brought up on localhost? Actually, that's specifically the use case I'm thinking of here. Each developer on this project has his own testing setup on the dev machine, while the production version runs on another host. Each test setup includes a database, daemon, and web app. We do use config files to point everything to the right codebase and database, so it's not the end of the world to add another entry for the url, but I try to be careful of the amount of configuration we need. I want to avoid the situation where a developer forgets to change his dev config file to point to his dev web app and so his daemon ends up talking to the production server instead, potentially resulting in something bad happening. So, if there is some totally automated way to do things instead, I opt for that. Of course, this may just be exposing some bad practices on our end wrt to dev environments and config files and protecting the production server from fallible developers such as myself. I think that you're trying to solve the wrong problem here, sorry. To be honest - how often are you really going to move the webapp once it's deployed? What's wrong with giving it it's own DNS CNAME which you switch between boxen hosting it? Yeah, that's true - we probably won't move the production app, and we'll use a CNAME if we do. Thanks for your help Byron Cheers Tom ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using URIs for my app in another program
The most straightforward method I can think of is to factor out the URIs to a common config file. You can have your daemon read in the config file and generate URIs from that. Your Catalyst application can either continue to use base to generate URIs or you can generate some special URIs from the config file as well. The problem with having your daemon load up Catalyst to generate a URI is that I'm not sure how that would work. Catalyst generates URIs given a HTTP request. No HTTP request, no base URI. Another safety measure is that you can have your Catalyst appl do a sanity check against the URI config file to make sure it doesn't become out of date (maybe a startup test request). Rob On Thu, May 1, 2008 at 2:27 PM, Byron Young [EMAIL PROTECTED] wrote: Hi all I've run into a situation that I can't find a good solution to and am hoping to solicit some ideas from people on the list here. An app I've been working on consists of two main parts - a Catalyst-based web app which provides the UI, and a daemon that does the heavy lifting. They are totally separate applications that talk to one another via database. The daemon will sometimes send emails to users when it finishes certain tasks that the users are interested in, and I want to include links in the emails that would bring the user to a Results page on the web app where they can get more information about the result of the task. So, what I would like is to be able to call $c-uri_for() from my daemon. Is there any 'sanctioned' way of doing that? If possible, I'd like to avoid loading my whole catalyst app and somehow tricking it into believing its running under the same environment as my real app. Another option is to use the database to pass URIs around. Maybe a URI table that maps finished tasks to URIs. However, I would rather just be able to arbitrarily call $c-uri_for() whenever I decide I need to include a URI in my daemon instead of having to create a table or column whenever I decide I want to send a link to a new type of resource. Any suggestions? Maybe I'm just going about it all wrong? Thanks! Byron ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Using URIs for my app in another program
Ah, right, I need a HTTP request to get base. I wasn't thinking straight about that. I think storing links in the database is what I'll do, because that leaves the responsibility of generating URIs solely with the catalyst app. If I refactor code or move things around I don't want to have to update my daemon at all. Thanks for your feedback, Robert. Byron From: Robert Krimen [mailto:[EMAIL PROTECTED] Sent: Thursday, May 01, 2008 3:34 PM To: The elegant MVC web framework Subject: Re: [Catalyst] Using URIs for my app in another program The most straightforward method I can think of is to factor out the URIs to a common config file. You can have your daemon read in the config file and generate URIs from that. Your Catalyst application can either continue to use base to generate URIs or you can generate some special URIs from the config file as well. The problem with having your daemon load up Catalyst to generate a URI is that I'm not sure how that would work. Catalyst generates URIs given a HTTP request. No HTTP request, no base URI. Another safety measure is that you can have your Catalyst appl do a sanity check against the URI config file to make sure it doesn't become out of date (maybe a startup test request). Rob On Thu, May 1, 2008 at 2:27 PM, Byron Young [EMAIL PROTECTED]mailto:[EMAIL PROTECTED] wrote: Hi all I've run into a situation that I can't find a good solution to and am hoping to solicit some ideas from people on the list here. An app I've been working on consists of two main parts - a Catalyst-based web app which provides the UI, and a daemon that does the heavy lifting. They are totally separate applications that talk to one another via database. The daemon will sometimes send emails to users when it finishes certain tasks that the users are interested in, and I want to include links in the emails that would bring the user to a Results page on the web app where they can get more information about the result of the task. So, what I would like is to be able to call $c-uri_for() from my daemon. Is there any 'sanctioned' way of doing that? If possible, I'd like to avoid loading my whole catalyst app and somehow tricking it into believing its running under the same environment as my real app. Another option is to use the database to pass URIs around. Maybe a URI table that maps finished tasks to URIs. However, I would rather just be able to arbitrarily call $c-uri_for() whenever I decide I need to include a URI in my daemon instead of having to create a table or column whenever I decide I want to send a link to a new type of resource. Any suggestions? Maybe I'm just going about it all wrong? Thanks! Byron ___ List: Catalyst@lists.scsys.co.ukmailto:Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using URIs for my app in another program
On Thu, May 1, 2008 at 4:00 PM, Byron Young [EMAIL PROTECTED] wrote: Ah, right, I need a HTTP request to get base. I wasn't thinking straight about that. I think storing links in the database is what I'll do, because that leaves the responsibility of generating URIs solely with the catalyst app. If I refactor code or move things around I don't want to have to update my daemon at all. Thanks for your feedback, Robert. Another option is to use a distributed cache system like memcached. Pretty easy to setup, and then you can have a warm cache action that populates the configured URIs in the cache. So, your daemon queries cache, if it comes up empty then make a call out to the app to generate the URLs and stuff them in cache. -J ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Using URIs for my app in another program
J. Shirley wrote on 2008-05-01: On Thu, May 1, 2008 at 4:00 PM, Byron Young [EMAIL PROTECTED] wrote: Ah, right, I need a HTTP request to get base. I wasn't thinking straight about that. I think storing links in the database is what I'll do, because that leaves the responsibility of generating URIs solely with the catalyst app. If I refactor code or move things around I don't want to have to update my daemon at all. Thanks for your feedback, Robert. Another option is to use a distributed cache system like memcached. Pretty easy to setup, and then you can have a warm cache action that populates the configured URIs in the cache. So, your daemon queries cache, if it comes up empty then make a call out to the app to generate the URLs and stuff them in cache. -J Hey J. Yes, that could work too, but it requires making a call to the catalyst app, which means at least one hard-coded url will be in the daemon. I considered having a page on my app that would just serve up a requested url, which is similar to your proposal, but I'd rather avoid hard-coding any urls in the daemon. Thanks for the suggestion. byron ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Using URIs for my app in another program
On Thu, May 1, 2008 at 4:53 PM, Byron Young [EMAIL PROTECTED] wrote: Hey J. Yes, that could work too, but it requires making a call to the catalyst app, which means at least one hard-coded url will be in the daemon. I considered having a page on my app that would just serve up a requested url, which is similar to your proposal, but I'd rather avoid hard-coding any urls in the daemon. Thanks for the suggestion. Not necessarily hard-coded; you can store that either A) in the daemon config, B) with the jobs that are sent in or C) in the DB somewhere. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/