Skip to content

Commit

Permalink
Merge pull request #596 from spagalloco/tasks-documentation
Browse files Browse the repository at this point in the history
added documentation for tasks
  • Loading branch information
mveitas committed May 24, 2014
2 parents 53a5606 + 8865c9d commit 48a41c8
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion docs/source/manual/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,29 @@ All Dropwizard applications start with the ``gc`` task, which explicitly trigger
collection. (This is useful, for example, for running full garbage collections during off-peak times
or while the given application is out of rotation.) The execute method of a ``Task`` can be annotated
with ``@Timed``, ``@Metered``, and ``@ExceptionMetered``. Dropwizard will automatically
record runtime information about your tasks.
record runtime information about your tasks. Here's a basic task class:
.. code-block:: java
public class TruncateDatabaseTask extends Task {
private final Database database;
public TruncateDatabaseTask(Database database) {
super('truncate');
this.database = database;
}
@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
this.database.truncate();
}
}
You can then add this task to your application's environment:
.. code-block:: java
environment.admin().addTask(new TruncateDatabaseTask(database));
Running a task can be done by sending a ``POST`` request to ``/tasks/{task-name}`` on the admin
port. For example::
Expand Down

0 comments on commit 48a41c8

Please sign in to comment.