Use of PageRenderLinkSource in a scheduled job

2013-09-06 Thread Nathan Quirynen

Hi,

I added a scheduled job to my Tapestry application, where I want to 
daily check if there are new tickets and send a mail to people assigned 
to these tickets.

So I've added it in AppModule as following:

@Startup
public static void scheduleJobs(
PeriodicExecutor executor,
final MailService mailService) {

executor.addJob(
new CronSchedule(* 8 * * * ?),
Cleanup Job,
new Runnable() {
@Override
public void run() {
mailService.mailNewTickets(now().minusHours(24));
}
});
}

This works perfect. Only I want to add links to the ticket detail page 
in these mails.
So I injected PageRenderLinkSource in my MailService class to create 
links with context:


pageRenderLinkSource.createPageRenderLinkWithContext(TicketDetails.class, 
ticket.getId()).toAbsoluteURI(true);

But this is not working as the scheduled job stops there. I don't see 
the exception thrown, probably because it's in another thread?
Maybe this is expected behaviour (Request not available?), but I don't 
know how to create the links otherwise besides using a hard coded string 
and concatenating the context.


Nathan


-
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Use of PageRenderLinkSource in a scheduled job

2013-09-06 Thread Lance Java
To generate a link, you need a request… so I suggest you do one of the
following

1. Use cron and wget to hit your app via a http request instead of a
@Startup job inside your app
2. Generate the link at some point in time when you have a
HTTPServletRequest and save it for later
3. Use a @Symbol for the base URL and generate the link yourself

NB. I started a project where you could render tapestry-templates offline
but never finished or tested it… it's nearly done

https://github.com/uklance/tapestry-offline

The idea was to generate a fake request where half the request was sourced
from an overridable global service and the other half was a runtime value.

https://github.com/uklance/tapestry-offline/blob/master/src/main/java/org/lazan/t5/offline/services/OfflineComponentRenderer.java
https://github.com/uklance/tapestry-offline/blob/master/src/main/java/org/lazan/t5/offline/services/OfflineRequestGlobals.java
https://github.com/uklance/tapestry-offline/blob/master/src/main/java/org/lazan/t5/offline/OfflineRequestContext.java

If there's enough interest in this… I'll resurrect the project and finish
it off.


Re: Use of PageRenderLinkSource in a scheduled job

2013-09-06 Thread Barry Books
I make all of my batch jobs Tapestry pages and use Hudson scheduled tasks
to access them. This give you more control, job history and email
notifications on failure. Since the jobs are just pages you can just go to
them to debug them and things like PageRenderLinkSource work as you would
expect. I run thousands of jobs this way every day. The history and
notifications alone are worth it and you can even build/deploy your
application with it.


On Fri, Sep 6, 2013 at 3:12 AM, Nathan Quirynen nat...@pensionarchitects.be
 wrote:

 Hi,

 I added a scheduled job to my Tapestry application, where I want to daily
 check if there are new tickets and send a mail to people assigned to these
 tickets.
 So I've added it in AppModule as following:

 @Startup
 public static void scheduleJobs(
 PeriodicExecutor executor,
 final MailService mailService) {

 executor.addJob(
 new CronSchedule(* 8 * * * ?),
 Cleanup Job,
 new Runnable() {
 @Override
 public void run() {
 mailService.mailNewTickets(**now().minusHours(24));
 }
 });
 }

 This works perfect. Only I want to add links to the ticket detail page in
 these mails.
 So I injected PageRenderLinkSource in my MailService class to create links
 with context:

 pageRenderLinkSource.**createPageRenderLinkWithContex**t(TicketDetails.class,
 ticket.getId()).toAbsoluteURI(**true);

 But this is not working as the scheduled job stops there. I don't see the
 exception thrown, probably because it's in another thread?
 Maybe this is expected behaviour (Request not available?), but I don't
 know how to create the links otherwise besides using a hard coded string
 and concatenating the context.

 Nathan


 --**--**-
 To unsubscribe, e-mail: 
 users-unsubscribe@tapestry.**apache.orgusers-unsubscr...@tapestry.apache.org
 For additional commands, e-mail: users-h...@tapestry.apache.org




Re: Use of PageRenderLinkSource in a scheduled job

2013-09-06 Thread Martin Kersten
Thanks barry,

this is a good advice. I will give it a try :)


Cheers,

Martin (Kersten)


2013/9/6 Barry Books trs...@gmail.com

 I make all of my batch jobs Tapestry pages and use Hudson scheduled tasks
 to access them. This give you more control, job history and email
 notifications on failure. Since the jobs are just pages you can just go to
 them to debug them and things like PageRenderLinkSource work as you would
 expect. I run thousands of jobs this way every day. The history and
 notifications alone are worth it and you can even build/deploy your
 application with it.


 On Fri, Sep 6, 2013 at 3:12 AM, Nathan Quirynen 
 nat...@pensionarchitects.be
  wrote:

  Hi,
 
  I added a scheduled job to my Tapestry application, where I want to daily
  check if there are new tickets and send a mail to people assigned to
 these
  tickets.
  So I've added it in AppModule as following:
 
  @Startup
  public static void scheduleJobs(
  PeriodicExecutor executor,
  final MailService mailService) {
 
  executor.addJob(
  new CronSchedule(* 8 * * * ?),
  Cleanup Job,
  new Runnable() {
  @Override
  public void run() {
  mailService.mailNewTickets(**now().minusHours(24));
  }
  });
  }
 
  This works perfect. Only I want to add links to the ticket detail page in
  these mails.
  So I injected PageRenderLinkSource in my MailService class to create
 links
  with context:
 
 
 pageRenderLinkSource.**createPageRenderLinkWithContex**t(TicketDetails.class,
  ticket.getId()).toAbsoluteURI(**true);
 
  But this is not working as the scheduled job stops there. I don't see the
  exception thrown, probably because it's in another thread?
  Maybe this is expected behaviour (Request not available?), but I don't
  know how to create the links otherwise besides using a hard coded string
  and concatenating the context.
 
  Nathan
 
 
  --**--**-
  To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org
 users-unsubscr...@tapestry.apache.org
  For additional commands, e-mail: users-h...@tapestry.apache.org
 
 



Re: Use of PageRenderLinkSource in a scheduled job

2013-09-06 Thread Kalle Korhonen
On Fri, Sep 6, 2013 at 2:03 AM, Lance Java lance.j...@googlemail.comwrote:

 To generate a link, you need a request… so I suggest you do one of the
 following


You only need the request to find out where your service is if you haven't
explicitly specified a hostname. If you have, PageRenderLinkSource uses the
HOSTNAME symbol instead of trying to obtain it from the request (which is
unreliable).

Kalle