@ Override public void storeTrigger ( OperableTrigger trigger , boolean replaceExisting , JedisCluster jedis ) throws JobPersistenceException { final String triggerHashKey = redisSchema . triggerHashKey ( trigger . getKey ( ) ) ; final String triggerGroupSetKey = redisSchema . triggerGroupSetKey ( trigger . getKey ( ) ) ; final String jobTriggerSetKey = redisSchema . jobTriggersSetKey ( trigger . getJobKey ( ) ) ; if ( ! ( trigger instanceof SimpleTrigger ) && ! ( trigger instanceof CronTrigger ) ) { throw new UnsupportedOperationException ( "Only SimpleTrigger and CronTrigger are supported." ) ; } final boolean exists = jedis . exists ( triggerHashKey ) ; if ( exists && ! replaceExisting ) { throw new ObjectAlreadyExistsException ( trigger ) ; } Map < String , String > triggerMap = mapper . convertValue ( trigger , new TypeReference < HashMap < String , String > > ( ) { } ) ; triggerMap . put ( TRIGGER_CLASS , trigger . getClass ( ) . getName ( ) ) ; jedis . hmset ( triggerHashKey , triggerMap ) ; jedis . sadd ( redisSchema . triggersSet ( ) , triggerHashKey ) ; jedis . sadd ( redisSchema . triggerGroupsSet ( ) , triggerGroupSetKey ) ; jedis . sadd ( triggerGroupSetKey , triggerHashKey ) ; jedis . sadd ( jobTriggerSetKey , triggerHashKey ) ; if ( trigger . getCalendarName ( ) != null && ! trigger . getCalendarName ( ) . isEmpty ( ) ) { final String calendarTriggersSetKey = redisSchema . calendarTriggersSetKey ( trigger . getCalendarName ( ) ) ; jedis . sadd ( calendarTriggersSetKey , triggerHashKey ) ; } if ( trigger . getJobDataMap ( ) != null && ! trigger . getJobDataMap ( ) . isEmpty ( ) ) { final String triggerDataMapHashKey = redisSchema . triggerDataMapHashKey ( trigger . getKey ( ) ) ; jedis . hmset ( triggerDataMapHashKey , getStringDataMap ( trigger . getJobDataMap ( ) ) ) ; } if ( exists ) { // We're overwriting a previously stored instance of this trigger, so clear any existing trigger state. unsetTriggerState ( triggerHashKey , jedis ) ; } Boolean triggerPausedResponse = jedis . sismember ( redisSchema . pausedTriggerGroupsSet ( ) , triggerGroupSetKey ) ; Boolean jobPausedResponse = jedis . sismember ( redisSchema . pausedJobGroupsSet ( ) , redisSchema . jobGroupSetKey ( trigger . getJobKey ( ) ) ) ; if ( triggerPausedResponse || jobPausedResponse ) { final long nextFireTime = trigger . getNextFireTime ( ) != null ? trigger . getNextFireTime ( ) . getTime ( ) : - 1 ; final String jobHashKey = redisSchema . jobHashKey ( trigger . getJobKey ( ) ) ; if ( isBlockedJob ( jobHashKey , jedis ) ) { setTriggerState ( RedisTriggerState . PAUSED_BLOCKED , ( double ) nextFireTime , triggerHashKey , jedis ) ; } else { setTriggerState ( RedisTriggerState . PAUSED , ( double ) nextFireTime , triggerHashKey , jedis ) ; } } else if ( trigger . getNextFireTime ( ) != null ) { setTriggerState ( RedisTriggerState . WAITING , ( double ) trigger . getNextFireTime ( ) . getTime ( ) , triggerHashKey , jedis ) ; } }
Store a trigger in redis