Skip to content

Instantly share code, notes, and snippets.

@yusuke
Created December 15, 2011 15:06
Show Gist options
  • Save yusuke/1481409 to your computer and use it in GitHub Desktop.
Save yusuke/1481409 to your computer and use it in GitHub Desktop.
/*
Copyright (C) 2011 Yusuke Yamamoto
Licensed under the Apache License, Version 2.0 (the "License");
http://www.apache.org/licenses/LICENSE-2.0
*/
import org.quartz.*
import org.quartz.impl.StdSchedulerFactory
import twitter4j.TwitterFactory
class UpdateProfileImageTask {
public void updateProfile() {
TwitterFactory.singleton.updateProfileImage(new File(new Date().format("yyyyMMdd") + ".gif"))
}
}
public class UpdateProfileJob implements Job {
public void execute(JobExecutionContext context)
throws JobExecutionException {
Map dataMap = context.getJobDetail().getJobDataMap()
UpdateProfileImageTask task = (UpdateProfileImageTask) dataMap.get("updateProfileTask")
task.updateProfile()
}
}
UpdateProfileImageTask task = new UpdateProfileImageTask()
//specify your scheduler task details
JobDetail job = new JobDetail()
job.setName("updateProfileJob")
job.setJobClass(UpdateProfileJob.class)
Map dataMap = job.getJobDataMap()
dataMap.put("updateProfileTask", task)
//configure the scheduler time
CronTrigger trigger = new CronTrigger()
trigger.setName("runMeJobTesting")
trigger.setCronExpression("0 0 0 * * ?")
//schedule it
Scheduler scheduler = new StdSchedulerFactory().getScheduler()
scheduler.start()
scheduler.scheduleJob(job, trigger)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment