I already made a Beat Mechanism for Yii; quite tight to that project which works pretty fine.
Right now I'm working on a beat mechanism totally decoupled from any project. A Module, maybe. Right now works but not in a very elegant way.
requires yiisoft/yii2-queue, yiisoft/mutex
beco\\yii-beat\\BeatControllerextends yii\\console\\Controller
beat/start - queues a beat/run process to run with 0 delay (if there is no BeatJob instance queued )
beat/run [register next run to queue, default 0] - immediately runs a BeatJob
beat/index - shows beat info
beco\\yii-beat\\jobs\\BeatJobimplements: yii\\queue\\JobInterface
Has two functions:
BeatInterface and invoke such a static functionbeco\\yii-beat\\interfaces\\BeatInterfaceinterface BeatInterface {
public static function executeBeat():void;
}
If a model implements BeatInterface, it will be asked to execute the static executeBeat function, such function has the responsibility to run or pass (according to time, business rules or whatever), furthermore this static function can (and most likely will) delegate one invocation into other static functions in the same Model
My code is here, I warn you it is not as elegant as I would like to, but would really appreciate any suggestions.
Measuring rooms’ temperature every eight hours. Using my own ActiveRecord.