Class RedisWorkQueuing

    • Field Detail

      • KEY_DATA

        protected static final String KEY_DATA
        Global hash of Work instance id -> serialized Work instance.
        See Also:
        Constant Field Values
      • KEY_STATE

        protected static final String KEY_STATE
        Global hash of Work instance id -> Work state. The completed state is followed by a completion time in milliseconds.
        See Also:
        Constant Field Values
      • KEY_SUSPENDED_PREFIX

        protected static final String KEY_SUSPENDED_PREFIX
        Per-queue list of suspended Work instance ids.
        See Also:
        Constant Field Values
      • KEY_SUSPENDED

        protected static final byte[] KEY_SUSPENDED
      • KEY_QUEUE_PREFIX

        protected static final String KEY_QUEUE_PREFIX
        Per-queue list of scheduled Work instance ids.
        See Also:
        Constant Field Values
      • KEY_QUEUE

        protected static final byte[] KEY_QUEUE
      • KEY_SCHEDULED_PREFIX

        protected static final String KEY_SCHEDULED_PREFIX
        Per-queue set of scheduled Work instance ids.
        See Also:
        Constant Field Values
      • KEY_SCHEDULED

        protected static final byte[] KEY_SCHEDULED
      • KEY_RUNNING_PREFIX

        protected static final String KEY_RUNNING_PREFIX
        Per-queue set of running Work instance ids.
        See Also:
        Constant Field Values
      • KEY_RUNNING

        protected static final byte[] KEY_RUNNING
      • KEY_COMPLETED

        protected static final byte[] KEY_COMPLETED
      • KEY_CANCELED

        protected static final byte[] KEY_CANCELED
      • STATE_SCHEDULED

        protected static final byte[] STATE_SCHEDULED
      • STATE_RUNNING

        protected static final byte[] STATE_RUNNING
      • STATE_UNKNOWN

        protected static final byte[] STATE_UNKNOWN
      • redisNamespace

        protected String redisNamespace
      • initWorkQueueSha

        protected byte[] initWorkQueueSha
      • metricsWorkQueueSha

        protected byte[] metricsWorkQueueSha
      • schedulingWorkSha

        protected byte[] schedulingWorkSha
      • popWorkSha

        protected byte[] popWorkSha
      • runningWorkSha

        protected byte[] runningWorkSha
      • cancelledScheduledWorkSha

        protected byte[] cancelledScheduledWorkSha
      • completedWorkSha

        protected byte[] completedWorkSha
      • cancelledRunningWorkSha

        protected byte[] cancelledRunningWorkSha
    • Method Detail

      • workRunning

        public void workRunning​(String queueId,
                                Work work)
        Description copied from interface: WorkQueuing
        Put the work instance into the running set.
        Specified by:
        workRunning in interface WorkQueuing
        Parameters:
        queueId - the queue id
        work - the work instance
      • workCompleted

        public void workCompleted​(String queueId,
                                  Work work)
        Description copied from interface: WorkQueuing
        Moves a work instance from the running set to the completed set.
        Specified by:
        workCompleted in interface WorkQueuing
        Parameters:
        queueId - the queue id
        work - the work instance
      • workReschedule

        public void workReschedule​(String queueId,
                                   Work work)
        Description copied from interface: WorkQueuing
        Moves back a work instance from running set to the scheduled set.
        Specified by:
        workReschedule in interface WorkQueuing
      • listWork

        public List<Work> listWork​(String queueId,
                                   Work.State state)
        Description copied from interface: WorkQueuing
        Lists the work instances in a given queue in a defined state.

        Note that an instance requested as RUNNING could be found SUSPENDING or SUSPENDED, and an instance requested as COMPLETED could be found FAILED.

        Specified by:
        listWork in interface WorkQueuing
        Parameters:
        queueId - the queue id
        state - the state defining the state to look into, SCHEDULED, RUNNING, or null for non-completed
        Returns:
        the list of work instances in the given state
      • listWorkIds

        public List<String> listWorkIds​(String queueId,
                                        Work.State state)
        Description copied from interface: WorkQueuing
        Lists the work ids in a given queue in a defined state.
        Specified by:
        listWorkIds in interface WorkQueuing
        Parameters:
        queueId - the queue id
        state - the state defining the state to look into, SCHEDULED, RUNNING, or null for non-completed
        Returns:
        the list of work ids in the given state
      • listScheduled

        protected List<Work> listScheduled​(String queueId)
      • listScheduledIds

        protected List<String> listScheduledIds​(String queueId)
      • listNonCompletedIds

        protected List<String> listNonCompletedIds​(String queueId)
      • count

        public long count​(String queueId,
                          Work.State state)
        Description copied from interface: WorkQueuing
        Gets the number of work instances in the given state in a given queue.
        Specified by:
        count in interface WorkQueuing
        Parameters:
        queueId - the queue id
        state - the state, SCHEDULED or RUNNING
        Returns:
        the number of scheduled work instances in the queue
      • find

        public Work find​(String workId,
                         Work.State state)
        Description copied from interface: WorkQueuing
        Finds a work instance in the scheduled or running or completed sets.
        Specified by:
        find in interface WorkQueuing
        Parameters:
        workId - the id of the work to find
        state - the state defining the state to look into, SCHEDULED, RUNNING, or null for SCHEDULED or RUNNING
        Returns:
        the found work instance, or null if not found
      • isWorkInState

        public boolean isWorkInState​(String workId,
                                     Work.State state)
        Description copied from interface: WorkQueuing
        Checks if a work instance with the given id is in the given state.
        Specified by:
        isWorkInState in interface WorkQueuing
        Parameters:
        workId - the work id
        state - the state, SCHEDULED, RUNNING, or null for non-completed
        Returns:
        true if a work instance with the given id is in the given state
      • removeScheduled

        public void removeScheduled​(String queueId,
                                    String workId)
        Description copied from interface: WorkQueuing
        Finds a scheduled work instance and removes it from the scheduled queue.
        Specified by:
        removeScheduled in interface WorkQueuing
        Parameters:
        queueId - the queue id
        workId - the id of the work to find
      • setActive

        public void setActive​(String queueId,
                              boolean value)
        Description copied from interface: WorkQueuing
        Enable/disable this queueId processing
        Specified by:
        setActive in interface WorkQueuing
      • string

        protected String string​(byte[] bytes)
      • bytes

        protected byte[] bytes​(String string)
      • bytes

        protected byte[] bytes​(Work.State state)
      • keyBytes

        protected byte[] keyBytes​(String prefix,
                                  String queueId)
      • keyBytes

        protected byte[] keyBytes​(String prefix)
      • workId

        protected byte[] workId​(Work work)
      • workId

        protected byte[] workId​(String id)
      • suspendedKey

        protected byte[] suspendedKey​(String queueId)
      • queuedKey

        protected byte[] queuedKey​(String queueId)
      • countKey

        protected byte[] countKey​(String queueId)
      • runningKey

        protected byte[] runningKey​(String queueId)
      • scheduledKey

        protected byte[] scheduledKey​(String queueId)
      • completedKey

        protected byte[] completedKey​(String queueId)
      • canceledKey

        protected byte[] canceledKey​(String queueId)
      • stateKey

        protected byte[] stateKey()
      • dataKey

        protected byte[] dataKey()
      • deserializeWork

        protected Work deserializeWork​(byte[] workBytes)
      • getSuspendedQueueIds

        protected Set<String> getSuspendedQueueIds()
                                            throws IOException
        Finds which queues have suspended work.
        Returns:
        a set of queue ids
        Throws:
        IOException
        Since:
        5.8
      • getScheduledQueueIds

        protected Set<String> getScheduledQueueIds()
      • getRunningQueueIds

        protected Set<String> getRunningQueueIds()
      • getQueueIds

        protected Set<String> getQueueIds​(String queuePrefix)
        Finds which queues have work for a given state prefix.
        Returns:
        a set of queue ids
        Since:
        5.8
      • scheduleSuspendedWork

        public int scheduleSuspendedWork​(String queueId)
                                  throws IOException
        Resumes all suspended work instances by moving them to the scheduled queue.
        Parameters:
        queueId - the queue id
        Returns:
        the number of work instances scheduled
        Throws:
        IOException
        Since:
        5.8
      • suspendScheduledWork

        public int suspendScheduledWork​(String queueId)
                                 throws IOException
        Suspends all scheduled work instances by moving them to the suspended queue.
        Parameters:
        queueId - the queue id
        Returns:
        the number of work instances suspended
        Throws:
        IOException
        Since:
        5.8
      • workSetScheduled

        public void workSetScheduled​(String queueId,
                                     Work work)
                              throws IOException
        Persists a work instance and adds it to the scheduled queue.
        Parameters:
        queueId - the queue id
        work - the work instance
        Throws:
        IOException
      • workSetCancelledScheduled

        protected void workSetCancelledScheduled​(String queueId,
                                                 Work work)
                                          throws IOException
        Switches a work to state completed, and saves its new state.
        Throws:
        IOException
      • workSetRunning

        protected void workSetRunning​(String queueId,
                                      Work work)
                               throws IOException
        Switches a work to state running.
        Parameters:
        queueId - the queue id
        work - the work
        Throws:
        IOException
      • workSetCompleted

        protected void workSetCompleted​(String queueId,
                                        Work work)
                                 throws IOException
        Switches a work to state completed, and saves its new state.
        Throws:
        IOException
      • workSetReschedule

        protected void workSetReschedule​(String queueId,
                                         Work work)
                                  throws IOException
        Switches a work to state canceled, and saves its new state.
        Throws:
        IOException
      • keys

        protected List<byte[]> keys​(String queueid)
      • getWorkStateInfo

        protected Work.State getWorkStateInfo​(String workId)
        Gets the work state.
        Parameters:
        workId - the work id
        Returns:
        the state, or null if not found
      • getWork

        protected Work getWork​(byte[] workIdBytes)
      • getWorkFromQueue

        protected Work getWorkFromQueue​(String queueId)
                                 throws IOException
        Removes first work from work queue.
        Parameters:
        queueId - the queue id
        Returns:
        the work, or null if the scheduled queue is empty
        Throws:
        IOException
      • removeScheduledWork

        protected void removeScheduledWork​(String queueId,
                                           String workId)
                                    throws IOException
        Removes a given work from queue, move the work from scheduled to completed set.
        Throws:
        IOException
      • coerceNullToZero

        protected static Number[] coerceNullToZero​(List<Number> numbers)
      • coerceNullToZero

        protected static Number[] coerceNullToZero​(Number[] counters)
      • supportsProcessingDisabling

        public boolean supportsProcessingDisabling()
        Specified by:
        supportsProcessingDisabling in interface WorkQueuing
        Returns:
        true if the implementation supports processing disabling