Skip to content

Instantly share code, notes, and snippets.

@geomagilles
Last active March 26, 2018 10:06
Show Gist options
  • Save geomagilles/61e0f885d576cc1b1f3398ce41a7796e to your computer and use it in GitHub Desktop.
Save geomagilles/61e0f885d576cc1b1f3398ce41a7796e to your computer and use it in GitHub Desktop.
<?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