Server Tags
Server Tags allow you to filter jobs by certain tags so that they are only run on specific servers.
Do you have some jobs that can only be run on certain servers (e.g. jobs tied to a specific OS like Linux, Max and Windows)? Or do you want to run a job only on the server that created the job? JobRunr has you covered with Server Tags!
A BackgroundJobServer
can have multiple server tags and a job can specify only one server tag via the Job annotation. If the server tag of the job matches any of the server tags of the server, the server is eligible to run the job.
Each
BackgroundJobServer
and eachJob
is by default tagged with theDEFAULT
tag - this makes sure that if you do not specify a tag on theJob
, it gets executed anyway.
Usage via @Job
annotation
Using server tags is as easy as using Queues, again thanks to the Job
annotation. Just add it to your service method and specify on which server your background job should run.
Usage via JobBuilder
pattern
When you are using the JobBuilder
pattern, you can pass the serverTag via the JobBuilder
.
Run job on the server that created the job
A special server tag is available to run a job on the server that created that same job. This comes in handy when you want to run a job that uses a resource (like a file, …) that is only available on the server that created the job.
In that case, you can use the following:
Configuration
Configuration is easy, both in the fluent api and using Spring configuration:
Fluent Api
Using the fluent API, pass all the server tags as Strings (or string constants) to the BackgroundJobServerConfiguration
.
Spring configuration
For the Spring configuration, you can use the org.jobrunr.background-job-server.tags
property to set the different server tags.