added on local at 2026-07-01 15:03:24
| 1 | #!/usr/bin/perl | |
| 2 | #====================================================================== | |
| 3 | # ContactForge -- subscription rollover daemon. | |
| 4 | # | |
| 5 | # Walks every active contact_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 rep 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/3dshawn.com/crm.3dshawn.com && \ | |
| 24 | # /usr/bin/perl _subscription_worker.pl >> /var/log/contactforge/sub_worker.log 2>&1 | |
| 25 | #====================================================================== | |
| 26 | use strict; | |
| 27 | use warnings; | |
| 28 | ||
| 29 | use lib '/var/www/vhosts/3dshawn.com/crm.3dshawn.com'; | |
| 30 | use MODS::DBConnect; | |
| 31 | use MODS::ContactForge::Config; | |
| 32 | use MODS::ContactForge::Subscriptions; | |
| 33 | ||
| 34 | my $db = MODS::DBConnect->new; | |
| 35 | my $cfg = MODS::ContactForge::Config->new; | |
| 36 | my $sub = MODS::ContactForge::Subscriptions->new; | |
| 37 | my $DB = $cfg->settings('database_name'); | |
| 38 | ||
| 39 | my $dbh = $db->db_connect(); | |
| 40 | unless ($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 | ||
| 46 | my $rolled = $sub->roll_periods($db, $dbh, $DB); | |
| 47 | print "[" . scalar(localtime) . "] rolled $rolled subscription period(s)\n"; | |
| 48 | ||
| 49 | $db->db_disconnect($dbh); | |
| 50 | exit 0; |