Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/hub/run/stripe-sync.js
Views: 687
#!/usr/bin/node12/*3ALMOST DEPRECATED - THIS EXISTS ONLY TO SUPPORT THE LEGACY UPGRADE SUBSCRIPTIONS.451. Periodically pull all data from Stripe for now. The only point of this is6to ensure there isn't drift between stripe and our database. Any time a user7actually looks at their subscription info, or an admin updates the stripe info8(by 'add user to stripe' in account settings) the info is also synced. So this9is not super important.1011TODO: Obviously, we should redo this to only pull maybe once per week (?) AND12also have a webhook so that any changes in stripe are immediately reflected here...13142. Periodically1516This is run as a singleton deployment on some preemptible.17*/1819const ms = require("ms");20const postgres = require("@cocalc/database");21const { stripe_sync } = require("@cocalc/server/stripe/sync");22const { callback2 } = require("@cocalc/util/async-utils");2324const db = postgres.db({ ensure_exists: false });2526async function do_stripe_sync() {27console.log("doing stripe_sync...");28await stripe_sync({29database: db,30logger: { debug: console.log },31});32console.log("did stripe_sync");33}3435// make sure all user upgrades to projects are valid and consistent36// (e.g. if upgrades expire remove them)37async function upgrade_check() {38console.log("doing project upgrade_check...");39await callback2(db.ensure_all_user_project_upgrades_are_valid.bind(db), {40limit: 1,41});42console.log("done with project upgrade_check");43}4445async function main() {46console.log("doing the stripe related periodic tasks...");47try {48await do_stripe_sync();49} catch (err) {50console.log(`ERROR do_stripe_sync -- ${err}`);51}52try {53await upgrade_check();54} catch (err) {55console.log(`ERROR upgrade_check -- ${err}`);56}57console.log("success -- waiting 11 hours before doing this again...");58setTimeout(main, ms("11 hours"));59}6061main();626364