Diff -- /var/www/vhosts/webstls.com/httpdocs/_marketplace_push_worker.pl
Diff

/var/www/vhosts/webstls.com/httpdocs/_marketplace_push_worker.pl

added on WebSTLs (webstls.com) at 2026-07-01 22:27:11

Added
+72
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 65dd74617b8f
Restore this content →
Unified diff
Naive LCS-based line diff. Additions in emerald, deletions in rose. Both sides decompressed live from BLOB_STORE.
1#!/usr/bin/perl
2#======================================================================
3# WebSTLs - Marketplace push worker.
4#
5# Cron-driven. Picks rows from marketplace_pushes where status='pending'
6# and dispatches them to per-platform adapters defined in
7# MODS::WebSTLs::Marketplaces. Each row is updated to 'success' or
8# 'failed' in the same pass with the adapter's verdict.
9#
10# Idempotency: rows that succeeded once are not retried. Failed rows
11# stay in status='failed' until an admin or the seller re-queues
12# manually (or until a dedicated retry button is built). This matches
13# the conservative defaults on the billing worker.
14#
15# Invocation:
16# /usr/bin/perl /var/www/vhosts/webstls.com/httpdocs/_marketplace_push_worker.pl
17# Recommended cron (Plesk Scheduled Tasks):
18# */10 * * * *
19#
20# Most adapter bodies are intentionally stubs that return a clear
21# "register OAuth at <url>" error. The worker still runs them and
22# writes the error to marketplace_pushes.error_message so the UI on
23# /marketplaces.cgi shows the seller exactly why a push didn't land
24# and what needs to happen before it will.
25#======================================================================
26use strict;
27use warnings;
28
29use lib '/var/www/vhosts/webstls.com/httpdocs';
30use MODS::DBConnect;
31use MODS::WebSTLs::Config;
32use MODS::WebSTLs::Marketplaces;
33
34$|=1;
35
36my $db = MODS::DBConnect->new;
37my $cfg = MODS::WebSTLs::Config->new;
38my $mkts = MODS::WebSTLs::Marketplaces->new;
39my $DB = $cfg->settings('database_name');
40
41sub _log {
42 my ($msg) = @_;
43 my @t = localtime();
44 printf "[%04d-%02d-%02d %02d:%02d:%02d] %s\n",
45 $t[5]+1900, $t[4]+1, $t[3], $t[2], $t[1], $t[0], $msg;
46}
47
48my $dbh = $db->db_connect();
49unless ($dbh) {
50 print STDERR "marketplace_push_worker: db_connect failed\n";
51 exit 1;
52}
53
54my @pending = $mkts->pending_pushes($db, $dbh, $DB, 50);
55my $count_success = 0;
56my $count_failed = 0;
57
58foreach my $row (@pending) {
59 my $r = $mkts->run_push($db, $dbh, $DB, $row);
60 if ($r && $r->{ok}) {
61 $count_success++;
62 _log("push id=$row->{id} user=$row->{user_id} model=$row->{model_id} platform=$row->{platform}: SUCCESS " . ($r->{remote_url} || ''));
63 } else {
64 $count_failed++;
65 _log("push id=$row->{id} user=$row->{user_id} model=$row->{model_id} platform=$row->{platform}: FAILED (" . ($r->{error} || '?') . ')');
66 }
67}
68
69_log("done: pending=" . scalar(@pending) . " success=$count_success failed=$count_failed");
70
71$db->db_disconnect($dbh);
72exit 0;
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help