Put constants in Laravel config
All checks were successful
Push image to registry / build-image (push) Successful in 5m38s
All checks were successful
Push image to registry / build-image (push) Successful in 5m38s
This commit is contained in:
@ -21,26 +21,6 @@ use Laravel\Dusk\Browser;
|
||||
class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProcessing
|
||||
{
|
||||
// === CONFIGURATION ===
|
||||
// TODO : put that in laravel config file
|
||||
/**
|
||||
* Maximum number of posts to repost per account
|
||||
* @var int
|
||||
*/
|
||||
private const MAX_REPOSTS_PER_ACCOUNT = 2;
|
||||
|
||||
/**
|
||||
* Max number of reposts per job
|
||||
* This is the maximum number of posts that will be reposted in a single job run.
|
||||
* @var int
|
||||
*/
|
||||
private const MAX_REPOSTS_PER_JOB = 3;
|
||||
|
||||
/**
|
||||
* Maximum number of tries to repost a reel
|
||||
* If a reel fails to be reposted, it will be retried up to this number of times.
|
||||
* @var int
|
||||
*/
|
||||
private const MAX_REPOST_TRIES = 3;
|
||||
|
||||
private const APPROXIMATIVE_RUNNING_MINUTES = 2;
|
||||
|
||||
@ -140,16 +120,16 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
}
|
||||
|
||||
// Add unreposted reels to the job run if not enough reels were downloaded
|
||||
if (count($toDownloadReels) < self::MAX_REPOSTS_PER_JOB) {
|
||||
if (count($toDownloadReels) < config("jobs.instagramRepost.max_reposts_per_job")) {
|
||||
$toDownloadReelsIds = array_map(function ($reel) {
|
||||
return $reel->reel_id;
|
||||
}, $toDownloadReels);
|
||||
|
||||
$unrepostedReels = InstagramRepost::where("reposted", false)
|
||||
->where("repost_tries", "<", self::MAX_REPOST_TRIES) // Limit to 3 tries
|
||||
->where("repost_tries", "<", config('jobs.instagramRepost.max_repost_tries')) // Limit to 3 tries
|
||||
->whereNotIn("reel_id", $toDownloadReelsIds) // Avoid already downloaded reels
|
||||
->whereIn("account_id", InstagramAccount::whereIn("username", $accounts)->pluck("id"))
|
||||
->take(self::MAX_REPOSTS_PER_JOB - count($toDownloadReels))
|
||||
->take(config("jobs.instagramRepost.max_reposts_per_job") - count($toDownloadReels))
|
||||
->get();
|
||||
|
||||
foreach ($unrepostedReels as $reel) {
|
||||
@ -159,7 +139,7 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
|
||||
// Shuffling and keeping only the x first posts
|
||||
shuffle($toDownloadReels);
|
||||
$toDownloadReels = array_slice($toDownloadReels, 0, self::MAX_REPOSTS_PER_JOB);
|
||||
$toDownloadReels = array_slice($toDownloadReels, 0, config("jobs.instagramRepost.max_reposts_per_job"));
|
||||
|
||||
$this->jobRun->addArtifact(new JobArtifact([
|
||||
"name" => count($toDownloadReels) . " reels sélectionnés pour être repost",
|
||||
@ -195,7 +175,7 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
$repostSuccess = false;
|
||||
do {
|
||||
$repostSuccess = $this->repostReel($browser, $reel, $videoInfo);
|
||||
} while (!$repostSuccess && $reel->repost_tries < self::MAX_REPOST_TRIES);
|
||||
} while (!$repostSuccess && $reel->repost_tries < config("jobs.instagramRepost.max_repost_tries"));
|
||||
$repostedReelsCounter += $repostSuccess;
|
||||
}
|
||||
|
||||
@ -263,7 +243,7 @@ class InstagramRepostJob extends BrowserJob implements ShouldBeUniqueUntilProces
|
||||
["reposted" => false, "repost_tries" => 0]
|
||||
);
|
||||
|
||||
if (count($accountReels) < self::MAX_REPOSTS_PER_ACCOUNT) {
|
||||
if (count($accountReels) < config("jobs.instagramRepost.max_reposts_per_account")) {
|
||||
$accountReels[] = $reelModel; // Add it to the to be downloaded reels array
|
||||
}
|
||||
}
|
||||
|
@ -17,4 +17,28 @@ return [
|
||||
'max_runs_per_job' => 50,
|
||||
],
|
||||
|
||||
/**
|
||||
* Instagram repost job.
|
||||
*/
|
||||
'instagramRepost' => [
|
||||
/**
|
||||
* Maximum number of posts to repost per account per job run.
|
||||
*/
|
||||
'max_reposts_per_account' => 2,
|
||||
|
||||
/**
|
||||
* Max number of reposts per job
|
||||
* This is the maximum number of posts that will be reposted in a single job run.
|
||||
*
|
||||
* The value mus try to not trigge rany API limit or bot detection service.
|
||||
*/
|
||||
'max_reposts_per_job' => 3,
|
||||
|
||||
/**
|
||||
* Maximum number of tries to repost a reel
|
||||
* If a reel fails to be reposted, it will be retried up to this number of times.
|
||||
*/
|
||||
'max_repost_tries' => 3,
|
||||
],
|
||||
|
||||
];
|
||||
|
Reference in New Issue
Block a user