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

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

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

Added
+50
lines
Removed
-0
lines
Context
0
unchanged
Blobs
from
to 82ff26f671b6
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 -- subscription rollover daemon.
4#
5# Walks every active buyer_subscription whose current_period_end has
6# passed. For each:
7# - Advances current_period_start / current_period_end by
8# cadence_days from the plan
9# - Zeros downloads_used_this_period + shipments_used_this_period
10# - For ship_monthly plans, queues a subscription_shipments row in
11# status='queued' for the seller to fulfill
12#
13# Stripe-backed subscriptions ALSO roll on the stripe_webhook side
14# (invoice.paid -> activate_from_stripe). This worker is the catch-all
15# for subscriptions that aren't on Stripe (the v1 "instant active" mode
16# used when Stripe isn't configured), and a safety net in case a
17# webhook is lost.
18#
19# Run from cron (daily is fine; hourly OK too -- the worker is
20# idempotent: it only touches subscriptions whose period has actually
21# expired):
22#
23# 0 3 * * * cd /var/www/vhosts/webstls.com/httpdocs && \
24# /usr/bin/perl _subscription_worker.pl >> /var/log/webstls/sub_worker.log 2>&1
25#======================================================================
26use strict;
27use warnings;
28
29use lib '/var/www/vhosts/webstls.com/httpdocs';
30use MODS::DBConnect;
31use MODS::WebSTLs::Config;
32use MODS::WebSTLs::Subscriptions;
33
34my $db = MODS::DBConnect->new;
35my $cfg = MODS::WebSTLs::Config->new;
36my $sub = MODS::WebSTLs::Subscriptions->new;
37my $DB = $cfg->settings('database_name');
38
39my $dbh = $db->db_connect();
40unless ($sub->schema_ready($db, $dbh, $DB)) {
41 $db->db_disconnect($dbh);
42 print "[" . scalar(localtime) . "] subscription schema not installed; skipping\n";
43 exit 0;
44}
45
46my $rolled = $sub->roll_periods($db, $dbh, $DB);
47print "[" . scalar(localtime) . "] rolled $rolled subscription period(s)\n";
48
49$db->db_disconnect($dbh);
50exit 0;
Keyboard: j next diff k previous diff g top G bottom r restore c compile-check ? help