Skip to content

Instantly share code, notes, and snippets.

@kyonmm
Forked from yusuke/TimeAvatar.groovy
Created August 8, 2012 07:12
Show Gist options
  • Save kyonmm/3293025 to your computer and use it in GitHub Desktop.
Save kyonmm/3293025 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.name = "updateProfileJob"
job.JobClass UpdateProfileJob.class
Map dataMap = job.getJobDataMap()
dataMap << updateProfileTask:task
//configure the scheduler time
CronTrigger trigger = new CronTrigger()
trigger.name = "runMeJobTesting"
trigger.cronExpression = "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