@Override public RepeatJobQueue getRepeatJobQueue(Config config) { return new MongoRepeatJobQueue(config); }
public MongoRepeatJobQueue(Config config) { super(config); // table name (Collection name) for single table setTableName(JobQueueUtils.REPEAT_JOB_QUEUE); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_jobId", "jobId", true, true); template.ensureIndex("idx_taskId_taskTrackerNodeGroup", "taskId, taskTrackerNodeGroup", true, true); template.ensureIndex("idx_realTaskId_taskTrackerNodeGroup", "realTaskId, taskTrackerNodeGroup"); template.ensureIndex("idx_relyOnPrevCycle_lgtt", "relyOnPrevCycle, lastGenerateTriggerTime"); } }
@Override public int incRepeatedCount(String jobId) { while (true) { JobPo jobPo = getJob(jobId); if (jobPo == null) { return -1; } Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); query.field("repeatedCount").equal(jobPo.getRepeatedCount()); UpdateOperations<JobPo> opts = template.createUpdateOperations(JobPo.class); opts.set("repeatedCount", jobPo.getRepeatedCount() + 1); UpdateResults ur = template.update(query, opts); if (ur.getUpdatedCount() == 1) { return jobPo.getRepeatedCount() + 1; } } }
public MongoRepeatJobQueue(Config config) { super(config); // table name (Collection name) for single table setTableName(JobQueueUtils.REPEAT_JOB_QUEUE); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_jobId", "jobId", true, true); template.ensureIndex("idx_taskId_taskTrackerNodeGroup", "taskId, taskTrackerNodeGroup", true, true); template.ensureIndex("idx_realTaskId_taskTrackerNodeGroup", "realTaskId, taskTrackerNodeGroup"); template.ensureIndex("idx_relyOnPrevCycle_lgtt", "relyOnPrevCycle, lastGenerateTriggerTime"); } }
@Override public int incRepeatedCount(String jobId) { while (true) { JobPo jobPo = getJob(jobId); if (jobPo == null) { return -1; } Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); query.field("repeatedCount").equal(jobPo.getRepeatedCount()); UpdateOperations<JobPo> opts = template.createUpdateOperations(JobPo.class); opts.set("repeatedCount", jobPo.getRepeatedCount() + 1); UpdateResults ur = template.update(query, opts); if (ur.getUpdatedCount() == 1) { return jobPo.getRepeatedCount() + 1; } } }
@Override public RepeatJobQueue getRepeatJobQueue(Config config) { return new MongoRepeatJobQueue(config); }
public MongoRepeatJobQueue(Config config) { super(config); // table name (Collection name) for single table setTableName(JobQueueUtils.REPEAT_JOB_QUEUE); // create table DBCollection dbCollection = template.getCollection(); List<DBObject> indexInfo = dbCollection.getIndexInfo(); // create index if not exist if (CollectionUtils.sizeOf(indexInfo) <= 1) { template.ensureIndex("idx_jobId", "jobId", true, true); template.ensureIndex("idx_taskId_taskTrackerNodeGroup", "taskId, taskTrackerNodeGroup", true, true); template.ensureIndex("idx_realTaskId_taskTrackerNodeGroup", "realTaskId, taskTrackerNodeGroup"); template.ensureIndex("idx_relyOnPrevCycle_lgtt", "relyOnPrevCycle, lastGenerateTriggerTime"); } }
@Override public int incRepeatedCount(String jobId) { while (true) { JobPo jobPo = getJob(jobId); if (jobPo == null) { return -1; } Query<JobPo> query = template.createQuery(JobPo.class); query.field("jobId").equal(jobId); query.field("repeatedCount").equal(jobPo.getRepeatedCount()); UpdateOperations<JobPo> opts = template.createUpdateOperations(JobPo.class); opts.set("repeatedCount", jobPo.getRepeatedCount() + 1); UpdateResults ur = template.update(query, opts); if (ur.getUpdatedCount() == 1) { return jobPo.getRepeatedCount() + 1; } } }
@Override public RepeatJobQueue getRepeatJobQueue(Config config) { return new MongoRepeatJobQueue(config); }