Last active
March 26, 2018 10:06
-
-
Save geomagilles/61e0f885d576cc1b1f3398ce41a7796e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Zenaton\Interfaces\WorkflowInterface; | |
use Zenaton\Traits\Zenatonable; | |
use Zenaton\Tasks\Wait; | |
class NotifyEtaWorkflow implements WorkflowInterface | |
{ | |
use Zenatonable; | |
// inform user # seconds before ETA | |
const BEFORE = 3600; | |
// trip id | |
protected $tripId; | |
// user to notify | |
protected $user; | |
public function __construct($tripId, $user) | |
{ | |
$this->tripId = $tripId; | |
$this->user = $user; | |
} | |
public function handle() | |
{ | |
// calulate current duration & ETA | |
[$duration, $eta] = (new CalculateTimeToArrivalTask($this->tripId))->execute(); | |
// wait until ETA - 1hour | |
(new Wait())->timestamp($eta - self::BEFORE)->execute(); | |
// notify user | |
(new NotifyUserOfEtaTask($this->user, $eta))->execute(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment