You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The OCP\BackgroundJob API is deprecated and 9.1 features a nice declarative way for registering Background Jobs in the info.xml.
However the current IJob/IJoblist API is a mess and very hard to use:
The IJob Interface requires you to implement method calls which make no sense, are pure boilerplate and whose PHPdoc description is either missing or unclear (maybe because the authors did not know why it was there in the first place)
setId: what's the usecase for this?
getId: redundant, I should not have to implement that
setArgument: no idea why it's needed, it's not used in JobList
getArgument: same as setArgument
getLastRun: why do I need to implement this? Shouldn't this already be done by core?
setLastRun: same as getLastRun
execute: circular dependencies and logger should be injected via the constructor. The joblist should remove a job not a job should access the joblist to remove itself. This is a potential trap, since the user needs to take care of this by himself
The API has circular dependencies because responsibilities are mixed (e.g.: jobs remove themselves from a joblist)
Classes which actually take care of the boilerplate are private, so you can not extend them.
I propose the following solution: Every Background Job implements this interface:
namespaceOCP\BackgroundJob;
interfaceITask {
/** * Runs the task */functionexecute();
}
That's it. So what about Timed and Regular Jobs? Pure configuration that I should not have to worry about.
How would one register or remove a cronjob programmatically? Use a service:
interfaceITaskService {
/** * @param $appId app's id * @param $taskId task id, use this to register the same task twice. Has * to be unique in combination with the app id * @param $class the class to run, has to implement ITask * @param int $interval optional, if given sleeps at least that many seconds * before the next execution */functionregisterTask($appId, $taskId, $class, $interval = 0);
/** * Removes a task from the execution plan * @param $appId * @param $taskId */functionunregisterTask($appId, $taskId);
/** * Returns the last time a task was executed * @param $appId app's id * @param $taskId task's id * * @return Date instance when the task was run the last time */functiongetLastRun($appId, $taskId);
}
The OCP\BackgroundJob API is deprecated and 9.1 features a nice declarative way for registering Background Jobs in the info.xml.
However the current IJob/IJoblist API is a mess and very hard to use:
I propose the following solution: Every Background Job implements this interface:
That's it. So what about Timed and Regular Jobs? Pure configuration that I should not have to worry about.
Timed Job:
Queued Job:
How would one register or remove a cronjob programmatically? Use a service:
@MorrisJobke @nickvergessen @DeepDiver1975 @icewind1991 @Xenopathic @PVince81 @LukasReschke
The text was updated successfully, but these errors were encountered: