aboutsummaryrefslogtreecommitdiffhomepage
path: root/Digitigrade/Job/GenerateLinkPreviews.php
diff options
context:
space:
mode:
Diffstat (limited to 'Digitigrade/Job/GenerateLinkPreviews.php')
-rw-r--r--Digitigrade/Job/GenerateLinkPreviews.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/Digitigrade/Job/GenerateLinkPreviews.php b/Digitigrade/Job/GenerateLinkPreviews.php
new file mode 100644
index 0000000..acaccbb
--- /dev/null
+++ b/Digitigrade/Job/GenerateLinkPreviews.php
@@ -0,0 +1,28 @@
+<?php
+namespace Digitigrade\Job;
+
+use Digitigrade\Job;
+use Digitigrade\JobQueue;
+use Digitigrade\Logger;
+use Digitigrade\Model\Note;
+
+class GenerateLinkPreviews extends Job {
+ public int $noteId;
+
+ public function __construct(Note $note) {
+ $this->noteId = $note->id;
+ $this->remainingTries = 4;
+ }
+
+ public function run() {
+ $note = Note::find($this->noteId);
+ Logger::getInstance()->info('Generating link previews for note: ' . $note->uri);
+ $note->generateLinkPreviews();
+ $note->save();
+ }
+
+ public function submit() {
+ // submit it after a random delay to avoid deluging the websites being previewed
+ JobQueue::getInstance()->submitDelayed($this, random_int(0, 60 * 15 /* 15 minutes */));
+ }
+} \ No newline at end of file