CN-122019074-A - Global task scheduling method and system based on event-triggered time-aware state machine
Abstract
The invention provides a global task scheduling method and system based on an event-triggered time-aware state machine. The method includes the steps of responding to the fact that physical time reaches a preset logic epoch boundary, generating a logic time vector containing epoch vectors and logic time indexes, submitting the logic time vector to a distributed consensus engine to enable system nodes to achieve consensus to form consensus logic time vectors, taking the consensus logic time vector as input, driving a time perception state machine corresponding to a task to carry out state transition, and triggering task execution when the transition is carried out to an execution state. The invention decouples the variable physical time calculation and the stable logic state decision, synchronizes the global logic time through the consensus mechanism, fundamentally solves the problem of inconsistent scheduling caused by daylight saving time and time zone rule change in a cross-time zone and cross-region environment, and has natural immunity to the abnormal conditions such as 'vanishing time' and 'repetition time'.
Inventors
- LIN ZHENGXIN
- CAI FEIFEI
- LI MEIJUAN
Assignees
- 厦门星纵数字科技有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20251225
Claims (9)
- 1. A global task scheduling method based on an event-triggered time-aware state machine, the method comprising: Generating a logic time vector describing a logic time state in response to the physical time reaching a preset logic epoch boundary, wherein the logic time vector at least comprises an epoch vector for indicating an active epoch and a logic time index for indicating a logic time progress in a current epoch; Submitting the logic time vector to a distributed consensus engine so that a plurality of nodes in the distributed system agree on the logic time vector to form an agreed logic time vector; Taking the consensus logic time vector as input, and driving a time-aware state machine of a corresponding task to perform state transition, wherein a state transfer function of the time-aware state machine is configured to determine whether to trigger an execution state according to the consensus logic time vector and preset task scheduling logic; and triggering the execution of the corresponding task when the time-aware state machine transitions to the execution state.
- 2. The method of claim 1, wherein generating a logical time vector describing a logical time state in response to the physical time reaching a preset logical epoch boundary comprises: When the physical time reaches the initial boundary of a new epoch, generating a new logic time vector, wherein the epoch vector in the new logic time vector is updated to contain the identification of the new epoch, and resetting the logic time index corresponding to the new epoch to an initial value; and in the new era, pushing the logic time index in a preset logic time unit.
- 3. The method of claim 1, wherein the logical epoch is defined by a quadruple, the quadruple comprising a unique identification of epoch, epoch type, and a start boundary and an end boundary on an absolute timeline.
- 4. The method of claim 1, wherein submitting the logical time vector to a distributed consensus engine to cause a plurality of nodes in a distributed system to agree on the logical time vector comprises: Initiating, by the physical clock adapter as a proposer, a consensus proposal for the logical time vector to a plurality of nodes as recipients; a modified Paxos consensus algorithm is run between the plurality of nodes to form and broadcast the consensus logical time vector to all subscribers.
- 5. The method of claim 1, wherein the transition condition of the state transfer function of the time-aware state machine comprises: detecting a switching of epoch vectors in said consensus logical time vector, and And detecting that the logic time index of the target epoch type in the consensus logic time vector reaches a preset trigger value.
- 6. The method of claim 5, wherein the detecting the switching of epoch vectors is accomplished by comparing a difference between the currently received consensus logical time vector and an epoch vector in a consensus logical time vector received at a previous time.
- 7. A global task scheduling system based on an event-triggered time aware state machine, the system comprising: The physical clock adapter is used for monitoring a physical time stream and generating a logic time vector describing a logic time state when the physical time reaches a preset logic epoch boundary, wherein the logic time vector at least comprises an epoch vector used for indicating an active epoch and a logic time index used for indicating a logic time progress in a current epoch; The distributed consensus engine is in communication connection with the physical clock adapter and is used for receiving the logic time vector and coordinating a plurality of nodes in the distributed system to agree on the logic time vector so as to form an agreed logic time vector; The time perception state machine pool is in communication connection with the distributed consensus engine, comprises at least one time perception state machine corresponding to a specific task, and is used for receiving the consensus logic time vector and driving state transition of the time perception state machine pool according to preset state transition logic; And the task executor is in communication connection with the time perception state machine pool and is used for executing corresponding tasks when the time perception state machine transitions to an execution state.
- 8. An electronic device, comprising a processor and a memory; the memory is used for storing instructions; the processor being configured to execute the instructions in the memory and to perform the method of any of claims 1-6.
- 9. A computer readable storage medium comprising instructions which, when run on a computer, cause the computer to perform the method of any of the preceding claims 1-6.
Description
Global task scheduling method and system based on event-triggered time-aware state machine Technical Field The invention relates to the technical field of distributed computing, task scheduling and time synchronization, in particular to a global task scheduling method and system based on an event-triggered time-aware state machine. Background In the context of globalization services, software systems need to provide timing services for users throughout the world, such as timing report generation, messaging, performing data batching, etc. Such tasks are typically managed by a task scheduling system, the core of which is to ensure that the tasks execute accurately at the "local time" desired by the user. However, the existing scheduling solutions have a number of drawbacks that are difficult to overcome when facing time zones, especially the daylight savings time regime. The prior art scheme mainly comprises a static conversion scheme based on UTC time, a scheme based on Cron expression and dynamic calculation in running time and a preprocessing scheme based on a commercial calendar library. The scheme has the common inherent defects that updating of future time zone rules cannot be processed, vanishing time and repetition time generated during daylight saving time switching cannot be processed correctly, calculation cost is high, system performance is affected by the number of tasks, system correctness is seriously dependent on consistency of local time zone databases of all nodes, the state is fragile, logic for processing time anomalies is complex and dispersed, and expandability is poor. Therefore, there is an urgent need in the art for a new task scheduling scheme that can fundamentally decouple time rules from scheduling logic, has inherent consistency, and can gracefully handle time anomalies. Disclosure of Invention The embodiment of the invention provides a global task scheduling method and a global task scheduling system based on an event-triggered time-aware state machine, which can realize global task scheduling which is decoupled from a physical time zone rule, has internal consistency and can robustly process time anomalies. The first aspect of the present invention provides a global task scheduling method based on an event-triggered time-aware state machine, comprising: Generating a logic time vector describing a logic time state in response to the physical time reaching a preset logic epoch boundary, wherein the logic time vector at least comprises an epoch vector for indicating an active epoch and a logic time index for indicating a logic time progress in a current epoch; Submitting the logic time vector to a distributed consensus engine so that a plurality of nodes in the distributed system agree on the logic time vector to form an agreed logic time vector; Taking the consensus logic time vector as input, and driving a time-aware state machine of a corresponding task to perform state transition, wherein a state transfer function of the time-aware state machine is configured to determine whether to trigger an execution state according to the consensus logic time vector and preset task scheduling logic; when the time-aware state machine transitions to an execution state, execution of the corresponding task is triggered. Optionally, in response to the physical time reaching a preset logical epoch boundary, generating a logical time vector describing a logical time state, including: When the physical time reaches the initial boundary of a new epoch, generating a new logic time vector, wherein the epoch vector in the new logic time vector is updated to contain the identification of the new epoch, and resetting the logic time index corresponding to the new epoch to be an initial value; and in the new era, pushing the logic time index in a preset logic time unit. Optionally, the logical epoch is defined by a four tuple comprising a unique identification of the epoch, the epoch type, and a start boundary and an end boundary on the absolute timeline. Optionally, submitting the logical time vector to a distributed consensus engine to cause a plurality of nodes in the distributed system to agree on the logical time vector, comprising: Initiating, by the physical clock adapter as a proposer, a consensus proposal for the logical time vector to a plurality of nodes as recipients; a modified Paxos consensus algorithm is run between multiple nodes to form and broadcast a consensus logical time vector to all subscribers. Optionally, the transition condition of the state transfer function of the time-aware state machine includes: detecting a switching of epoch vectors in the consensus logical time vectors, and And detecting that the logic time index of the target epoch type in the consensus logic time vector reaches a preset trigger value. Optionally, detecting that an epoch vector switches is accomplished by comparing the difference between the current received consensus logical time vector and the epoch vec