Interface Work

    • Method Detail

      • run

        void run()
        Runs the work instance and does all the transaction management and retry.
        Implementation Note:
        Usually only implemented by AbstractWork, which should be subclassed instead of implementing this method.
      • getId

        String getId()
        The work id.

        The id is used for equality comparisons, and as a key in persistent queues.

        Returns:
        the work id, which must not be null
        Since:
        5.8
      • cleanUp

        void cleanUp​(boolean ok,
                     Exception e)
        This method is called after work() is done, in a finally block, whether work completed normally or was in error or was interrupted.
        Parameters:
        ok - true if the work completed normally
        e - the exception, if available
      • setWorkInstanceSuspending

        void setWorkInstanceSuspending()
        CALLED BY THE WORK MANAGER (not user code) when it requests that this work instance be suspended.
        Since:
        5.8
      • isSuspending

        boolean isSuspending()
        Checks if a suspend has been requested for this work instance by the work manager.

        If true, then state should be saved, suspended() should be called, and the work() method should return.

        Since:
        5.8
      • suspended

        void suspended()
        Must be called by Work implementations to advertise that state saving is done, when isSuspending() returned true. After this is called, the work() method should return.
        Since:
        5.8
      • isWorkInstanceSuspended

        boolean isWorkInstanceSuspended()
        CALLED BY THE WORK MANAGER (not user code) to check if this work instance really suspended.
        Since:
        5.8
      • setWorkInstanceState

        void setWorkInstanceState​(Work.State state)
        CALLED BY THE WORK MANAGER (not user code) to set this work instance's state.
        Since:
        5.8
      • getWorkInstanceState

        Work.State getWorkInstanceState()
        CALLED BY THE WORK MANAGER (not user code) to get this work instance's state.

        Used only to get the final state of a completed instance.

        Since:
        5.8
      • getCategory

        String getCategory()
        Gets the category for this work.

        Used to choose an execution queue.

        Returns:
        the category, or null for the default
      • getTitle

        String getTitle()
        Gets a human-readable name for this work instance.
        Returns:
        a human-readable name
      • getStatus

        String getStatus()
        Gets a human-readable status for this work instance.
        Returns:
        a human-readable status
      • getSchedulingTime

        long getSchedulingTime()
        Gets the time at which this work instance was first scheduled.
        Returns:
        the scheduling time (milliseconds since epoch)
      • getStartTime

        long getStartTime()
        Gets the time at which this work instance was first started.
        Returns:
        the start time (milliseconds since epoch), or 0 if not stated
      • getCompletionTime

        long getCompletionTime()
        Gets the time at which this work instance was completed, suspended or failed.
        Returns:
        the completion time (milliseconds since epoch), or 0 if not completed
      • setStartTime

        void setStartTime()
        CALLED BY THE WORK MANAGER (not user code) to set the start time on the work instance.
        Since:
        5.9.2
      • getProgress

        Work.Progress getProgress()
        Gets a progress report for this work instance.
        Returns:
        a progress report, not null
      • getOriginatingUsername

        String getOriginatingUsername()
        Gets the user on behalf of which this work is done.
        Returns:
        the originating username, or null
        Since:
        8.1
      • isDocumentTree

        boolean isDocumentTree()
        Returns true if getDocument() is only the root of a set of documents on which this Work instance will act.
        Returns:
        true if a whole tree is impacted
        Since:
        5.8
      • getPartitionKey

        default String getPartitionKey()
        Returns a key that can be used by the WorkManager implementation to guarantee that works with the same partition key will be executed in the order they are submitted.
        Since:
        9.3
      • isIdempotent

        default boolean isIdempotent()
        Returns true if a work with a given getId() should always produce the same result. The WorkManager implementation can safely skip duplicate executions of idempotent work.
        Since:
        10.1
      • isCoalescing

        default boolean isCoalescing()
        When setting the coalescing flag to true you indicate to the work manager that if multiple works with the same id are scheduled you only care about the lastest execution. The goal is to skip useless executions to save resources, It is up to the work manager implementation to support or not this optimization.
        Since:
        10.3