[ANN] dropwizard-sundial - scheduled jobs (interval and cron) for dropwizard

432 views
Skip to first unread message

Tim Molter

unread,
Mar 4, 2015, 9:04:30 AM3/4/15
to dropwiz...@googlegroups.com
I've recently released a project called dropwizard-sundial, which nicely integrates Sundial into a Dropwizard app, adding many new convenient features. With [dropwizard-sundial](https://github.com/timmolter/dropwizard-sundial), you can easily integrate the lightweight multi-threaded Java job scheduling library, [Sundial](https://github.com/timmolter/Sundial), and add Jobs either using a `SimpleTrigger` or a `CronTrigger`. First, you'd start out with a class defining your job logic with a `SimpleTrigger` annotation: 


    @SimpleTrigger(repeatInterval = 60, timeUnit = TimeUnit.SECONDS)    
    
public class SampleJob extends com.xeiam.sundial.Job {
        
      
@Override
      
public void doRun() throws JobInterruptException {
        
// Do something interesting...
      
}
    
}



A `CronTrigger` annotation is also available (@CronTrigger(cron = "0/5 * * * * ?")). In your Dropwizard app's `yaml` file, you'll need to define what package `dropwizard-sundial` should search for annotated job classes. Following is an example config with the `annotated-jobs-package-name` config param along with several other optional params for fine-tuning the scheduler:

    sundial:
      thread
-pool-size: 10
      shutdown
-on-unload: true
      wait
-on-shutdown: false
      start
-delay-seconds: 0
      start
-scheduler-on-load: true
      
global-lock-on-load: false
      annotated
-jobs-package-name: com.foo.bar.jobs


Additionally, you can control the scheduler asynchronously via Curl while the app is running to do things like locking and unlocking the scheduler, starting, stopping, adding, removing jobs and triggers. Here are a few examples:

    curl -X POST http://localhost:9090/admin/tasks/locksundialscheduler
    curl 
-X POST http://localhost:9090/admin/tasks/unlocksundialscheduler
    curl 
-X POST "http://localhost:9090/admin/tasks/startjob?JOB_NAME=MyJob"

Instructions for integration as well as more features can be found in the project's README. Enjoy!

Carlo Barbara

unread,
Mar 4, 2015, 9:26:07 AM3/4/15
to dropwiz...@googlegroups.com
Thanks for sharing!

--
You received this message because you are subscribed to the Google Groups "dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dropwizard-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

André Ricardo

unread,
Aug 14, 2015, 7:01:40 AM8/14/15
to dropwizard-user
In dropwizard-sundial is there a way to access the PrintWriter output as I do in a Dropwizard Task?

@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
    output
.println("task executing");
}

dropwizard-sundial

@Override
public void doRun() throws JobInterruptException {

   
output.println("pinnnng job is executing"); // How do I do this?
}

Thanks!

André Ricardo

unread,
Aug 14, 2015, 7:20:07 AM8/14/15
to dropwizard-user
I have managed to do what I wanted by using the Logger and passing DAO objects via ServletContext but I am not sure this is the correct aproach, anyone care to comment?

@SimpleTrigger(repeatInterval = 5, timeUnit = TimeUnit.SECONDS)
public class WordOfTheDayJob extends Job {

   
private final Logger logger = LoggerFactory.getLogger(WordOfTheDayJob.class);


   
@Override
   
public void doRun() throws JobInterruptException {

        logger
.info("pinnnng");

       
DictionaryDAO daoDA = (DictionaryDAO) SundialJobScheduler.getServletContext().getAttribute("daoDA");

       
WordResource wordResource = new WordResource(daoDA);
       
Word word = wordResource.wordOfTheDay();
        logger
.info("Word of the day: " + word.getNormalized());
   
}
}



On Wednesday, March 4, 2015 at 2:04:30 PM UTC, Tim Molter wrote:

Tim Molter

unread,
Aug 16, 2015, 2:26:00 PM8/16/15
to dropwizard-user
Reply all
Reply to author
Forward
0 new messages