Skip to content

Instantly share code, notes, and snippets.

@os890
Last active December 31, 2015 13:08
Show Gist options
  • Save os890/7990494 to your computer and use it in GitHub Desktop.
Save os890/7990494 to your computer and use it in GitHub Desktop.
@ApplicationScoped
public class ProjectStageAwareSchedulerController
{
@Inject
private Scheduler<Job> jobScheduler;
@Inject
private ProjectStage projectStage;
public void registerJobs()
{
if (ProjectStage.Production.equals(this.projectStage))
{
//see 'false' for @Scheduled#onStartup
this.jobScheduler.scheduleJob(ManualCdiAwareQuartzJob.class);
}
}
@Scheduled(cronExpression = "0 0/10 * * * ?", onStartup = false)
public class ManualCdiAwareQuartzJob implements org.quartz.Job
{
@Inject
private MyService service;
@Override
public void execute(JobExecutionContext context)
throws JobExecutionException
{
//...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment