Skip to content

Add <service-schedule> and <cancel-scheduled-service> XML actions#719

Open
moqui-industrial wants to merge 2 commits into
moqui:masterfrom
moqui-industrial:feat/service-schedule
Open

Add <service-schedule> and <cancel-scheduled-service> XML actions#719
moqui-industrial wants to merge 2 commits into
moqui:masterfrom
moqui-industrial:feat/service-schedule

Conversation

@moqui-industrial

Copy link
Copy Markdown

Summary

Adds two new XML action elements for scheduling services declaratively from within service definitions, with optional distributed execution across a Hazelcast cluster.

New XML actions

<service-schedule>

<service-schedule name="my.Service.verb#Noun"
    task-name="unique-task-id"
    type="one-shot|at-fixed-rate|with-fixed-delay"
    distribute="true"
    initial-delay="1000"
    polling-interval="5000"
    duration="60000"
    in-map="[param:value]"/>

<cancel-scheduled-service>

<cancel-scheduled-service task-name="unique-task-id" cancel-delay="10000"/>

Distributed executor interface

Adds CustomDistributedScheduledExecutor interface in ContextJavaUtil and wires a distributed-scheduled-executor-factory attribute into MoquiConf.xsd / ServiceFacadeImpl. When distribute="true" and a factory implementation is present (e.g. moqui-hazelcast), the task is submitted to the distributed executor; otherwise it falls back to the local ScheduledExecutorService.

ScheduledServiceCallable and ScheduledServiceRunnable implement Externalizable for transparent cross-node serialization in a cluster.

Backward compatibility

Fully additive. No existing API or configuration is changed. The distributed-scheduled-executor-factory attribute is optional; omitting it disables distribution silently.

New XML actions for high-frequency device polling and event-driven scheduled tasks:

  <service-schedule task-name="..." service-name="..." mode="one-shot|at-fixed-rate|with-fixed-delay"
      initial-delay="..." period="..." delay="..." time-unit="..."/>
  <cancel-scheduled-service task-name="..."/>

Backed by a dedicated CustomScheduledExecutor (separate from the job runner) so short
periods (50 ms, 100 ms) do not starve long-running batch jobs.

ServiceCallScheduled fluent API mirrors ServiceCallSync/Async. scheduledFutureMap
(ConcurrentHashMap) tracks active futures by taskName for cancel-by-name support.
ServiceFacadeImpl.schedule() factory methods wire everything together and shut the
executor down cleanly on destroy().

Usage example in example/service/ExampleServices.xml.
Introduces CustomDistributedScheduledExecutor interface (ContextJavaUtil) and wires
it through ServiceFacadeImpl so a Hazelcast (or other) implementation can replace
the local ScheduledExecutorService for cluster-wide scheduled service execution.

BREAKING: distributed-factory attribute renamed to distributed-executor-factory.
Update any MoquiConf.xml that uses distributed-factory="..." accordingly.

The distributed-scheduled-executor-factory attribute is new and optional; omitting
it keeps the current local-only behaviour.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant