Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Services\Podcasting;
  4.  
  5. use Services\Podcasting\Transcoder\Queue as TranscoderQueue;
  6. use Illuminate\Support\Carbon;
  7. use Illuminate\Contracts\Support\Jsonable;
  8.  
  9. class PodcastStatus implements Jsonable
  10. {
  11. /**
  12. * Transcode Queue for Podcasts
  13. *
  14. * @var \Services\Podcasting\Transcoder\Queue
  15. */
  16. protected $queue;
  17.  
  18. /**
  19. * The Podcast being checked
  20. *
  21. * @var App\Podcast
  22. */
  23. protected $podcast;
  24.  
  25. /**
  26. * The Status of the Podcast
  27. *
  28. * @var string
  29. */
  30. protected $status;
  31.  
  32. /**
  33. * If the Status is "pending" or "queued", the moment it may be start processing
  34. *
  35. * @var \Illuminate\Support\Carbon
  36. */
  37. protected $estimated_at;
  38.  
  39. /**
  40. * Creates a new Podcasting instance
  41. *
  42. * @return void
  43. */
  44. public function __construct(TranscoderQueue $queue)
  45. {
  46. $this->queue = $queue;
  47. }
  48.  
  49. /**
  50. * Get the processing status of a queued Podcast
  51. *
  52. * @return $this
  53. */
  54. public function getPodcastStatus(Podcast $podcast)
  55. {
  56. $this->podcast = $podcast;
  57.  
  58. [$status, $estimated_at] = $this->queue->checkId($podcast->getKey());
  59.  
  60. $this->status = $status;
  61.  
  62. $this->estimated_at = $estimated_at ? Carbon::parse($estimated_at) : null;
  63.  
  64. return $this;
  65. }
  66.  
  67. /**
  68. * Convert the object to its JSON representation.
  69. *
  70. * @param int $options
  71. * @return string
  72. */
  73. public function toJson($options = 0)
  74. {
  75. return json_encode([
  76. 'podcast_id' => $this->podcast->getKey(),
  77. 'status' => $this->status ?? 'not_found',
  78. 'estimated_at' => $this->estimated_at,
  79. ]);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement