newfold-labs / wp-module-tasks

A task system for processing asynchronous tasks with wordpress, the tasks could be one-off long running tasks or periodic tasks.
2 stars 1 forks source link

Reconsider method of Task instantiation #4

Closed wpscholar closed 1 year ago

wpscholar commented 1 year ago

Having 9 parameters to instantiate a Task seems a bit much. Do we really need them all in the constructor?

https://github.com/newfold-labs/wp-module-tasks/blob/a7d309cd8a693dd82e0c284834cc2b7ee3a8fb12/includes/Models/Data/Task.php#L135-L143

For example, why not default to a low or mid-range priority and then allow calling $task->priority( 80 ) to change it?

By introducing chainable methods, we could do something like $task->priority( 80 )->retries(3). This allows us to instantiate in a more reader-friendly way and without having to pass null for multiple parameters.