package com.newvideo.job;
|
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import com.newvideo.iqiyi.entity.IqiyiUpdateQueue;
|
import com.newvideo.iqiyi.util.IqiyiUtil;
|
import com.newvideo.service.imp.juhe.IqiyiQueueService;
|
import com.newvideo.util.Constant;
|
import com.newvideo.util.StringUtil;
|
|
/**
|
*
|
*
|
* @author Administrator
|
*
|
*/
|
@Component
|
public class VideoUpdateJob {
|
@Resource
|
private IqiyiUtil iqiyiUtil;
|
|
@Resource
|
private IqiyiQueueService iqiyiQueueService;
|
|
@Scheduled(cron = "0 0 0,9,14,20 * * ?")
|
public void doJob() {
|
if (!Constant.JobTasker)
|
return;
|
System.out.println("VideoUpdateJob-doJob");
|
new Thread(new Runnable() {
|
|
public void run() {
|
iqiyiUtil.updateAll("");
|
}
|
}).start();
|
}
|
|
@Scheduled(cron = "0 5 0,12,20 * * ? ")
|
public void updateIqiyiQueue() {
|
if (!Constant.JobTasker)
|
return;
|
synchronized (iqiyiQueueService) {
|
List<IqiyiUpdateQueue> queueList = iqiyiQueueService.listUpdateQueue();
|
for (IqiyiUpdateQueue queue : queueList) {
|
String aid = null;
|
int count = 0;
|
while (StringUtil.isNullOrEmpty(aid) && count < 3) {
|
if (StringUtil.isNullOrEmpty(queue.getAid())) {
|
aid = IqiyiUtil.getAlbumIdFromPlayUrl(queue.getUrl());
|
count++;
|
try {
|
Thread.sleep(1000 * 2);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
} else
|
aid = queue.getAid();
|
}
|
if (!StringUtil.isNullOrEmpty(aid)) {
|
queue.setAid(aid);
|
iqiyiQueueService.updateUpdateQueue(queue);
|
iqiyiUtil.updateAlbum(aid);
|
}
|
}
|
}
|
}
|
}
|