{"id":20718496,"url":"https://github.com/knowm/dropwizard-sundial","last_synced_at":"2025-04-23T14:13:15.735Z","repository":{"id":27660401,"uuid":"31146064","full_name":"knowm/dropwizard-sundial","owner":"knowm","description":"Scheduled jobs in dropwizard","archived":false,"fork":false,"pushed_at":"2024-04-19T12:32:32.000Z","size":206,"stargazers_count":35,"open_issues_count":6,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-05-19T05:40:15.491Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knowm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2015-02-21T23:52:37.000Z","updated_at":"2024-04-18T17:23:59.000Z","dependencies_parsed_at":"2024-04-18T18:37:49.718Z","dependency_job_id":"8b7d6378-0f17-40a0-af70-0a08c9a630a1","html_url":"https://github.com/knowm/dropwizard-sundial","commit_stats":null,"previous_names":["timmolter/dropwizard-sundial"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowm%2Fdropwizard-sundial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowm%2Fdropwizard-sundial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowm%2Fdropwizard-sundial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowm%2Fdropwizard-sundial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knowm","download_url":"https://codeload.github.com/knowm/dropwizard-sundial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224992998,"owners_count":17403944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T03:13:51.380Z","updated_at":"2024-11-17T03:13:51.786Z","avatar_url":"https://github.com/knowm.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## dropwizard-sundial\n\nScheduled jobs in [Dropwizard](https://github.com/dropwizard/dropwizard) using [Sundial](https://github.com/knowm/Sundial), a quartz fork.\n\n## Note!!!\n\nBefore version `1.0.0-rc2.0`, you'll need to add the following lines to your `Application`'s `run()` method. From the 1.0.0-rc2.0 release and onwards, it will be automatically configured, but before that you need to explicitly add all the tasks yourself! \n\n```java\nenvironment.admin().addTask(new LockSundialSchedulerTask());\nenvironment.admin().addTask(new UnlockSundialSchedulerTask());\nenvironment.admin().addTask(new RemoveJobTriggerTask());\nenvironment.admin().addTask(new AddCronJobTriggerTask());\nenvironment.admin().addTask(new StartJobTask());\nenvironment.admin().addTask(new StopJobTask());\nenvironment.admin().addTask(new RemoveJobTask());\nenvironment.admin().addTask(new AddJobTask());\n```\n\nTo enable only some of the tasks, list the tasks you want enabled in the\n`tasks` configuration setting. If left unset, all tasks are enabled.\n\n## In a Nutshell\n\nSundial makes adding scheduled jobs to your Java application a walk in the park. Simply define jobs, define triggers, and start the Sundial scheduler. **dropwizard-sundial** makes integrating and configuring the job scheduler into dropwizard a snap.\n\n## Adding the dropwizard-sundial dependency\n\nAdd the **dropwizard-sundial** library as a dependency to your `pom.xml` file:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.knowm\u003c/groupId\u003e\n    \u003cartifactId\u003edropwizard-sundial\u003c/artifactId\u003e\n    \u003cversion\u003e4.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Adding and configuring the **dropwizard-sundial** bundle\n\nAdd the Sundial bundle to the Dropwizard environment:\n\n```java\npublic void initialize(Bootstrap\u003cMyApplicationConfiguration\u003e bootstrap) {\n\n  bootstrap.addBundle(new SundialBundle\u003cMyApplicationConfiguration\u003e() {\n\n    @Override\n    public SundialConfiguration getSundialConfiguration(MyApplicationConfiguration configuration) {\n      return configuration.getSundialConfiguration();\n    }\n  });\n}\n```\n\n## Add the 'SundialConfiguration' to your application configuration class (`MyApplicationConfiguration`):\n```java\n@Valid\n@NotNull\npublic SundialConfiguration sundialConfiguration = new SundialConfiguration();\n\n@JsonProperty(\"sundial\")\npublic SundialConfiguration getSundialConfiguration() {\n\n  return sundialConfiguration;\n}\n```\n\n## Edit you app's Dropwizard YAML config file (default values are shown below except for `annotated-jobs-package-name` and `tasks`):\n```yml\nsundial:\n  thread-pool-size: 10\n  shutdown-on-unload: true\n  start-delay-seconds: 0\n  start-scheduler-on-load: true\n  global-lock-on-load: false\n  annotated-jobs-package-name: com.foo.bar.jobs\n  tasks: [startjob, stopjob]\n```\n\n## Configure package name for `Job` classes containing `CronTrigger` and `SimpleTrigger` annotations:\n```yml\nsundial:\n  annotated-jobs-package-name: com.foo.bar.jobs\n```\n## Create a Job Class\n\n```java\npublic class SampleJob extends org.knowm.sundial.Job {\n\n  @Override\n  public void doRun() throws JobInterruptException {\n    // Do something interesting...\n  }\n}\n```\n##  ...with CronTrigger or SimpleTrigger Annotation\n```java\n@CronTrigger(cron = \"0/5 * * * * ?\")\n```\n```java\n@SimpleTrigger(repeatInterval = 30, timeUnit = TimeUnit.SECONDS)\n```\n## Alternatively, Put an XML File Called jobs.xml on Classpath\n\nIf adding jobs and triggers this way, you should not use annotations.\n\n```xml\n\u003c?xml version='1.0' encoding='utf-8'?\u003e\n\u003cjob-scheduling-data\u003e\n\n\t\u003cschedule\u003e\n\n\t\t\u003c!-- job with cron trigger --\u003e\n\t\t\u003cjob\u003e\n\t\t\t\u003cname\u003eSampleJob3\u003c/name\u003e\n\t\t\t\u003cjob-class\u003ecom.foo.bar.jobs.SampleJob3\u003c/job-class\u003e\n\t\t\t\u003cconcurrency-allowed\u003etrue\u003c/concurrency-allowed\u003e\n\t\t\u003c/job\u003e\n\t\t\u003ctrigger\u003e\n\t\t\t\u003ccron\u003e\n\t\t\t\t\u003cname\u003eSampleJob3-Trigger\u003c/name\u003e\n\t\t\t\t\u003cjob-name\u003eSampleJob3\u003c/job-name\u003e\n\t\t\t\t\u003ccron-expression\u003e*/15 * * * * ?\u003c/cron-expression\u003e\n\t\t\t\u003c/cron\u003e\n\t\t\u003c/trigger\u003e\n\n\t\t\u003c!-- job with simple trigger --\u003e\n\t\t\u003cjob\u003e\n\t\t\t\u003cname\u003eSampleJob2\u003c/name\u003e\n\t\t\t\u003cjob-class\u003ecom.foo.bar.jobs.SampleJob2\u003c/job-class\u003e\n\t\t\t\u003cjob-data-map\u003e\n\t\t\t\t\u003centry\u003e\n\t\t\t\t\t\u003ckey\u003eMyParam\u003c/key\u003e\n\t\t\t\t\t\u003cvalue\u003e42\u003c/value\u003e\n\t\t\t\t\u003c/entry\u003e\n\t\t\t\u003c/job-data-map\u003e\n\t\t\u003c/job\u003e\n\t\t\u003ctrigger\u003e\n\t\t\t\u003csimple\u003e\n\t\t\t\t\u003cname\u003eSampleJob2-Trigger\u003c/name\u003e\n\t\t\t\t\u003cjob-name\u003eSampleJob2\u003c/job-name\u003e\n\t\t\t\t\u003crepeat-count\u003e5\u003c/repeat-count\u003e\n\t\t\t\t\u003crepeat-interval\u003e5000\u003c/repeat-interval\u003e\n\t\t\t\u003c/simple\u003e\n\t\t\u003c/trigger\u003e\n\n\t\u003c/schedule\u003e\n\n\u003c/job-scheduling-data\u003e\n```\n\n### Inject Global Objects or Config Parameters into a Job\n\nYou may want access to a global object such as a REST client, and you don't want to have to reinstantiate that object every single time the job is run. It can be done quite easily by \nputting the object in the ServletContext during app startup in the `run` method. Since Sundial is bound to the ServletContext's lifecycle, it has direct access to the ServletContext. \nThe ServletContext has a `String, Object` map for holding these global objects. The following code snippets show how to add an object to the ServletContext in the dropwizard `run` method and how \nto access it from a job.\n\n```java\n@Override\npublic void run(XDropWizardApplicationConfiguration configuration, Environment environment) throws Exception {\n\n  logger.info(\"running DropWizard!\");\n\n  // Add object to ServletContext for accessing from Sundial Jobs\n  environment.getApplicationContext().setAttribute(\"MyKey\", \"MyObject\");\n    \n  ...\n}\n```\n\n```java\n@CronTrigger(cron = \"0/25 * * * * ?\")\npublic class MyJob extends Job {\n\n  private final Logger logger = LoggerFactory.getLogger(MyJob.class);\n\n  @Override\n  public void doRun() throws JobInterruptException {\n\n    // pull object from ServletContext, which was added in the application's run method\n    String myObject = (String) SundialJobScheduler.getServletContext().getAttribute(\"MyKey\");\n\n    logger.info(\"MyJob says: \" + myObject);\n  }\n}\n```\n\n## Control Scheduler asynchronously via Curl\n\n```bash\ncurl -X POST http://localhost:9090/admin/tasks/locksundialscheduler\ncurl -X POST http://localhost:9090/admin/tasks/unlocksundialscheduler\ncurl -X POST \"http://localhost:9090/admin/tasks/startjob?JOB_NAME=MyJob\"\ncurl -X POST \"http://localhost:9090/admin/tasks/startjob?JOB_NAME=SampleJob3\u0026MyParam=9999\"\ncurl -X POST \"http://localhost:9090/admin/tasks/stopjob?JOB_NAME=SampleJob3\"\ncurl -X POST \"http://localhost:9090/admin/tasks/removejob?JOB_NAME=SampleJob3\"\ncurl -X POST \"http://localhost:9090/admin/tasks/addjob?JOB_NAME=SampleJob3\u0026JOB_CLASS=org.knowm.xdropwizard.jobs.SampleJob3\u0026MyParam=888\"\ncurl -X POST http://localhost:9090/admin/tasks/removejobtrigger?TRIGGER_NAME=SampleJob3-Trigger\ncurl -X POST \"http://localhost:9090/admin/tasks/addcronjobtrigger?TRIGGER_NAME=SampleJob3-Trigger\u0026JOB_NAME=SampleJob3\u0026CRON_EXPRESSION=0/45%20*%20*%20*%20*%20?\"\ncurl -X POST \"http://localhost:9090/admin/tasks/addcronjobtrigger?TRIGGER_NAME=SampleJob3-Trigger\u0026JOB_NAME=SampleJob3\" --data-urlencode \"CRON_EXPRESSION=0/45 * * * * ?\"\n```\n\n## Learn\n\nVisit [Sundial](https://github.com/timmolter/Sundial) to find out more about the scheduler itself and [XDropWizard](https://github.com/timmolter/XDropWizard) to see a working example of a DropWizard app integrating Sundial via the `dropwizard-sundial` project.\n\n![Screenshot of Dashboard](https://raw.githubusercontent.com/timmolter/XDropWizard/master/etc/xdropwizard.png)\n\n\n## Continuous Integration\n[![Build Status](https://travis-ci.org/knowm/dropwizard-sundial.png?branch=master)](https://travis-ci.org/timmolter/dropwizard-sundial.png)  \n[Build History](https://travis-ci.org/knowm/dropwizard-sundial/builds)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowm%2Fdropwizard-sundial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknowm%2Fdropwizard-sundial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowm%2Fdropwizard-sundial/lists"}