Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider implementing Unit of Work like pattern to isolate complex tasks and their execution #22

Open
Thoronir42 opened this issue Sep 12, 2019 · 0 comments

Comments

@Thoronir42
Copy link
Owner

Thoronir42 commented Sep 12, 2019

I feel that it could be usefull to provide pattern like

class NotifyContestantsJob implements ExecutableJob {
  private $templateMails;

  public function validateParameters() {
    $parameters = func_get_args();
    // check if $parameters[0] is array of Person
    // check if $parameters[1] is a Contest
  }

  public function getJobProperties() {
    return [
      'transaction-atomic',
    ];
  }

  public function run(Person[] $contestants, Contests $contest) {
    foreach ($contestants as $contestant) {
        $this->templateMails->sendContestMail($contestants, $contest);
    }
  }
}

This could be used in two ways:

// either directly:
$notifyContestantJob->run($contestants, $contest);

// or with some other context
JobExecutor::schedule($notifyContestantJob, $contestants, $contest);

Also it might be nice to specify bulk/single logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant