Zum Hauptinhalt springen

Instagram Jobs

Jobs für Instagram-spezifische Verarbeitung. Instagram-Scraping selbst läuft über das Collector-System (Browser-Extension), nicht über Laravel Queues.

ProcessWatcherImportRun

Dispatcht einzelne ImportWatcherFromUrl Jobs für jedes Item eines Bulk-Imports. Fungiert als Dispatcher-Job, um N+1-Probleme in Web-Requests zu vermeiden.

Location: app/Jobs/ProcessWatcherImportRun.php

EigenschaftWert
Queueimports-youtube
Tries1
Timeout300s (5 Minuten für große Imports)
UniqueNein
TriggerUser-Import (Livewire Watchers\Index)

Ablauf

  1. WatcherImportRun laden und validieren
  2. Alle WatcherImportItem Records für diesen Run abfragen
  3. Pro Item einen ImportWatcherFromUrl Job dispatchen (auf imports-youtube Queue)
foreach ($items as $item) {
ImportWatcherFromUrl::dispatch(
runId: $this->runId,
workspaceId: $run->workspace_id,
createdBy: $run->created_by,
url: $item->url,
dedupeKey: $item->dedupe_key,
)->onQueue('imports-youtube');
}

Zusammenspiel mit Import-System

User gibt URLs ein (Livewire)
└── WatcherImportRun + WatcherImportItems erstellen
└── ProcessWatcherImportRun dispatchen
└── Pro Item: ImportWatcherFromUrl dispatchen
├── Profil importieren (API-Call)
├── Watcher + WatcherSource erstellen
├── WatcherImportProgress broadcasten
└── Bei Quota: Run pausieren, Jobs verzögern

FindRelatedInstagramProfiles

Sucht ähnliche Instagram-Profile basierend auf Keyword-Matching aus der lokalen Datenbank. Keine API-Calls erforderlich.

Location: app/Jobs/Instagram/FindRelatedInstagramProfiles.php

EigenschaftWert
Queueinstagram-related-profiles
Tries3
Backoff1min, 5min, 15min
UniqueJa (uniqueFor: 3600, 1 Stunde)
UniqueIdfind-related-instagram-profiles-{socialProfileId}
TriggerUser-Klick (Livewire RelatedProfiles)

Ablauf

  1. Profil laden, Status auf running setzen
  2. Keywords extrahieren (ProfileKeywordExtractor): Bio, Handle, Username
  3. Kandidat-Profile mit gemeinsamen Keywords finden (max 500)
  4. Relevance-Scores berechnen (max 100 Punkte)
  5. Top 25 Profile speichern in instagram_related_profiles
  6. RelatedProfilesCalculated Event broadcasten

Keyword-Extraktion + AI-Keywords

Der ProfileKeywordExtractor Service extrahiert Keywords aus mehreren Quellen. Zusaetzlich werden Gemini AI-Keywords (ai_keywords JSONB) hinzugemerged:

$keywords = $extractor->extractAndStore($profile);
// Quellen: bio, handle, username
// + AI Keywords aus $profile->ai_keywords

$aiKeywords = ! empty($profile->ai_keywords) ? $profile->ai_keywords : [];
$allKeywords = array_unique(array_merge($localKeywords, $aiKeywords));

Dynamische Stopwords aus keywords:update-stopwords werden automatisch gefiltert.

Source-gewichtete Keyword-Scoring

Keywords werden nach Herkunft unterschiedlich gewichtet:

SourcePunkte pro MatchBegruendung
bio6Bio-Inhalt ist am aussagekraeftigsten
title5Display-Name zeigt Thema
handle3Handle-Woerter sind weniger spezifisch
Default4Fallback fuer unbekannte Sources

Relevance-Scoring (max 100 Punkte)

KriteriumPunkteBeschreibung
Parsed Link Match0-30Approved (30pt), auto-parsed (25pt), generic @handle (20pt)
Popularity Bonus0-20Absolute Follower-Zahl (1M+ = 20 Punkte)
Bio-Keyword-MatchvariabelSource-gewichtet (bio=6, title=5, handle=3 pro Match)
Follower-Aehnlichkeit0-15Logarithmische log10-Skala
Favorites-Bonus0-10Konfigurierbar via config('postbox.favorites_tiers_instagram')
Name-Aehnlichkeit0-10similar_text() auf Profil-Titel
Gleicher Profile-Typ0-10Business/Creator/Private Match
Sprache/Land0-10+5 gleiche Sprache, +5 gleiches Land

Minimum-Schwelle: MIN_RELEVANCE_SCORE = 15 — Kandidaten darunter werden verworfen.

Links aus social_profile_links werden batch-geladen ($approvedLinksByProfile) und beruecksichtigt:

// Approved curated Link: 30 Punkte
// Auto-parsed (unapproved) Link: 25 Punkte
// Generischer @handle in Bio: 20 Punkte

Fehlerbehandlung

  • Status wird auf failed gesetzt mit Fehlerbeschreibung
  • Error-Report via report() mit Profil-Kontext
  • RelatedProfilesCalculated Event mit Fehler-Status broadcasten
  • Bei fehlenden Keywords: Bestehende Related Profiles werden gelöscht, Status completed

RecalculateRelatedInstagramScores

Berechnet Relevance-Scores für bestehende Instagram Related Profiles neu, basierend auf aktuellen Follower-Daten. Keine neue Keyword-Suche.

Location: app/Jobs/Instagram/RecalculateRelatedInstagramScores.php

EigenschaftWert
Queueinstagram-related-profiles
Tries1
Timeout120s
UniqueNein
Triggersocial:recalculate-related-scores Command

Scoring (max 100 Punkte)

KriteriumPunkteBeschreibung
Base (existierende Beziehung)25Grundpunkte für jede Beziehung
Popularity Bonus0-25Follower-basiert (1M+ = 25)
Follower-Ähnlichkeit0-15log10-Skala-Vergleich
Name-Ähnlichkeit0-15similar_text() Vergleich
Gleicher Profile-Typ0-10Business/Creator/Private
Sprache/Land0-10+5 Sprache, +5 Land

Ablauf

  1. Source-Profil und alle Related Profiles laden (mit Eager Loading)
  2. Follower-Counts fuer alle betroffenen Profile aus social_profile_daily_metrics abfragen
  3. Neuen Score pro Beziehung berechnen
  4. Batch-Update via CASE/WHEN SQL (eine Query statt N einzelner UPDATEs)
  5. Anzahl aktualisierter Scores loggen

Batch-Update

UPDATE instagram_related_profiles
SET relevance_score = (CASE WHEN id = ? THEN ? ... END)::smallint, updated_at = ?
WHERE id IN (?, ...)