[{"data":1,"prerenderedAt":14845},["ShallowReactive",2],{"guides-/guides/distributed-execution":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"navigation":10,"body":11,"_type":14839,"_id":14840,"_source":14841,"_file":14842,"_stem":14843,"_extension":14844},"/guides/distributed-execution","guides",false,"","Distributed Execution","Run large or long-running jobs reliably with batches and loops",{"title":8},{"type":12,"children":13,"toc":14779},"root",[14,23,37,78,83,92,120,125,132,137,191,196,202,207,301,313,319,324,331,349,544,556,779,791,804,808,814,819,1078,1083,1145,1166,1171,1375,1380,1385,1507,1512,1515,1521,1556,1568,1573,1793,1813,1825,1866,1987,2163,2185,2190,2241,2255,2303,2306,2312,2332,2344,2357,2370,2382,2385,2391,2403,2570,2582,2585,2591,2610,2622,2738,2759,2778,2781,2787,2805,2817,2822,2946,2965,2968,2979,2992,3010,3021,3282,3309,3319,3322,3328,3340,3345,3357,3362,3401,3413,3425,3533,3544,3828,3841,3853,3865,3972,3977,4214,4227,4239,4251,4256,4374,4379,4599,4619,4631,4637,4748,4751,4757,4769,4957,4983,4994,4997,5003,5008,5014,5024,5719,6236,6580,6585,6636,6639,6645,6654,7113,7649,7654,7657,7663,7672,8131,8136,8270,8704,9121,9133,9161,9164,9170,9179,9536,9917,10408,10634,10646,10649,10655,10664,10676,10932,11306,11311,11314,11320,11329,11341,11798,11801,11807,11816,11821,12026,12054,12059,12064,12179,12309,12322,12325,12331,12336,12403,12406,12412,12564,12567,12573,12583,12596,12959,12970,13110,13120,13131,13281,13287,13306,13648,13666,13669,13675,13681,13692,13803,14315,14321,14326,14436,14457,14463,14468,14597,14618,14621,14627,14640,14664,14669,14672,14678,14683,14723,14728,14731,14737,14773],{"type":15,"tag":16,"props":17,"children":19},"element","h1",{"id":18},"distributed-execution-guide",[20],{"type":21,"value":22},"text","Distributed Execution Guide",{"type":15,"tag":24,"props":25,"children":26},"p",{},[27,29,35],{"type":21,"value":28},"Most action scripts you write run a small, predictable amount of work and finish in a fraction of a second. But sometimes you need to do something ",{"type":15,"tag":30,"props":31,"children":32},"strong",{},[33],{"type":21,"value":34},"bigger",{"type":21,"value":36},":",{"type":15,"tag":38,"props":39,"children":40},"ul",{},[41,54,66],{"type":15,"tag":42,"props":43,"children":44},"li",{},[45,47,52],{"type":21,"value":46},"Send a personalised welcome email to ",{"type":15,"tag":30,"props":48,"children":49},{},[50],{"type":21,"value":51},"every",{"type":21,"value":53}," user who signed up in the last week.",{"type":15,"tag":42,"props":55,"children":56},{},[57,59,64],{"type":21,"value":58},"Sync the ",{"type":15,"tag":30,"props":60,"children":61},{},[62],{"type":21,"value":63},"full",{"type":21,"value":65}," product catalogue from a partner's API into your database.",{"type":15,"tag":42,"props":67,"children":68},{},[69,71,76],{"type":21,"value":70},"Generate a PDF for ",{"type":15,"tag":30,"props":72,"children":73},{},[74],{"type":21,"value":75},"each",{"type":21,"value":77}," of 50,000 customers when the monthly invoicing job runs.",{"type":15,"tag":24,"props":79,"children":80},{},[81],{"type":21,"value":82},"These jobs share a property that breaks the simple action model: they take long enough that you can't reasonably wait inside a single script. They also tend to be brittle — if a script crashes halfway through, you lose your place. If the server restarts, you lose everything.",{"type":15,"tag":24,"props":84,"children":85},{},[86,90],{"type":15,"tag":30,"props":87,"children":88},{},[89],{"type":21,"value":8},{"type":21,"value":91}," is Appivo's solution for these cases. It lets you express jobs like the ones above in a few lines of JavaScript, and it takes care of the awkward parts:",{"type":15,"tag":38,"props":93,"children":94},{},[95,100,105,110,115],{"type":15,"tag":42,"props":96,"children":97},{},[98],{"type":21,"value":99},"splitting work into many small action invocations,",{"type":15,"tag":42,"props":101,"children":102},{},[103],{"type":21,"value":104},"running them in parallel across all your worker instances,",{"type":15,"tag":42,"props":106,"children":107},{},[108],{"type":21,"value":109},"tracking which ones finished and which ones didn't,",{"type":15,"tag":42,"props":111,"children":112},{},[113],{"type":21,"value":114},"tolerating worker crashes, server restarts, and message redelivery,",{"type":15,"tag":42,"props":116,"children":117},{},[118],{"type":21,"value":119},"running a wrap-up action when everything is done.",{"type":15,"tag":24,"props":121,"children":122},{},[123],{"type":21,"value":124},"You don't need to understand any distributed-systems machinery to use it. This guide walks through everything you need.",{"type":15,"tag":126,"props":127,"children":129},"h2",{"id":128},"when-to-use-this",[130],{"type":21,"value":131},"When To Use This",{"type":15,"tag":24,"props":133,"children":134},{},[135],{"type":21,"value":136},"Reach for distributed execution whenever you have a task that:",{"type":15,"tag":38,"props":138,"children":139},{},[140,152,162,174,186],{"type":15,"tag":42,"props":141,"children":142},{},[143,145,150],{"type":21,"value":144},"Operates on a ",{"type":15,"tag":30,"props":146,"children":147},{},[148],{"type":21,"value":149},"large set of records",{"type":21,"value":151}," (hundreds, thousands, or millions).",{"type":15,"tag":42,"props":153,"children":154},{},[155,160],{"type":15,"tag":30,"props":156,"children":157},{},[158],{"type":21,"value":159},"Takes longer than a few seconds",{"type":21,"value":161}," in total.",{"type":15,"tag":42,"props":163,"children":164},{},[165,167,172],{"type":21,"value":166},"Can be ",{"type":15,"tag":30,"props":168,"children":169},{},[170],{"type":21,"value":171},"broken into smaller, independent units",{"type":21,"value":173}," of work.",{"type":15,"tag":42,"props":175,"children":176},{},[177,179,184],{"type":21,"value":178},"Calls ",{"type":15,"tag":30,"props":180,"children":181},{},[182],{"type":21,"value":183},"slow external services",{"type":21,"value":185}," (APIs, mail servers, payment gateways).",{"type":15,"tag":42,"props":187,"children":188},{},[189],{"type":21,"value":190},"Should keep going even if a worker crashes or the server restarts.",{"type":15,"tag":24,"props":192,"children":193},{},[194],{"type":21,"value":195},"If your script handles a single record, or finishes in well under a second, a regular SCRIPT action is the right choice. Distributed execution is for the heavy stuff.",{"type":15,"tag":126,"props":197,"children":199},{"id":198},"two-patterns-batches-and-loops",[200],{"type":21,"value":201},"Two Patterns: Batches and Loops",{"type":15,"tag":24,"props":203,"children":204},{},[205],{"type":21,"value":206},"There are two shapes of \"big job\" you can express. They solve different problems.",{"type":15,"tag":208,"props":209,"children":210},"table",{},[211,235],{"type":15,"tag":212,"props":213,"children":214},"thead",{},[215],{"type":15,"tag":216,"props":217,"children":218},"tr",{},[219,225,230],{"type":15,"tag":220,"props":221,"children":222},"th",{},[223],{"type":21,"value":224},"Pattern",{"type":15,"tag":220,"props":226,"children":227},{},[228],{"type":21,"value":229},"Use When",{"type":15,"tag":220,"props":231,"children":232},{},[233],{"type":21,"value":234},"Example",{"type":15,"tag":236,"props":237,"children":238},"tbody",{},[239,272],{"type":15,"tag":216,"props":240,"children":241},{},[242,262,267],{"type":15,"tag":243,"props":244,"children":245},"td",{},[246,251,253,260],{"type":15,"tag":30,"props":247,"children":248},{},[249],{"type":21,"value":250},"Batch",{"type":21,"value":252}," (",{"type":15,"tag":254,"props":255,"children":257},"code",{"className":256},[],[258],{"type":21,"value":259},"createBatch",{"type":21,"value":261},")",{"type":15,"tag":243,"props":263,"children":264},{},[265],{"type":21,"value":266},"You have a known list of items to process the same way, in parallel",{"type":15,"tag":243,"props":268,"children":269},{},[270],{"type":21,"value":271},"\"Send an email to each user in this list\"",{"type":15,"tag":216,"props":273,"children":274},{},[275,291,296],{"type":15,"tag":243,"props":276,"children":277},{},[278,283,284,290],{"type":15,"tag":30,"props":279,"children":280},{},[281],{"type":21,"value":282},"Loop",{"type":21,"value":252},{"type":15,"tag":254,"props":285,"children":287},{"className":286},[],[288],{"type":21,"value":289},"createLoop",{"type":21,"value":261},{"type":15,"tag":243,"props":292,"children":293},{},[294],{"type":21,"value":295},"You have a sequential job whose endpoint you don't know up-front",{"type":15,"tag":243,"props":297,"children":298},{},[299],{"type":21,"value":300},"\"Keep paginating through the partner's API until they say there's no more data\"",{"type":15,"tag":24,"props":302,"children":303},{},[304,306,311],{"type":21,"value":305},"If you can't decide: ",{"type":15,"tag":30,"props":307,"children":308},{},[309],{"type":21,"value":310},"try a batch first",{"type":21,"value":312},". They're more common and easier to reason about. Loops are the right answer when \"the next thing depends on what happened in the last thing.\"",{"type":15,"tag":126,"props":314,"children":316},{"id":315},"a-non-negotiable-rule-before-you-start",[317],{"type":21,"value":318},"A Non-Negotiable Rule Before You Start",{"type":15,"tag":24,"props":320,"children":321},{},[322],{"type":21,"value":323},"Before showing the first example, there is one rule that applies to every action script in the platform:",{"type":15,"tag":325,"props":326,"children":328},"h3",{"id":327},"always-close-query-results",[329],{"type":21,"value":330},"Always Close Query Results",{"type":15,"tag":24,"props":332,"children":333},{},[334,340,342,347],{"type":15,"tag":254,"props":335,"children":337},{"className":336},[],[338],{"type":21,"value":339},"context.query()",{"type":21,"value":341}," returns a cursor that holds an open database transaction. ",{"type":15,"tag":30,"props":343,"children":344},{},[345],{"type":21,"value":346},"It must be closed",{"type":21,"value":348},", or you risk leaking transactions and exhausting the connection pool. The standard idiom is:",{"type":15,"tag":350,"props":351,"children":355},"pre",{"className":352,"code":353,"language":354,"meta":7,"style":7},"language-javascript shiki shiki-themes github-light github-dark","let result = context.query(\"select u from user u where u.active = true\");\ntry {\n    while (result.hasNext()) {\n        let user = result.next();\n        // ... use it\n    }\n} finally {\n    result.close();\n}\n","javascript",[356],{"type":15,"tag":254,"props":357,"children":358},{"__ignoreMap":7},[359,409,423,447,480,490,499,517,535],{"type":15,"tag":360,"props":361,"children":364},"span",{"class":362,"line":363},"line",1,[365,371,377,382,387,393,398,404],{"type":15,"tag":360,"props":366,"children":368},{"style":367},"--shiki-default:#D73A49;--shiki-dark:#F97583",[369],{"type":21,"value":370},"let",{"type":15,"tag":360,"props":372,"children":374},{"style":373},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[375],{"type":21,"value":376}," result ",{"type":15,"tag":360,"props":378,"children":379},{"style":367},[380],{"type":21,"value":381},"=",{"type":15,"tag":360,"props":383,"children":384},{"style":373},[385],{"type":21,"value":386}," context.",{"type":15,"tag":360,"props":388,"children":390},{"style":389},"--shiki-default:#6F42C1;--shiki-dark:#B392F0",[391],{"type":21,"value":392},"query",{"type":15,"tag":360,"props":394,"children":395},{"style":373},[396],{"type":21,"value":397},"(",{"type":15,"tag":360,"props":399,"children":401},{"style":400},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[402],{"type":21,"value":403},"\"select u from user u where u.active = true\"",{"type":15,"tag":360,"props":405,"children":406},{"style":373},[407],{"type":21,"value":408},");\n",{"type":15,"tag":360,"props":410,"children":412},{"class":362,"line":411},2,[413,418],{"type":15,"tag":360,"props":414,"children":415},{"style":367},[416],{"type":21,"value":417},"try",{"type":15,"tag":360,"props":419,"children":420},{"style":373},[421],{"type":21,"value":422}," {\n",{"type":15,"tag":360,"props":424,"children":426},{"class":362,"line":425},3,[427,432,437,442],{"type":15,"tag":360,"props":428,"children":429},{"style":367},[430],{"type":21,"value":431},"    while",{"type":15,"tag":360,"props":433,"children":434},{"style":373},[435],{"type":21,"value":436}," (result.",{"type":15,"tag":360,"props":438,"children":439},{"style":389},[440],{"type":21,"value":441},"hasNext",{"type":15,"tag":360,"props":443,"children":444},{"style":373},[445],{"type":21,"value":446},"()) {\n",{"type":15,"tag":360,"props":448,"children":450},{"class":362,"line":449},4,[451,456,461,465,470,475],{"type":15,"tag":360,"props":452,"children":453},{"style":367},[454],{"type":21,"value":455},"        let",{"type":15,"tag":360,"props":457,"children":458},{"style":373},[459],{"type":21,"value":460}," user ",{"type":15,"tag":360,"props":462,"children":463},{"style":367},[464],{"type":21,"value":381},{"type":15,"tag":360,"props":466,"children":467},{"style":373},[468],{"type":21,"value":469}," result.",{"type":15,"tag":360,"props":471,"children":472},{"style":389},[473],{"type":21,"value":474},"next",{"type":15,"tag":360,"props":476,"children":477},{"style":373},[478],{"type":21,"value":479},"();\n",{"type":15,"tag":360,"props":481,"children":483},{"class":362,"line":482},5,[484],{"type":15,"tag":360,"props":485,"children":487},{"style":486},"--shiki-default:#6A737D;--shiki-dark:#6A737D",[488],{"type":21,"value":489},"        // ... use it\n",{"type":15,"tag":360,"props":491,"children":493},{"class":362,"line":492},6,[494],{"type":15,"tag":360,"props":495,"children":496},{"style":373},[497],{"type":21,"value":498},"    }\n",{"type":15,"tag":360,"props":500,"children":502},{"class":362,"line":501},7,[503,508,513],{"type":15,"tag":360,"props":504,"children":505},{"style":373},[506],{"type":21,"value":507},"} ",{"type":15,"tag":360,"props":509,"children":510},{"style":367},[511],{"type":21,"value":512},"finally",{"type":15,"tag":360,"props":514,"children":515},{"style":373},[516],{"type":21,"value":422},{"type":15,"tag":360,"props":518,"children":520},{"class":362,"line":519},8,[521,526,531],{"type":15,"tag":360,"props":522,"children":523},{"style":373},[524],{"type":21,"value":525},"    result.",{"type":15,"tag":360,"props":527,"children":528},{"style":389},[529],{"type":21,"value":530},"close",{"type":15,"tag":360,"props":532,"children":533},{"style":373},[534],{"type":21,"value":479},{"type":15,"tag":360,"props":536,"children":538},{"class":362,"line":537},9,[539],{"type":15,"tag":360,"props":540,"children":541},{"style":373},[542],{"type":21,"value":543},"}\n",{"type":15,"tag":24,"props":545,"children":546},{},[547,549,554],{"type":21,"value":548},"When you use a batch in the same script, the ",{"type":15,"tag":254,"props":550,"children":552},{"className":551},[],[553],{"type":21,"value":512},{"type":21,"value":555}," block also seals the batch:",{"type":15,"tag":350,"props":557,"children":559},{"className":352,"code":558,"language":354,"meta":7,"style":7},"let users = context.query(\"select u from user u where u.invited = false\");\nlet batch = context.createBatch({ /* ... */ });\ntry {\n    while (users.hasNext()) {\n        batch.add(\"sendOneInvitation\", users.next(), null);\n    }\n} finally {\n    users.close();\n    batch.seal();\n}\n",[560],{"type":15,"tag":254,"props":561,"children":562},{"__ignoreMap":7},[563,600,639,650,670,716,723,738,754,771],{"type":15,"tag":360,"props":564,"children":565},{"class":362,"line":363},[566,570,575,579,583,587,591,596],{"type":15,"tag":360,"props":567,"children":568},{"style":367},[569],{"type":21,"value":370},{"type":15,"tag":360,"props":571,"children":572},{"style":373},[573],{"type":21,"value":574}," users ",{"type":15,"tag":360,"props":576,"children":577},{"style":367},[578],{"type":21,"value":381},{"type":15,"tag":360,"props":580,"children":581},{"style":373},[582],{"type":21,"value":386},{"type":15,"tag":360,"props":584,"children":585},{"style":389},[586],{"type":21,"value":392},{"type":15,"tag":360,"props":588,"children":589},{"style":373},[590],{"type":21,"value":397},{"type":15,"tag":360,"props":592,"children":593},{"style":400},[594],{"type":21,"value":595},"\"select u from user u where u.invited = false\"",{"type":15,"tag":360,"props":597,"children":598},{"style":373},[599],{"type":21,"value":408},{"type":15,"tag":360,"props":601,"children":602},{"class":362,"line":411},[603,607,612,616,620,624,629,634],{"type":15,"tag":360,"props":604,"children":605},{"style":367},[606],{"type":21,"value":370},{"type":15,"tag":360,"props":608,"children":609},{"style":373},[610],{"type":21,"value":611}," batch ",{"type":15,"tag":360,"props":613,"children":614},{"style":367},[615],{"type":21,"value":381},{"type":15,"tag":360,"props":617,"children":618},{"style":373},[619],{"type":21,"value":386},{"type":15,"tag":360,"props":621,"children":622},{"style":389},[623],{"type":21,"value":259},{"type":15,"tag":360,"props":625,"children":626},{"style":373},[627],{"type":21,"value":628},"({ ",{"type":15,"tag":360,"props":630,"children":631},{"style":486},[632],{"type":21,"value":633},"/* ... */",{"type":15,"tag":360,"props":635,"children":636},{"style":373},[637],{"type":21,"value":638}," });\n",{"type":15,"tag":360,"props":640,"children":641},{"class":362,"line":425},[642,646],{"type":15,"tag":360,"props":643,"children":644},{"style":367},[645],{"type":21,"value":417},{"type":15,"tag":360,"props":647,"children":648},{"style":373},[649],{"type":21,"value":422},{"type":15,"tag":360,"props":651,"children":652},{"class":362,"line":449},[653,657,662,666],{"type":15,"tag":360,"props":654,"children":655},{"style":367},[656],{"type":21,"value":431},{"type":15,"tag":360,"props":658,"children":659},{"style":373},[660],{"type":21,"value":661}," (users.",{"type":15,"tag":360,"props":663,"children":664},{"style":389},[665],{"type":21,"value":441},{"type":15,"tag":360,"props":667,"children":668},{"style":373},[669],{"type":21,"value":446},{"type":15,"tag":360,"props":671,"children":672},{"class":362,"line":482},[673,678,683,687,692,697,701,706,712],{"type":15,"tag":360,"props":674,"children":675},{"style":373},[676],{"type":21,"value":677},"        batch.",{"type":15,"tag":360,"props":679,"children":680},{"style":389},[681],{"type":21,"value":682},"add",{"type":15,"tag":360,"props":684,"children":685},{"style":373},[686],{"type":21,"value":397},{"type":15,"tag":360,"props":688,"children":689},{"style":400},[690],{"type":21,"value":691},"\"sendOneInvitation\"",{"type":15,"tag":360,"props":693,"children":694},{"style":373},[695],{"type":21,"value":696},", users.",{"type":15,"tag":360,"props":698,"children":699},{"style":389},[700],{"type":21,"value":474},{"type":15,"tag":360,"props":702,"children":703},{"style":373},[704],{"type":21,"value":705},"(), ",{"type":15,"tag":360,"props":707,"children":709},{"style":708},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[710],{"type":21,"value":711},"null",{"type":15,"tag":360,"props":713,"children":714},{"style":373},[715],{"type":21,"value":408},{"type":15,"tag":360,"props":717,"children":718},{"class":362,"line":492},[719],{"type":15,"tag":360,"props":720,"children":721},{"style":373},[722],{"type":21,"value":498},{"type":15,"tag":360,"props":724,"children":725},{"class":362,"line":501},[726,730,734],{"type":15,"tag":360,"props":727,"children":728},{"style":373},[729],{"type":21,"value":507},{"type":15,"tag":360,"props":731,"children":732},{"style":367},[733],{"type":21,"value":512},{"type":15,"tag":360,"props":735,"children":736},{"style":373},[737],{"type":21,"value":422},{"type":15,"tag":360,"props":739,"children":740},{"class":362,"line":519},[741,746,750],{"type":15,"tag":360,"props":742,"children":743},{"style":373},[744],{"type":21,"value":745},"    users.",{"type":15,"tag":360,"props":747,"children":748},{"style":389},[749],{"type":21,"value":530},{"type":15,"tag":360,"props":751,"children":752},{"style":373},[753],{"type":21,"value":479},{"type":15,"tag":360,"props":755,"children":756},{"class":362,"line":537},[757,762,767],{"type":15,"tag":360,"props":758,"children":759},{"style":373},[760],{"type":21,"value":761},"    batch.",{"type":15,"tag":360,"props":763,"children":764},{"style":389},[765],{"type":21,"value":766},"seal",{"type":15,"tag":360,"props":768,"children":769},{"style":373},[770],{"type":21,"value":479},{"type":15,"tag":360,"props":772,"children":774},{"class":362,"line":773},10,[775],{"type":15,"tag":360,"props":776,"children":777},{"style":373},[778],{"type":21,"value":543},{"type":15,"tag":24,"props":780,"children":781},{},[782,784,789],{"type":21,"value":783},"Both calls in the ",{"type":15,"tag":254,"props":785,"children":787},{"className":786},[],[788],{"type":21,"value":512},{"type":21,"value":790}," block are unconditional and idempotent — closing a closed cursor and sealing a sealed batch are both safe no-ops. So even on errors, both resources are cleaned up properly.",{"type":15,"tag":24,"props":792,"children":793},{},[794,796,802],{"type":21,"value":795},"Get into this habit early. It's the same pattern as ",{"type":15,"tag":254,"props":797,"children":799},{"className":798},[],[800],{"type":21,"value":801},"try-finally",{"type":21,"value":803}," around any resource handle.",{"type":15,"tag":805,"props":806,"children":807},"hr",{},[],{"type":15,"tag":126,"props":809,"children":811},{"id":810},"your-first-batch",[812],{"type":21,"value":813},"Your First Batch",{"type":15,"tag":24,"props":815,"children":816},{},[817],{"type":21,"value":818},"Here is the simplest possible example. We'll send an invitation email to every user who hasn't been invited yet.",{"type":15,"tag":350,"props":820,"children":822},{"className":352,"code":821,"language":354,"meta":7,"style":7},"// Action: \"sendInvitations\"\n\nlet users = context.query(\"select u from user u where u.invited = false\");\nlet batch = context.createBatch({\n    onSuccess: \"invitationsCompleted\",\n    onError:   \"invitationsFailed\"\n});\ntry {\n    while (users.hasNext()) {\n        batch.add(\"sendOneInvitation\", users.next(), null);\n    }\n} finally {\n    users.close();\n    batch.seal();\n}\n",[823],{"type":15,"tag":254,"props":824,"children":825},{"__ignoreMap":7},[826,834,843,878,906,924,937,945,956,975,1014,1022,1038,1054,1070],{"type":15,"tag":360,"props":827,"children":828},{"class":362,"line":363},[829],{"type":15,"tag":360,"props":830,"children":831},{"style":486},[832],{"type":21,"value":833},"// Action: \"sendInvitations\"\n",{"type":15,"tag":360,"props":835,"children":836},{"class":362,"line":411},[837],{"type":15,"tag":360,"props":838,"children":840},{"emptyLinePlaceholder":839},true,[841],{"type":21,"value":842},"\n",{"type":15,"tag":360,"props":844,"children":845},{"class":362,"line":425},[846,850,854,858,862,866,870,874],{"type":15,"tag":360,"props":847,"children":848},{"style":367},[849],{"type":21,"value":370},{"type":15,"tag":360,"props":851,"children":852},{"style":373},[853],{"type":21,"value":574},{"type":15,"tag":360,"props":855,"children":856},{"style":367},[857],{"type":21,"value":381},{"type":15,"tag":360,"props":859,"children":860},{"style":373},[861],{"type":21,"value":386},{"type":15,"tag":360,"props":863,"children":864},{"style":389},[865],{"type":21,"value":392},{"type":15,"tag":360,"props":867,"children":868},{"style":373},[869],{"type":21,"value":397},{"type":15,"tag":360,"props":871,"children":872},{"style":400},[873],{"type":21,"value":595},{"type":15,"tag":360,"props":875,"children":876},{"style":373},[877],{"type":21,"value":408},{"type":15,"tag":360,"props":879,"children":880},{"class":362,"line":449},[881,885,889,893,897,901],{"type":15,"tag":360,"props":882,"children":883},{"style":367},[884],{"type":21,"value":370},{"type":15,"tag":360,"props":886,"children":887},{"style":373},[888],{"type":21,"value":611},{"type":15,"tag":360,"props":890,"children":891},{"style":367},[892],{"type":21,"value":381},{"type":15,"tag":360,"props":894,"children":895},{"style":373},[896],{"type":21,"value":386},{"type":15,"tag":360,"props":898,"children":899},{"style":389},[900],{"type":21,"value":259},{"type":15,"tag":360,"props":902,"children":903},{"style":373},[904],{"type":21,"value":905},"({\n",{"type":15,"tag":360,"props":907,"children":908},{"class":362,"line":482},[909,914,919],{"type":15,"tag":360,"props":910,"children":911},{"style":373},[912],{"type":21,"value":913},"    onSuccess: ",{"type":15,"tag":360,"props":915,"children":916},{"style":400},[917],{"type":21,"value":918},"\"invitationsCompleted\"",{"type":15,"tag":360,"props":920,"children":921},{"style":373},[922],{"type":21,"value":923},",\n",{"type":15,"tag":360,"props":925,"children":926},{"class":362,"line":492},[927,932],{"type":15,"tag":360,"props":928,"children":929},{"style":373},[930],{"type":21,"value":931},"    onError:   ",{"type":15,"tag":360,"props":933,"children":934},{"style":400},[935],{"type":21,"value":936},"\"invitationsFailed\"\n",{"type":15,"tag":360,"props":938,"children":939},{"class":362,"line":501},[940],{"type":15,"tag":360,"props":941,"children":942},{"style":373},[943],{"type":21,"value":944},"});\n",{"type":15,"tag":360,"props":946,"children":947},{"class":362,"line":519},[948,952],{"type":15,"tag":360,"props":949,"children":950},{"style":367},[951],{"type":21,"value":417},{"type":15,"tag":360,"props":953,"children":954},{"style":373},[955],{"type":21,"value":422},{"type":15,"tag":360,"props":957,"children":958},{"class":362,"line":537},[959,963,967,971],{"type":15,"tag":360,"props":960,"children":961},{"style":367},[962],{"type":21,"value":431},{"type":15,"tag":360,"props":964,"children":965},{"style":373},[966],{"type":21,"value":661},{"type":15,"tag":360,"props":968,"children":969},{"style":389},[970],{"type":21,"value":441},{"type":15,"tag":360,"props":972,"children":973},{"style":373},[974],{"type":21,"value":446},{"type":15,"tag":360,"props":976,"children":977},{"class":362,"line":773},[978,982,986,990,994,998,1002,1006,1010],{"type":15,"tag":360,"props":979,"children":980},{"style":373},[981],{"type":21,"value":677},{"type":15,"tag":360,"props":983,"children":984},{"style":389},[985],{"type":21,"value":682},{"type":15,"tag":360,"props":987,"children":988},{"style":373},[989],{"type":21,"value":397},{"type":15,"tag":360,"props":991,"children":992},{"style":400},[993],{"type":21,"value":691},{"type":15,"tag":360,"props":995,"children":996},{"style":373},[997],{"type":21,"value":696},{"type":15,"tag":360,"props":999,"children":1000},{"style":389},[1001],{"type":21,"value":474},{"type":15,"tag":360,"props":1003,"children":1004},{"style":373},[1005],{"type":21,"value":705},{"type":15,"tag":360,"props":1007,"children":1008},{"style":708},[1009],{"type":21,"value":711},{"type":15,"tag":360,"props":1011,"children":1012},{"style":373},[1013],{"type":21,"value":408},{"type":15,"tag":360,"props":1015,"children":1017},{"class":362,"line":1016},11,[1018],{"type":15,"tag":360,"props":1019,"children":1020},{"style":373},[1021],{"type":21,"value":498},{"type":15,"tag":360,"props":1023,"children":1025},{"class":362,"line":1024},12,[1026,1030,1034],{"type":15,"tag":360,"props":1027,"children":1028},{"style":373},[1029],{"type":21,"value":507},{"type":15,"tag":360,"props":1031,"children":1032},{"style":367},[1033],{"type":21,"value":512},{"type":15,"tag":360,"props":1035,"children":1036},{"style":373},[1037],{"type":21,"value":422},{"type":15,"tag":360,"props":1039,"children":1041},{"class":362,"line":1040},13,[1042,1046,1050],{"type":15,"tag":360,"props":1043,"children":1044},{"style":373},[1045],{"type":21,"value":745},{"type":15,"tag":360,"props":1047,"children":1048},{"style":389},[1049],{"type":21,"value":530},{"type":15,"tag":360,"props":1051,"children":1052},{"style":373},[1053],{"type":21,"value":479},{"type":15,"tag":360,"props":1055,"children":1057},{"class":362,"line":1056},14,[1058,1062,1066],{"type":15,"tag":360,"props":1059,"children":1060},{"style":373},[1061],{"type":21,"value":761},{"type":15,"tag":360,"props":1063,"children":1064},{"style":389},[1065],{"type":21,"value":766},{"type":15,"tag":360,"props":1067,"children":1068},{"style":373},[1069],{"type":21,"value":479},{"type":15,"tag":360,"props":1071,"children":1073},{"class":362,"line":1072},15,[1074],{"type":15,"tag":360,"props":1075,"children":1076},{"style":373},[1077],{"type":21,"value":543},{"type":15,"tag":24,"props":1079,"children":1080},{},[1081],{"type":21,"value":1082},"That's it. Three things happen here:",{"type":15,"tag":1084,"props":1085,"children":1086},"ol",{},[1087,1101,1131],{"type":15,"tag":42,"props":1088,"children":1089},{},[1090,1099],{"type":15,"tag":30,"props":1091,"children":1092},{},[1093],{"type":15,"tag":254,"props":1094,"children":1096},{"className":1095},[],[1097],{"type":21,"value":1098},"createBatch(...)",{"type":21,"value":1100}," registers a new batch with the platform. You give it the names of two follow-up actions: one to run when everything finishes successfully, and one to run if things go wrong.",{"type":15,"tag":42,"props":1102,"children":1103},{},[1104,1113,1115,1121,1123,1129],{"type":15,"tag":30,"props":1105,"children":1106},{},[1107],{"type":15,"tag":254,"props":1108,"children":1110},{"className":1109},[],[1111],{"type":21,"value":1112},"batch.add(...)",{"type":21,"value":1114}," schedules a single child action to run. Each call queues one invocation of ",{"type":15,"tag":254,"props":1116,"children":1118},{"className":1117},[],[1119],{"type":21,"value":1120},"sendOneInvitation",{"type":21,"value":1122}," with one ",{"type":15,"tag":254,"props":1124,"children":1126},{"className":1125},[],[1127],{"type":21,"value":1128},"user",{"type":21,"value":1130}," record bound to it. The children run on whichever worker instances are free — you don't have to pick.",{"type":15,"tag":42,"props":1132,"children":1133},{},[1134,1143],{"type":15,"tag":30,"props":1135,"children":1136},{},[1137],{"type":15,"tag":254,"props":1138,"children":1140},{"className":1139},[],[1141],{"type":21,"value":1142},"batch.seal()",{"type":21,"value":1144}," tells the platform \"I'm done adding work — start watching for completion.\"",{"type":15,"tag":24,"props":1146,"children":1147},{},[1148,1150,1156,1158,1164],{"type":21,"value":1149},"After ",{"type":15,"tag":254,"props":1151,"children":1153},{"className":1152},[],[1154],{"type":21,"value":1155},"seal()",{"type":21,"value":1157}," returns, this script is finished. The 8,000 (or however many) child invocations run in the background. The platform tracks how many succeed and how many fail. When the last one finishes, the platform automatically schedules ",{"type":15,"tag":254,"props":1159,"children":1161},{"className":1160},[],[1162],{"type":21,"value":1163},"invitationsCompleted",{"type":21,"value":1165}," and runs it.",{"type":15,"tag":24,"props":1167,"children":1168},{},[1169],{"type":21,"value":1170},"The child action looks like any other action you'd write:",{"type":15,"tag":350,"props":1172,"children":1174},{"className":352,"code":1173,"language":354,"meta":7,"style":7},"// Action: \"sendOneInvitation\"\n\nlet user = context.getRecord();   // the user record passed via batch.add\ncontext.sendMail({\n    to:      user.get(\"email\"),\n    subject: \"You're invited!\",\n    body:    context.renderTemplate(\"invitation\", user)\n});\nuser.set(\"invited\", true);\ncontext.update(user);\n",[1175],{"type":15,"tag":254,"props":1176,"children":1177},{"__ignoreMap":7},[1178,1186,1193,1227,1244,1271,1288,1315,1322,1358],{"type":15,"tag":360,"props":1179,"children":1180},{"class":362,"line":363},[1181],{"type":15,"tag":360,"props":1182,"children":1183},{"style":486},[1184],{"type":21,"value":1185},"// Action: \"sendOneInvitation\"\n",{"type":15,"tag":360,"props":1187,"children":1188},{"class":362,"line":411},[1189],{"type":15,"tag":360,"props":1190,"children":1191},{"emptyLinePlaceholder":839},[1192],{"type":21,"value":842},{"type":15,"tag":360,"props":1194,"children":1195},{"class":362,"line":425},[1196,1200,1204,1208,1212,1217,1222],{"type":15,"tag":360,"props":1197,"children":1198},{"style":367},[1199],{"type":21,"value":370},{"type":15,"tag":360,"props":1201,"children":1202},{"style":373},[1203],{"type":21,"value":460},{"type":15,"tag":360,"props":1205,"children":1206},{"style":367},[1207],{"type":21,"value":381},{"type":15,"tag":360,"props":1209,"children":1210},{"style":373},[1211],{"type":21,"value":386},{"type":15,"tag":360,"props":1213,"children":1214},{"style":389},[1215],{"type":21,"value":1216},"getRecord",{"type":15,"tag":360,"props":1218,"children":1219},{"style":373},[1220],{"type":21,"value":1221},"();   ",{"type":15,"tag":360,"props":1223,"children":1224},{"style":486},[1225],{"type":21,"value":1226},"// the user record passed via batch.add\n",{"type":15,"tag":360,"props":1228,"children":1229},{"class":362,"line":449},[1230,1235,1240],{"type":15,"tag":360,"props":1231,"children":1232},{"style":373},[1233],{"type":21,"value":1234},"context.",{"type":15,"tag":360,"props":1236,"children":1237},{"style":389},[1238],{"type":21,"value":1239},"sendMail",{"type":15,"tag":360,"props":1241,"children":1242},{"style":373},[1243],{"type":21,"value":905},{"type":15,"tag":360,"props":1245,"children":1246},{"class":362,"line":482},[1247,1252,1257,1261,1266],{"type":15,"tag":360,"props":1248,"children":1249},{"style":373},[1250],{"type":21,"value":1251},"    to:      user.",{"type":15,"tag":360,"props":1253,"children":1254},{"style":389},[1255],{"type":21,"value":1256},"get",{"type":15,"tag":360,"props":1258,"children":1259},{"style":373},[1260],{"type":21,"value":397},{"type":15,"tag":360,"props":1262,"children":1263},{"style":400},[1264],{"type":21,"value":1265},"\"email\"",{"type":15,"tag":360,"props":1267,"children":1268},{"style":373},[1269],{"type":21,"value":1270},"),\n",{"type":15,"tag":360,"props":1272,"children":1273},{"class":362,"line":492},[1274,1279,1284],{"type":15,"tag":360,"props":1275,"children":1276},{"style":373},[1277],{"type":21,"value":1278},"    subject: ",{"type":15,"tag":360,"props":1280,"children":1281},{"style":400},[1282],{"type":21,"value":1283},"\"You're invited!\"",{"type":15,"tag":360,"props":1285,"children":1286},{"style":373},[1287],{"type":21,"value":923},{"type":15,"tag":360,"props":1289,"children":1290},{"class":362,"line":501},[1291,1296,1301,1305,1310],{"type":15,"tag":360,"props":1292,"children":1293},{"style":373},[1294],{"type":21,"value":1295},"    body:    context.",{"type":15,"tag":360,"props":1297,"children":1298},{"style":389},[1299],{"type":21,"value":1300},"renderTemplate",{"type":15,"tag":360,"props":1302,"children":1303},{"style":373},[1304],{"type":21,"value":397},{"type":15,"tag":360,"props":1306,"children":1307},{"style":400},[1308],{"type":21,"value":1309},"\"invitation\"",{"type":15,"tag":360,"props":1311,"children":1312},{"style":373},[1313],{"type":21,"value":1314},", user)\n",{"type":15,"tag":360,"props":1316,"children":1317},{"class":362,"line":519},[1318],{"type":15,"tag":360,"props":1319,"children":1320},{"style":373},[1321],{"type":21,"value":944},{"type":15,"tag":360,"props":1323,"children":1324},{"class":362,"line":537},[1325,1330,1335,1339,1344,1349,1354],{"type":15,"tag":360,"props":1326,"children":1327},{"style":373},[1328],{"type":21,"value":1329},"user.",{"type":15,"tag":360,"props":1331,"children":1332},{"style":389},[1333],{"type":21,"value":1334},"set",{"type":15,"tag":360,"props":1336,"children":1337},{"style":373},[1338],{"type":21,"value":397},{"type":15,"tag":360,"props":1340,"children":1341},{"style":400},[1342],{"type":21,"value":1343},"\"invited\"",{"type":15,"tag":360,"props":1345,"children":1346},{"style":373},[1347],{"type":21,"value":1348},", ",{"type":15,"tag":360,"props":1350,"children":1351},{"style":708},[1352],{"type":21,"value":1353},"true",{"type":15,"tag":360,"props":1355,"children":1356},{"style":373},[1357],{"type":21,"value":408},{"type":15,"tag":360,"props":1359,"children":1360},{"class":362,"line":773},[1361,1365,1370],{"type":15,"tag":360,"props":1362,"children":1363},{"style":373},[1364],{"type":21,"value":1234},{"type":15,"tag":360,"props":1366,"children":1367},{"style":389},[1368],{"type":21,"value":1369},"update",{"type":15,"tag":360,"props":1371,"children":1372},{"style":373},[1373],{"type":21,"value":1374},"(user);\n",{"type":15,"tag":24,"props":1376,"children":1377},{},[1378],{"type":21,"value":1379},"You don't write any plumbing. The child doesn't even know it's part of a batch — it's just an action being run.",{"type":15,"tag":24,"props":1381,"children":1382},{},[1383],{"type":21,"value":1384},"The completion action receives a summary in its input:",{"type":15,"tag":350,"props":1386,"children":1388},{"className":352,"code":1387,"language":354,"meta":7,"style":7},"// Action: \"invitationsCompleted\"\n\ncontext.log(\"Invitations sent: succeeded={}, failed={}, total={}\",\n    context.getInput(\"succeededJobs\"),\n    context.getInput(\"failedJobs\"),\n    context.getInput(\"totalJobs\"));\n",[1389],{"type":15,"tag":254,"props":1390,"children":1391},{"__ignoreMap":7},[1392,1400,1407,1432,1458,1482],{"type":15,"tag":360,"props":1393,"children":1394},{"class":362,"line":363},[1395],{"type":15,"tag":360,"props":1396,"children":1397},{"style":486},[1398],{"type":21,"value":1399},"// Action: \"invitationsCompleted\"\n",{"type":15,"tag":360,"props":1401,"children":1402},{"class":362,"line":411},[1403],{"type":15,"tag":360,"props":1404,"children":1405},{"emptyLinePlaceholder":839},[1406],{"type":21,"value":842},{"type":15,"tag":360,"props":1408,"children":1409},{"class":362,"line":425},[1410,1414,1419,1423,1428],{"type":15,"tag":360,"props":1411,"children":1412},{"style":373},[1413],{"type":21,"value":1234},{"type":15,"tag":360,"props":1415,"children":1416},{"style":389},[1417],{"type":21,"value":1418},"log",{"type":15,"tag":360,"props":1420,"children":1421},{"style":373},[1422],{"type":21,"value":397},{"type":15,"tag":360,"props":1424,"children":1425},{"style":400},[1426],{"type":21,"value":1427},"\"Invitations sent: succeeded={}, failed={}, total={}\"",{"type":15,"tag":360,"props":1429,"children":1430},{"style":373},[1431],{"type":21,"value":923},{"type":15,"tag":360,"props":1433,"children":1434},{"class":362,"line":449},[1435,1440,1445,1449,1454],{"type":15,"tag":360,"props":1436,"children":1437},{"style":373},[1438],{"type":21,"value":1439},"    context.",{"type":15,"tag":360,"props":1441,"children":1442},{"style":389},[1443],{"type":21,"value":1444},"getInput",{"type":15,"tag":360,"props":1446,"children":1447},{"style":373},[1448],{"type":21,"value":397},{"type":15,"tag":360,"props":1450,"children":1451},{"style":400},[1452],{"type":21,"value":1453},"\"succeededJobs\"",{"type":15,"tag":360,"props":1455,"children":1456},{"style":373},[1457],{"type":21,"value":1270},{"type":15,"tag":360,"props":1459,"children":1460},{"class":362,"line":482},[1461,1465,1469,1473,1478],{"type":15,"tag":360,"props":1462,"children":1463},{"style":373},[1464],{"type":21,"value":1439},{"type":15,"tag":360,"props":1466,"children":1467},{"style":389},[1468],{"type":21,"value":1444},{"type":15,"tag":360,"props":1470,"children":1471},{"style":373},[1472],{"type":21,"value":397},{"type":15,"tag":360,"props":1474,"children":1475},{"style":400},[1476],{"type":21,"value":1477},"\"failedJobs\"",{"type":15,"tag":360,"props":1479,"children":1480},{"style":373},[1481],{"type":21,"value":1270},{"type":15,"tag":360,"props":1483,"children":1484},{"class":362,"line":492},[1485,1489,1493,1497,1502],{"type":15,"tag":360,"props":1486,"children":1487},{"style":373},[1488],{"type":21,"value":1439},{"type":15,"tag":360,"props":1490,"children":1491},{"style":389},[1492],{"type":21,"value":1444},{"type":15,"tag":360,"props":1494,"children":1495},{"style":373},[1496],{"type":21,"value":397},{"type":15,"tag":360,"props":1498,"children":1499},{"style":400},[1500],{"type":21,"value":1501},"\"totalJobs\"",{"type":15,"tag":360,"props":1503,"children":1504},{"style":373},[1505],{"type":21,"value":1506},"));\n",{"type":15,"tag":24,"props":1508,"children":1509},{},[1510],{"type":21,"value":1511},"That's the complete picture. Now let's look at what's actually in that summary, what happens when something goes wrong, and the more advanced options.",{"type":15,"tag":805,"props":1513,"children":1514},{},[],{"type":15,"tag":126,"props":1516,"children":1518},{"id":1517},"what-the-finalizer-receives",[1519],{"type":21,"value":1520},"What the Finalizer Receives",{"type":15,"tag":24,"props":1522,"children":1523},{},[1524,1526,1532,1533,1539,1541,1547,1549,1554],{"type":21,"value":1525},"The action you configure as ",{"type":15,"tag":254,"props":1527,"children":1529},{"className":1528},[],[1530],{"type":21,"value":1531},"onSuccess",{"type":21,"value":1348},{"type":15,"tag":254,"props":1534,"children":1536},{"className":1535},[],[1537],{"type":21,"value":1538},"onError",{"type":21,"value":1540},", or ",{"type":15,"tag":254,"props":1542,"children":1544},{"className":1543},[],[1545],{"type":21,"value":1546},"onPartial",{"type":21,"value":1548}," is called the ",{"type":15,"tag":30,"props":1550,"children":1551},{},[1552],{"type":21,"value":1553},"finalizer",{"type":21,"value":1555},". It receives information from two distinct channels — knowing which channel a value comes from determines how you read it.",{"type":15,"tag":325,"props":1557,"children":1559},{"id":1558},"channel-1-platform-supplied-input-contextgetinput",[1560,1562],{"type":21,"value":1561},"Channel 1: Platform-Supplied Input — ",{"type":15,"tag":254,"props":1563,"children":1565},{"className":1564},[],[1566],{"type":21,"value":1567},"context.getInput()",{"type":15,"tag":24,"props":1569,"children":1570},{},[1571],{"type":21,"value":1572},"The platform always provides the following fields:",{"type":15,"tag":208,"props":1574,"children":1575},{},[1576,1592],{"type":15,"tag":212,"props":1577,"children":1578},{},[1579],{"type":15,"tag":216,"props":1580,"children":1581},{},[1582,1587],{"type":15,"tag":220,"props":1583,"children":1584},{},[1585],{"type":21,"value":1586},"Field",{"type":15,"tag":220,"props":1588,"children":1589},{},[1590],{"type":21,"value":1591},"Description",{"type":15,"tag":236,"props":1593,"children":1594},{},[1595,1612,1665,1682,1699,1716,1740,1776],{"type":15,"tag":216,"props":1596,"children":1597},{},[1598,1607],{"type":15,"tag":243,"props":1599,"children":1600},{},[1601],{"type":15,"tag":254,"props":1602,"children":1604},{"className":1603},[],[1605],{"type":21,"value":1606},"executionId",{"type":15,"tag":243,"props":1608,"children":1609},{},[1610],{"type":21,"value":1611},"A unique id for this batch. Useful for logging or correlation.",{"type":15,"tag":216,"props":1613,"children":1614},{},[1615,1624],{"type":15,"tag":243,"props":1616,"children":1617},{},[1618],{"type":15,"tag":254,"props":1619,"children":1621},{"className":1620},[],[1622],{"type":21,"value":1623},"state",{"type":15,"tag":243,"props":1625,"children":1626},{},[1627,1629,1635,1636,1642,1643,1649,1650,1656,1657,1663],{"type":21,"value":1628},"One of ",{"type":15,"tag":254,"props":1630,"children":1632},{"className":1631},[],[1633],{"type":21,"value":1634},"COMPLETED",{"type":21,"value":1348},{"type":15,"tag":254,"props":1637,"children":1639},{"className":1638},[],[1640],{"type":21,"value":1641},"FAILED",{"type":21,"value":1348},{"type":15,"tag":254,"props":1644,"children":1646},{"className":1645},[],[1647],{"type":21,"value":1648},"PARTIAL",{"type":21,"value":1348},{"type":15,"tag":254,"props":1651,"children":1653},{"className":1652},[],[1654],{"type":21,"value":1655},"TIMED_OUT",{"type":21,"value":1348},{"type":15,"tag":254,"props":1658,"children":1660},{"className":1659},[],[1661],{"type":21,"value":1662},"CANCELLED",{"type":21,"value":1664},".",{"type":15,"tag":216,"props":1666,"children":1667},{},[1668,1677],{"type":15,"tag":243,"props":1669,"children":1670},{},[1671],{"type":15,"tag":254,"props":1672,"children":1674},{"className":1673},[],[1675],{"type":21,"value":1676},"totalJobs",{"type":15,"tag":243,"props":1678,"children":1679},{},[1680],{"type":21,"value":1681},"How many children were added to the batch.",{"type":15,"tag":216,"props":1683,"children":1684},{},[1685,1694],{"type":15,"tag":243,"props":1686,"children":1687},{},[1688],{"type":15,"tag":254,"props":1689,"children":1691},{"className":1690},[],[1692],{"type":21,"value":1693},"succeededJobs",{"type":15,"tag":243,"props":1695,"children":1696},{},[1697],{"type":21,"value":1698},"How many returned successfully.",{"type":15,"tag":216,"props":1700,"children":1701},{},[1702,1711],{"type":15,"tag":243,"props":1703,"children":1704},{},[1705],{"type":15,"tag":254,"props":1706,"children":1708},{"className":1707},[],[1709],{"type":21,"value":1710},"failedJobs",{"type":15,"tag":243,"props":1712,"children":1713},{},[1714],{"type":21,"value":1715},"How many failed (after exhausting retries).",{"type":15,"tag":216,"props":1717,"children":1718},{},[1719,1728],{"type":15,"tag":243,"props":1720,"children":1721},{},[1722],{"type":15,"tag":254,"props":1723,"children":1725},{"className":1724},[],[1726],{"type":21,"value":1727},"durationMs",{"type":15,"tag":243,"props":1729,"children":1730},{},[1731,1733,1738],{"type":21,"value":1732},"Time from ",{"type":15,"tag":254,"props":1734,"children":1736},{"className":1735},[],[1737],{"type":21,"value":1155},{"type":21,"value":1739}," to completion.",{"type":15,"tag":216,"props":1741,"children":1742},{},[1743,1752],{"type":15,"tag":243,"props":1744,"children":1745},{},[1746],{"type":15,"tag":254,"props":1747,"children":1749},{"className":1748},[],[1750],{"type":21,"value":1751},"reason",{"type":15,"tag":243,"props":1753,"children":1754},{},[1755,1757,1762,1763,1768,1769,1774],{"type":21,"value":1756},"A short reason string — ",{"type":15,"tag":254,"props":1758,"children":1760},{"className":1759},[],[1761],{"type":21,"value":1634},{"type":21,"value":1348},{"type":15,"tag":254,"props":1764,"children":1766},{"className":1765},[],[1767],{"type":21,"value":1641},{"type":21,"value":1348},{"type":15,"tag":254,"props":1770,"children":1772},{"className":1771},[],[1773],{"type":21,"value":1655},{"type":21,"value":1775},", etc.",{"type":15,"tag":216,"props":1777,"children":1778},{},[1779,1788],{"type":15,"tag":243,"props":1780,"children":1781},{},[1782],{"type":15,"tag":254,"props":1783,"children":1785},{"className":1784},[],[1786],{"type":21,"value":1787},"resultsDatasetId",{"type":15,"tag":243,"props":1789,"children":1790},{},[1791],{"type":21,"value":1792},"Where per-child results are stored, if you asked for them.",{"type":15,"tag":24,"props":1794,"children":1795},{},[1796,1798,1804,1806,1811],{"type":21,"value":1797},"Read these with ",{"type":15,"tag":254,"props":1799,"children":1801},{"className":1800},[],[1802],{"type":21,"value":1803},"context.getInput(\"name\")",{"type":21,"value":1805},". They tell the finalizer ",{"type":15,"tag":30,"props":1807,"children":1808},{},[1809],{"type":21,"value":1810},"what happened",{"type":21,"value":1812}," — the outcome and the counters.",{"type":15,"tag":325,"props":1814,"children":1816},{"id":1815},"channel-2-caller-supplied-parameters-contextgetparameter",[1817,1819],{"type":21,"value":1818},"Channel 2: Caller-Supplied Parameters — ",{"type":15,"tag":254,"props":1820,"children":1822},{"className":1821},[],[1823],{"type":21,"value":1824},"context.getParameter()",{"type":15,"tag":24,"props":1826,"children":1827},{},[1828,1830,1835,1837,1843,1845,1851,1853,1858,1859,1864],{"type":21,"value":1829},"This is the channel ",{"type":15,"tag":30,"props":1831,"children":1832},{},[1833],{"type":21,"value":1834},"you",{"type":21,"value":1836}," control. Anything you put in the ",{"type":15,"tag":254,"props":1838,"children":1840},{"className":1839},[],[1841],{"type":21,"value":1842},"context: {...}",{"type":21,"value":1844}," option when creating the batch is forwarded to the finalizer as parameters and read with ",{"type":15,"tag":254,"props":1846,"children":1848},{"className":1847},[],[1849],{"type":21,"value":1850},"context.getParameter(\"name\")",{"type":21,"value":1852},". This is how you tell the finalizer ",{"type":15,"tag":30,"props":1854,"children":1855},{},[1856],{"type":21,"value":1857},"why it was running",{"type":21,"value":1348},{"type":15,"tag":30,"props":1860,"children":1861},{},[1862],{"type":21,"value":1863},"what it should do next",{"type":21,"value":1865},", and anything else not already in the platform-supplied input.",{"type":15,"tag":350,"props":1867,"children":1869},{"className":352,"code":1868,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess: \"invitationsCompleted\",\n    onError:   \"invitationsFailed\",\n    context: {\n        triggeredBy: context.user.username,\n        campaignId:  campaign.get(\"id\")\n    }\n});\n",[1870],{"type":15,"tag":254,"props":1871,"children":1872},{"__ignoreMap":7},[1873,1900,1915,1931,1939,1947,1973,1980],{"type":15,"tag":360,"props":1874,"children":1875},{"class":362,"line":363},[1876,1880,1884,1888,1892,1896],{"type":15,"tag":360,"props":1877,"children":1878},{"style":367},[1879],{"type":21,"value":370},{"type":15,"tag":360,"props":1881,"children":1882},{"style":373},[1883],{"type":21,"value":611},{"type":15,"tag":360,"props":1885,"children":1886},{"style":367},[1887],{"type":21,"value":381},{"type":15,"tag":360,"props":1889,"children":1890},{"style":373},[1891],{"type":21,"value":386},{"type":15,"tag":360,"props":1893,"children":1894},{"style":389},[1895],{"type":21,"value":259},{"type":15,"tag":360,"props":1897,"children":1898},{"style":373},[1899],{"type":21,"value":905},{"type":15,"tag":360,"props":1901,"children":1902},{"class":362,"line":411},[1903,1907,1911],{"type":15,"tag":360,"props":1904,"children":1905},{"style":373},[1906],{"type":21,"value":913},{"type":15,"tag":360,"props":1908,"children":1909},{"style":400},[1910],{"type":21,"value":918},{"type":15,"tag":360,"props":1912,"children":1913},{"style":373},[1914],{"type":21,"value":923},{"type":15,"tag":360,"props":1916,"children":1917},{"class":362,"line":425},[1918,1922,1927],{"type":15,"tag":360,"props":1919,"children":1920},{"style":373},[1921],{"type":21,"value":931},{"type":15,"tag":360,"props":1923,"children":1924},{"style":400},[1925],{"type":21,"value":1926},"\"invitationsFailed\"",{"type":15,"tag":360,"props":1928,"children":1929},{"style":373},[1930],{"type":21,"value":923},{"type":15,"tag":360,"props":1932,"children":1933},{"class":362,"line":449},[1934],{"type":15,"tag":360,"props":1935,"children":1936},{"style":373},[1937],{"type":21,"value":1938},"    context: {\n",{"type":15,"tag":360,"props":1940,"children":1941},{"class":362,"line":482},[1942],{"type":15,"tag":360,"props":1943,"children":1944},{"style":373},[1945],{"type":21,"value":1946},"        triggeredBy: context.user.username,\n",{"type":15,"tag":360,"props":1948,"children":1949},{"class":362,"line":492},[1950,1955,1959,1963,1968],{"type":15,"tag":360,"props":1951,"children":1952},{"style":373},[1953],{"type":21,"value":1954},"        campaignId:  campaign.",{"type":15,"tag":360,"props":1956,"children":1957},{"style":389},[1958],{"type":21,"value":1256},{"type":15,"tag":360,"props":1960,"children":1961},{"style":373},[1962],{"type":21,"value":397},{"type":15,"tag":360,"props":1964,"children":1965},{"style":400},[1966],{"type":21,"value":1967},"\"id\"",{"type":15,"tag":360,"props":1969,"children":1970},{"style":373},[1971],{"type":21,"value":1972},")\n",{"type":15,"tag":360,"props":1974,"children":1975},{"class":362,"line":501},[1976],{"type":15,"tag":360,"props":1977,"children":1978},{"style":373},[1979],{"type":21,"value":498},{"type":15,"tag":360,"props":1981,"children":1982},{"class":362,"line":519},[1983],{"type":15,"tag":360,"props":1984,"children":1985},{"style":373},[1986],{"type":21,"value":944},{"type":15,"tag":350,"props":1988,"children":1990},{"className":352,"code":1989,"language":354,"meta":7,"style":7},"// Action: \"invitationsCompleted\"\nlet succeeded   = context.getInput(\"succeededJobs\");      // platform — what happened\nlet triggeredBy = context.getParameter(\"triggeredBy\");    // caller — who triggered it\nlet campaignId  = context.getParameter(\"campaignId\");\n\ncontext.log(\"Campaign {} completed for {}: {} sent\",\n    campaignId, triggeredBy, succeeded);\n",[1991],{"type":15,"tag":254,"props":1992,"children":1993},{"__ignoreMap":7},[1994,2001,2043,2087,2124,2131,2155],{"type":15,"tag":360,"props":1995,"children":1996},{"class":362,"line":363},[1997],{"type":15,"tag":360,"props":1998,"children":1999},{"style":486},[2000],{"type":21,"value":1399},{"type":15,"tag":360,"props":2002,"children":2003},{"class":362,"line":411},[2004,2008,2013,2017,2021,2025,2029,2033,2038],{"type":15,"tag":360,"props":2005,"children":2006},{"style":367},[2007],{"type":21,"value":370},{"type":15,"tag":360,"props":2009,"children":2010},{"style":373},[2011],{"type":21,"value":2012}," succeeded   ",{"type":15,"tag":360,"props":2014,"children":2015},{"style":367},[2016],{"type":21,"value":381},{"type":15,"tag":360,"props":2018,"children":2019},{"style":373},[2020],{"type":21,"value":386},{"type":15,"tag":360,"props":2022,"children":2023},{"style":389},[2024],{"type":21,"value":1444},{"type":15,"tag":360,"props":2026,"children":2027},{"style":373},[2028],{"type":21,"value":397},{"type":15,"tag":360,"props":2030,"children":2031},{"style":400},[2032],{"type":21,"value":1453},{"type":15,"tag":360,"props":2034,"children":2035},{"style":373},[2036],{"type":21,"value":2037},");      ",{"type":15,"tag":360,"props":2039,"children":2040},{"style":486},[2041],{"type":21,"value":2042},"// platform — what happened\n",{"type":15,"tag":360,"props":2044,"children":2045},{"class":362,"line":425},[2046,2050,2055,2059,2063,2068,2072,2077,2082],{"type":15,"tag":360,"props":2047,"children":2048},{"style":367},[2049],{"type":21,"value":370},{"type":15,"tag":360,"props":2051,"children":2052},{"style":373},[2053],{"type":21,"value":2054}," triggeredBy ",{"type":15,"tag":360,"props":2056,"children":2057},{"style":367},[2058],{"type":21,"value":381},{"type":15,"tag":360,"props":2060,"children":2061},{"style":373},[2062],{"type":21,"value":386},{"type":15,"tag":360,"props":2064,"children":2065},{"style":389},[2066],{"type":21,"value":2067},"getParameter",{"type":15,"tag":360,"props":2069,"children":2070},{"style":373},[2071],{"type":21,"value":397},{"type":15,"tag":360,"props":2073,"children":2074},{"style":400},[2075],{"type":21,"value":2076},"\"triggeredBy\"",{"type":15,"tag":360,"props":2078,"children":2079},{"style":373},[2080],{"type":21,"value":2081},");    ",{"type":15,"tag":360,"props":2083,"children":2084},{"style":486},[2085],{"type":21,"value":2086},"// caller — who triggered it\n",{"type":15,"tag":360,"props":2088,"children":2089},{"class":362,"line":449},[2090,2094,2099,2103,2107,2111,2115,2120],{"type":15,"tag":360,"props":2091,"children":2092},{"style":367},[2093],{"type":21,"value":370},{"type":15,"tag":360,"props":2095,"children":2096},{"style":373},[2097],{"type":21,"value":2098}," campaignId  ",{"type":15,"tag":360,"props":2100,"children":2101},{"style":367},[2102],{"type":21,"value":381},{"type":15,"tag":360,"props":2104,"children":2105},{"style":373},[2106],{"type":21,"value":386},{"type":15,"tag":360,"props":2108,"children":2109},{"style":389},[2110],{"type":21,"value":2067},{"type":15,"tag":360,"props":2112,"children":2113},{"style":373},[2114],{"type":21,"value":397},{"type":15,"tag":360,"props":2116,"children":2117},{"style":400},[2118],{"type":21,"value":2119},"\"campaignId\"",{"type":15,"tag":360,"props":2121,"children":2122},{"style":373},[2123],{"type":21,"value":408},{"type":15,"tag":360,"props":2125,"children":2126},{"class":362,"line":482},[2127],{"type":15,"tag":360,"props":2128,"children":2129},{"emptyLinePlaceholder":839},[2130],{"type":21,"value":842},{"type":15,"tag":360,"props":2132,"children":2133},{"class":362,"line":492},[2134,2138,2142,2146,2151],{"type":15,"tag":360,"props":2135,"children":2136},{"style":373},[2137],{"type":21,"value":1234},{"type":15,"tag":360,"props":2139,"children":2140},{"style":389},[2141],{"type":21,"value":1418},{"type":15,"tag":360,"props":2143,"children":2144},{"style":373},[2145],{"type":21,"value":397},{"type":15,"tag":360,"props":2147,"children":2148},{"style":400},[2149],{"type":21,"value":2150},"\"Campaign {} completed for {}: {} sent\"",{"type":15,"tag":360,"props":2152,"children":2153},{"style":373},[2154],{"type":21,"value":923},{"type":15,"tag":360,"props":2156,"children":2157},{"class":362,"line":501},[2158],{"type":15,"tag":360,"props":2159,"children":2160},{"style":373},[2161],{"type":21,"value":2162},"    campaignId, triggeredBy, succeeded);\n",{"type":15,"tag":2164,"props":2165,"children":2166},"blockquote",{},[2167],{"type":15,"tag":24,"props":2168,"children":2169},{},[2170,2175,2177,2183],{"type":15,"tag":30,"props":2171,"children":2172},{},[2173],{"type":21,"value":2174},"Tip:",{"type":21,"value":2176}," Be generous with the ",{"type":15,"tag":254,"props":2178,"children":2180},{"className":2179},[],[2181],{"type":21,"value":2182},"context:",{"type":21,"value":2184}," map. It's small, it's free, and if the finalizer needs more state next month you don't have to plumb it through any other layer.",{"type":15,"tag":24,"props":2186,"children":2187},{},[2188],{"type":21,"value":2189},"Common things worth forwarding:",{"type":15,"tag":38,"props":2191,"children":2192},{},[2193,2205,2210,2236],{"type":15,"tag":42,"props":2194,"children":2195},{},[2196,2198,2204],{"type":21,"value":2197},"The user / role that triggered the batch (",{"type":15,"tag":254,"props":2199,"children":2201},{"className":2200},[],[2202],{"type":21,"value":2203},"triggeredBy",{"type":21,"value":261},{"type":15,"tag":42,"props":2206,"children":2207},{},[2208],{"type":21,"value":2209},"A parent record id or job id for traceability",{"type":15,"tag":42,"props":2211,"children":2212},{},[2213,2215,2221,2222,2228,2229,2235],{"type":21,"value":2214},"A label describing why this run started (",{"type":15,"tag":254,"props":2216,"children":2218},{"className":2217},[],[2219],{"type":21,"value":2220},"\"nightly-cron\"",{"type":21,"value":1348},{"type":15,"tag":254,"props":2223,"children":2225},{"className":2224},[],[2226],{"type":21,"value":2227},"\"manual-button-click\"",{"type":21,"value":1348},{"type":15,"tag":254,"props":2230,"children":2232},{"className":2231},[],[2233],{"type":21,"value":2234},"\"webhook-from-stripe\"",{"type":21,"value":261},{"type":15,"tag":42,"props":2237,"children":2238},{},[2239],{"type":21,"value":2240},"Any timestamps, cutoffs, or bounds you used when selecting the children",{"type":15,"tag":325,"props":2242,"children":2244},{"id":2243},"what-is-not-in-the-finalizers-input",[2245,2247,2253],{"type":21,"value":2246},"What Is ",{"type":15,"tag":2248,"props":2249,"children":2250},"em",{},[2251],{"type":21,"value":2252},"Not",{"type":21,"value":2254}," in the Finalizer's Input",{"type":15,"tag":24,"props":2256,"children":2257},{},[2258,2260,2266,2267,2273,2274,2280,2281,2287,2289,2294,2296,2301],{"type":21,"value":2259},"The other batch options — ",{"type":15,"tag":254,"props":2261,"children":2263},{"className":2262},[],[2264],{"type":21,"value":2265},"failureThreshold",{"type":21,"value":1348},{"type":15,"tag":254,"props":2268,"children":2270},{"className":2269},[],[2271],{"type":21,"value":2272},"maxConcurrent",{"type":21,"value":1348},{"type":15,"tag":254,"props":2275,"children":2277},{"className":2276},[],[2278],{"type":21,"value":2279},"deadlineMs",{"type":21,"value":1348},{"type":15,"tag":254,"props":2282,"children":2284},{"className":2283},[],[2285],{"type":21,"value":2286},"resultsMode",{"type":21,"value":2288},", etc. — ",{"type":15,"tag":30,"props":2290,"children":2291},{},[2292],{"type":21,"value":2293},"are not",{"type":21,"value":2295}," automatically forwarded. This is deliberate: it keeps the finalizer's contract small and explicit. If a finalizer needs one of these values, copy it into the ",{"type":15,"tag":254,"props":2297,"children":2299},{"className":2298},[],[2300],{"type":21,"value":2182},{"type":21,"value":2302}," map yourself.",{"type":15,"tag":805,"props":2304,"children":2305},{},[],{"type":15,"tag":126,"props":2307,"children":2309},{"id":2308},"what-succeeded-and-failed-mean",[2310],{"type":21,"value":2311},"What \"Succeeded\" and \"Failed\" Mean",{"type":15,"tag":24,"props":2313,"children":2314},{},[2315,2317,2322,2324,2330],{"type":21,"value":2316},"A child invocation ",{"type":15,"tag":30,"props":2318,"children":2319},{},[2320],{"type":21,"value":2321},"succeeds",{"type":21,"value":2323}," if the action script finishes normally — it didn't throw, didn't call ",{"type":15,"tag":254,"props":2325,"children":2327},{"className":2326},[],[2328],{"type":21,"value":2329},"context.error()",{"type":21,"value":2331},", didn't return an error result.",{"type":15,"tag":24,"props":2333,"children":2334},{},[2335,2337,2342],{"type":21,"value":2336},"A child ",{"type":15,"tag":30,"props":2338,"children":2339},{},[2340],{"type":21,"value":2341},"fails",{"type":21,"value":2343}," if either:",{"type":15,"tag":38,"props":2345,"children":2346},{},[2347,2352],{"type":15,"tag":42,"props":2348,"children":2349},{},[2350],{"type":21,"value":2351},"the action script throws an exception, or",{"type":15,"tag":42,"props":2353,"children":2354},{},[2355],{"type":21,"value":2356},"the action explicitly returns a failure result.",{"type":15,"tag":2164,"props":2358,"children":2359},{},[2360],{"type":15,"tag":24,"props":2361,"children":2362},{},[2363,2368],{"type":15,"tag":30,"props":2364,"children":2365},{},[2366],{"type":21,"value":2367},"Important:",{"type":21,"value":2369}," Transient failures are retried automatically. The platform retries failing children on a backoff schedule (around 5, 15, and 30 minutes). A child only counts as \"failed\" after all retries are exhausted. This means temporary problems — a flaky external API, a brief database hiccup — heal themselves without you doing anything.",{"type":15,"tag":24,"props":2371,"children":2372},{},[2373,2375,2380],{"type":21,"value":2374},"This also means you generally ",{"type":15,"tag":30,"props":2376,"children":2377},{},[2378],{"type":21,"value":2379},"shouldn't",{"type":21,"value":2381}," add your own retry logic inside a child action. Let the platform retry.",{"type":15,"tag":805,"props":2383,"children":2384},{},[],{"type":15,"tag":126,"props":2386,"children":2388},{"id":2387},"the-five-terminal-states",[2389],{"type":21,"value":2390},"The Five Terminal States",{"type":15,"tag":24,"props":2392,"children":2393},{},[2394,2396,2401],{"type":21,"value":2395},"A batch always ends in exactly one of five states. Most jobs only ever see ",{"type":15,"tag":254,"props":2397,"children":2399},{"className":2398},[],[2400],{"type":21,"value":1634},{"type":21,"value":2402},", but understanding the others is useful for designing robust finalizers.",{"type":15,"tag":208,"props":2404,"children":2405},{},[2406,2427],{"type":15,"tag":212,"props":2407,"children":2408},{},[2409],{"type":15,"tag":216,"props":2410,"children":2411},{},[2412,2417,2422],{"type":15,"tag":220,"props":2413,"children":2414},{},[2415],{"type":21,"value":2416},"State",{"type":15,"tag":220,"props":2418,"children":2419},{},[2420],{"type":21,"value":2421},"Meaning",{"type":15,"tag":220,"props":2423,"children":2424},{},[2425],{"type":21,"value":2426},"Finalizer Run",{"type":15,"tag":236,"props":2428,"children":2429},{},[2430,2453,2484,2507,2539],{"type":15,"tag":216,"props":2431,"children":2432},{},[2433,2440,2445],{"type":15,"tag":243,"props":2434,"children":2435},{},[2436],{"type":15,"tag":30,"props":2437,"children":2438},{},[2439],{"type":21,"value":1634},{"type":15,"tag":243,"props":2441,"children":2442},{},[2443],{"type":21,"value":2444},"Every child succeeded.",{"type":15,"tag":243,"props":2446,"children":2447},{},[2448],{"type":15,"tag":254,"props":2449,"children":2451},{"className":2450},[],[2452],{"type":21,"value":1531},{"type":15,"tag":216,"props":2454,"children":2455},{},[2456,2463,2468],{"type":15,"tag":243,"props":2457,"children":2458},{},[2459],{"type":15,"tag":30,"props":2460,"children":2461},{},[2462],{"type":21,"value":1648},{"type":15,"tag":243,"props":2464,"children":2465},{},[2466],{"type":21,"value":2467},"Some succeeded, some failed, but the failure rate stayed below your threshold.",{"type":15,"tag":243,"props":2469,"children":2470},{},[2471,2476,2478,2483],{"type":15,"tag":254,"props":2472,"children":2474},{"className":2473},[],[2475],{"type":21,"value":1546},{"type":21,"value":2477}," (falls back to ",{"type":15,"tag":254,"props":2479,"children":2481},{"className":2480},[],[2482],{"type":21,"value":1531},{"type":21,"value":261},{"type":15,"tag":216,"props":2485,"children":2486},{},[2487,2494,2499],{"type":15,"tag":243,"props":2488,"children":2489},{},[2490],{"type":15,"tag":30,"props":2491,"children":2492},{},[2493],{"type":21,"value":1641},{"type":15,"tag":243,"props":2495,"children":2496},{},[2497],{"type":21,"value":2498},"Every child failed, OR the failure threshold was exceeded.",{"type":15,"tag":243,"props":2500,"children":2501},{},[2502],{"type":15,"tag":254,"props":2503,"children":2505},{"className":2504},[],[2506],{"type":21,"value":1538},{"type":15,"tag":216,"props":2508,"children":2509},{},[2510,2517,2522],{"type":15,"tag":243,"props":2511,"children":2512},{},[2513],{"type":15,"tag":30,"props":2514,"children":2515},{},[2516],{"type":21,"value":1655},{"type":15,"tag":243,"props":2518,"children":2519},{},[2520],{"type":21,"value":2521},"The batch's deadline passed before everything finished.",{"type":15,"tag":243,"props":2523,"children":2524},{},[2525,2530,2532,2538],{"type":15,"tag":254,"props":2526,"children":2528},{"className":2527},[],[2529],{"type":21,"value":1538},{"type":21,"value":2531}," (with ",{"type":15,"tag":254,"props":2533,"children":2535},{"className":2534},[],[2536],{"type":21,"value":2537},"reason: \"TIMED_OUT\"",{"type":21,"value":261},{"type":15,"tag":216,"props":2540,"children":2541},{},[2542,2549,2554],{"type":15,"tag":243,"props":2543,"children":2544},{},[2545],{"type":15,"tag":30,"props":2546,"children":2547},{},[2548],{"type":21,"value":1662},{"type":15,"tag":243,"props":2550,"children":2551},{},[2552],{"type":21,"value":2553},"Somebody (an admin, or your code) explicitly cancelled the batch.",{"type":15,"tag":243,"props":2555,"children":2556},{},[2557,2562,2563,2569],{"type":15,"tag":254,"props":2558,"children":2560},{"className":2559},[],[2561],{"type":21,"value":1538},{"type":21,"value":2531},{"type":15,"tag":254,"props":2564,"children":2566},{"className":2565},[],[2567],{"type":21,"value":2568},"reason: \"CANCELLED\"",{"type":21,"value":261},{"type":15,"tag":24,"props":2571,"children":2572},{},[2573,2575,2580],{"type":21,"value":2574},"The finalizer always runs ",{"type":15,"tag":30,"props":2576,"children":2577},{},[2578],{"type":21,"value":2579},"exactly once",{"type":21,"value":2581},". Even if the worker that's supposed to run it crashes, the platform's safety nets republish the request until it succeeds.",{"type":15,"tag":805,"props":2583,"children":2584},{},[],{"type":15,"tag":126,"props":2586,"children":2588},{"id":2587},"failure-thresholds-circuit-breakers",[2589],{"type":21,"value":2590},"Failure Thresholds: Circuit Breakers",{"type":15,"tag":24,"props":2592,"children":2593},{},[2594,2596,2601,2603,2608],{"type":21,"value":2595},"By default a batch is only ",{"type":15,"tag":254,"props":2597,"children":2599},{"className":2598},[],[2600],{"type":21,"value":1641},{"type":21,"value":2602}," if ",{"type":15,"tag":30,"props":2604,"children":2605},{},[2606],{"type":21,"value":2607},"every single child",{"type":21,"value":2609}," failed. That's usually too lenient. If you're sending 100,000 emails and 99,000 succeeded, calling that \"completed\" is fine — but if 60,000 failed, something is seriously wrong and you don't want to keep going.",{"type":15,"tag":24,"props":2611,"children":2612},{},[2613,2615,2620],{"type":21,"value":2614},"Use ",{"type":15,"tag":254,"props":2616,"children":2618},{"className":2617},[],[2619],{"type":21,"value":2265},{"type":21,"value":2621}," to set a circuit-breaker:",{"type":15,"tag":350,"props":2623,"children":2625},{"className":352,"code":2624,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess:         \"done\",\n    onError:           \"somethingBroke\",\n    failureThreshold:  0.10,      // abort if more than 10% fail\n    failureMinSamples: 50         // ignore until at least 50 children have failed\n});\n",[2626],{"type":15,"tag":254,"props":2627,"children":2628},{"__ignoreMap":7},[2629,2656,2673,2690,2713,2731],{"type":15,"tag":360,"props":2630,"children":2631},{"class":362,"line":363},[2632,2636,2640,2644,2648,2652],{"type":15,"tag":360,"props":2633,"children":2634},{"style":367},[2635],{"type":21,"value":370},{"type":15,"tag":360,"props":2637,"children":2638},{"style":373},[2639],{"type":21,"value":611},{"type":15,"tag":360,"props":2641,"children":2642},{"style":367},[2643],{"type":21,"value":381},{"type":15,"tag":360,"props":2645,"children":2646},{"style":373},[2647],{"type":21,"value":386},{"type":15,"tag":360,"props":2649,"children":2650},{"style":389},[2651],{"type":21,"value":259},{"type":15,"tag":360,"props":2653,"children":2654},{"style":373},[2655],{"type":21,"value":905},{"type":15,"tag":360,"props":2657,"children":2658},{"class":362,"line":411},[2659,2664,2669],{"type":15,"tag":360,"props":2660,"children":2661},{"style":373},[2662],{"type":21,"value":2663},"    onSuccess:         ",{"type":15,"tag":360,"props":2665,"children":2666},{"style":400},[2667],{"type":21,"value":2668},"\"done\"",{"type":15,"tag":360,"props":2670,"children":2671},{"style":373},[2672],{"type":21,"value":923},{"type":15,"tag":360,"props":2674,"children":2675},{"class":362,"line":425},[2676,2681,2686],{"type":15,"tag":360,"props":2677,"children":2678},{"style":373},[2679],{"type":21,"value":2680},"    onError:           ",{"type":15,"tag":360,"props":2682,"children":2683},{"style":400},[2684],{"type":21,"value":2685},"\"somethingBroke\"",{"type":15,"tag":360,"props":2687,"children":2688},{"style":373},[2689],{"type":21,"value":923},{"type":15,"tag":360,"props":2691,"children":2692},{"class":362,"line":449},[2693,2698,2703,2708],{"type":15,"tag":360,"props":2694,"children":2695},{"style":373},[2696],{"type":21,"value":2697},"    failureThreshold:  ",{"type":15,"tag":360,"props":2699,"children":2700},{"style":708},[2701],{"type":21,"value":2702},"0.10",{"type":15,"tag":360,"props":2704,"children":2705},{"style":373},[2706],{"type":21,"value":2707},",      ",{"type":15,"tag":360,"props":2709,"children":2710},{"style":486},[2711],{"type":21,"value":2712},"// abort if more than 10% fail\n",{"type":15,"tag":360,"props":2714,"children":2715},{"class":362,"line":482},[2716,2721,2726],{"type":15,"tag":360,"props":2717,"children":2718},{"style":373},[2719],{"type":21,"value":2720},"    failureMinSamples: ",{"type":15,"tag":360,"props":2722,"children":2723},{"style":708},[2724],{"type":21,"value":2725},"50",{"type":15,"tag":360,"props":2727,"children":2728},{"style":486},[2729],{"type":21,"value":2730},"         // ignore until at least 50 children have failed\n",{"type":15,"tag":360,"props":2732,"children":2733},{"class":362,"line":492},[2734],{"type":15,"tag":360,"props":2735,"children":2736},{"style":373},[2737],{"type":21,"value":944},{"type":15,"tag":24,"props":2739,"children":2740},{},[2741,2743,2749,2751,2757],{"type":21,"value":2742},"The ",{"type":15,"tag":254,"props":2744,"children":2746},{"className":2745},[],[2747],{"type":21,"value":2748},"failureMinSamples",{"type":21,"value":2750}," floor exists so the very first failure doesn't trip a low threshold. Without it, a 1% threshold would trip on the first failure (",{"type":15,"tag":254,"props":2752,"children":2754},{"className":2753},[],[2755],{"type":21,"value":2756},"1/1 = 100%",{"type":21,"value":2758},").",{"type":15,"tag":24,"props":2760,"children":2761},{},[2762,2764,2769,2771,2776],{"type":21,"value":2763},"When the threshold trips, the batch flips to ",{"type":15,"tag":254,"props":2765,"children":2767},{"className":2766},[],[2768],{"type":21,"value":1641},{"type":21,"value":2770}," immediately and ",{"type":15,"tag":254,"props":2772,"children":2774},{"className":2773},[],[2775],{"type":21,"value":1538},{"type":21,"value":2777}," runs. Children already running in the background will finish, but no new ones are picked up.",{"type":15,"tag":805,"props":2779,"children":2780},{},[],{"type":15,"tag":126,"props":2782,"children":2784},{"id":2783},"deadlines-safety-nets",[2785],{"type":21,"value":2786},"Deadlines: Safety Nets",{"type":15,"tag":24,"props":2788,"children":2789},{},[2790,2792,2797,2799,2804],{"type":21,"value":2791},"Every batch has a deadline. By default it's 24 hours from when you create the batch. If the deadline passes and the batch is still running, the platform forcibly transitions it to ",{"type":15,"tag":254,"props":2793,"children":2795},{"className":2794},[],[2796],{"type":21,"value":1655},{"type":21,"value":2798}," and runs ",{"type":15,"tag":254,"props":2800,"children":2802},{"className":2801},[],[2803],{"type":21,"value":1538},{"type":21,"value":1664},{"type":15,"tag":24,"props":2806,"children":2807},{},[2808,2810,2815],{"type":21,"value":2809},"This is the safety net for the rare case where something goes really wrong — a worker silently crashes mid-job, a message gets lost, etc. ",{"type":15,"tag":30,"props":2811,"children":2812},{},[2813],{"type":21,"value":2814},"You don't have to do anything to make it work.",{"type":21,"value":2816}," It just runs in the background.",{"type":15,"tag":24,"props":2818,"children":2819},{},[2820],{"type":21,"value":2821},"You can shorten or extend the deadline:",{"type":15,"tag":350,"props":2823,"children":2825},{"className":352,"code":2824,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess: \"done\",\n    onError:   \"timedOut\",\n    deadlineMs: Date.now() + 30 * 60 * 1000   // 30 minutes from now\n});\n",[2826],{"type":15,"tag":254,"props":2827,"children":2828},{"__ignoreMap":7},[2829,2856,2871,2887,2939],{"type":15,"tag":360,"props":2830,"children":2831},{"class":362,"line":363},[2832,2836,2840,2844,2848,2852],{"type":15,"tag":360,"props":2833,"children":2834},{"style":367},[2835],{"type":21,"value":370},{"type":15,"tag":360,"props":2837,"children":2838},{"style":373},[2839],{"type":21,"value":611},{"type":15,"tag":360,"props":2841,"children":2842},{"style":367},[2843],{"type":21,"value":381},{"type":15,"tag":360,"props":2845,"children":2846},{"style":373},[2847],{"type":21,"value":386},{"type":15,"tag":360,"props":2849,"children":2850},{"style":389},[2851],{"type":21,"value":259},{"type":15,"tag":360,"props":2853,"children":2854},{"style":373},[2855],{"type":21,"value":905},{"type":15,"tag":360,"props":2857,"children":2858},{"class":362,"line":411},[2859,2863,2867],{"type":15,"tag":360,"props":2860,"children":2861},{"style":373},[2862],{"type":21,"value":913},{"type":15,"tag":360,"props":2864,"children":2865},{"style":400},[2866],{"type":21,"value":2668},{"type":15,"tag":360,"props":2868,"children":2869},{"style":373},[2870],{"type":21,"value":923},{"type":15,"tag":360,"props":2872,"children":2873},{"class":362,"line":425},[2874,2878,2883],{"type":15,"tag":360,"props":2875,"children":2876},{"style":373},[2877],{"type":21,"value":931},{"type":15,"tag":360,"props":2879,"children":2880},{"style":400},[2881],{"type":21,"value":2882},"\"timedOut\"",{"type":15,"tag":360,"props":2884,"children":2885},{"style":373},[2886],{"type":21,"value":923},{"type":15,"tag":360,"props":2888,"children":2889},{"class":362,"line":449},[2890,2895,2900,2905,2910,2915,2920,2925,2929,2934],{"type":15,"tag":360,"props":2891,"children":2892},{"style":373},[2893],{"type":21,"value":2894},"    deadlineMs: Date.",{"type":15,"tag":360,"props":2896,"children":2897},{"style":389},[2898],{"type":21,"value":2899},"now",{"type":15,"tag":360,"props":2901,"children":2902},{"style":373},[2903],{"type":21,"value":2904},"() ",{"type":15,"tag":360,"props":2906,"children":2907},{"style":367},[2908],{"type":21,"value":2909},"+",{"type":15,"tag":360,"props":2911,"children":2912},{"style":708},[2913],{"type":21,"value":2914}," 30",{"type":15,"tag":360,"props":2916,"children":2917},{"style":367},[2918],{"type":21,"value":2919}," *",{"type":15,"tag":360,"props":2921,"children":2922},{"style":708},[2923],{"type":21,"value":2924}," 60",{"type":15,"tag":360,"props":2926,"children":2927},{"style":367},[2928],{"type":21,"value":2919},{"type":15,"tag":360,"props":2930,"children":2931},{"style":708},[2932],{"type":21,"value":2933}," 1000",{"type":15,"tag":360,"props":2935,"children":2936},{"style":486},[2937],{"type":21,"value":2938},"   // 30 minutes from now\n",{"type":15,"tag":360,"props":2940,"children":2941},{"class":362,"line":482},[2942],{"type":15,"tag":360,"props":2943,"children":2944},{"style":373},[2945],{"type":21,"value":944},{"type":15,"tag":2164,"props":2947,"children":2948},{},[2949],{"type":15,"tag":24,"props":2950,"children":2951},{},[2952,2956,2958,2963],{"type":15,"tag":30,"props":2953,"children":2954},{},[2955],{"type":21,"value":2174},{"type":21,"value":2957}," Pick a deadline that's generous compared to how long the batch ",{"type":15,"tag":2248,"props":2959,"children":2960},{},[2961],{"type":21,"value":2962},"should",{"type":21,"value":2964}," take. If you expect 5,000 children at ~2s each with ~50 in flight at once, that's roughly 200 seconds in the perfect case — give it 30–60 minutes to be safe. The deadline is a backstop, not a target.",{"type":15,"tag":805,"props":2966,"children":2967},{},[],{"type":15,"tag":126,"props":2969,"children":2971},{"id":2970},"concurrency-control-maxconcurrent",[2972,2974],{"type":21,"value":2973},"Concurrency Control: ",{"type":15,"tag":254,"props":2975,"children":2977},{"className":2976},[],[2978],{"type":21,"value":2272},{"type":15,"tag":24,"props":2980,"children":2981},{},[2982,2984,2990],{"type":21,"value":2983},"If you ",{"type":15,"tag":254,"props":2985,"children":2987},{"className":2986},[],[2988],{"type":21,"value":2989},"add()",{"type":21,"value":2991}," 50,000 children, the platform will happily try to run all 50,000 in parallel on whatever workers are available. That's usually fine — but sometimes you need to be gentler:",{"type":15,"tag":38,"props":2993,"children":2994},{},[2995,3000,3005],{"type":15,"tag":42,"props":2996,"children":2997},{},[2998],{"type":21,"value":2999},"You're calling a third-party API that limits you to 10 requests per second.",{"type":15,"tag":42,"props":3001,"children":3002},{},[3003],{"type":21,"value":3004},"The job involves expensive operations and you don't want to crowd out other work.",{"type":15,"tag":42,"props":3006,"children":3007},{},[3008],{"type":21,"value":3009},"A downstream system can only handle so much load.",{"type":15,"tag":24,"props":3011,"children":3012},{},[3013,3014,3019],{"type":21,"value":2614},{"type":15,"tag":254,"props":3015,"children":3017},{"className":3016},[],[3018],{"type":21,"value":2272},{"type":21,"value":3020}," to cap the number of children that run simultaneously:",{"type":15,"tag":350,"props":3022,"children":3024},{"className":352,"code":3023,"language":354,"meta":7,"style":7},"let products = context.query(\"select p from product p\");\nlet batch = context.createBatch({\n    onSuccess:     \"done\",\n    onError:       \"failed\",\n    maxConcurrent: 10              // never more than 10 in flight at once\n});\ntry {\n    while (products.hasNext()) {\n        batch.add(\"syncProductWithStripe\", products.next(), null);\n    }\n} finally {\n    products.close();\n    batch.seal();\n}\n",[3025],{"type":15,"tag":254,"props":3026,"children":3027},{"__ignoreMap":7},[3028,3065,3092,3108,3125,3143,3150,3161,3181,3222,3229,3244,3260,3275],{"type":15,"tag":360,"props":3029,"children":3030},{"class":362,"line":363},[3031,3035,3040,3044,3048,3052,3056,3061],{"type":15,"tag":360,"props":3032,"children":3033},{"style":367},[3034],{"type":21,"value":370},{"type":15,"tag":360,"props":3036,"children":3037},{"style":373},[3038],{"type":21,"value":3039}," products ",{"type":15,"tag":360,"props":3041,"children":3042},{"style":367},[3043],{"type":21,"value":381},{"type":15,"tag":360,"props":3045,"children":3046},{"style":373},[3047],{"type":21,"value":386},{"type":15,"tag":360,"props":3049,"children":3050},{"style":389},[3051],{"type":21,"value":392},{"type":15,"tag":360,"props":3053,"children":3054},{"style":373},[3055],{"type":21,"value":397},{"type":15,"tag":360,"props":3057,"children":3058},{"style":400},[3059],{"type":21,"value":3060},"\"select p from product p\"",{"type":15,"tag":360,"props":3062,"children":3063},{"style":373},[3064],{"type":21,"value":408},{"type":15,"tag":360,"props":3066,"children":3067},{"class":362,"line":411},[3068,3072,3076,3080,3084,3088],{"type":15,"tag":360,"props":3069,"children":3070},{"style":367},[3071],{"type":21,"value":370},{"type":15,"tag":360,"props":3073,"children":3074},{"style":373},[3075],{"type":21,"value":611},{"type":15,"tag":360,"props":3077,"children":3078},{"style":367},[3079],{"type":21,"value":381},{"type":15,"tag":360,"props":3081,"children":3082},{"style":373},[3083],{"type":21,"value":386},{"type":15,"tag":360,"props":3085,"children":3086},{"style":389},[3087],{"type":21,"value":259},{"type":15,"tag":360,"props":3089,"children":3090},{"style":373},[3091],{"type":21,"value":905},{"type":15,"tag":360,"props":3093,"children":3094},{"class":362,"line":425},[3095,3100,3104],{"type":15,"tag":360,"props":3096,"children":3097},{"style":373},[3098],{"type":21,"value":3099},"    onSuccess:     ",{"type":15,"tag":360,"props":3101,"children":3102},{"style":400},[3103],{"type":21,"value":2668},{"type":15,"tag":360,"props":3105,"children":3106},{"style":373},[3107],{"type":21,"value":923},{"type":15,"tag":360,"props":3109,"children":3110},{"class":362,"line":449},[3111,3116,3121],{"type":15,"tag":360,"props":3112,"children":3113},{"style":373},[3114],{"type":21,"value":3115},"    onError:       ",{"type":15,"tag":360,"props":3117,"children":3118},{"style":400},[3119],{"type":21,"value":3120},"\"failed\"",{"type":15,"tag":360,"props":3122,"children":3123},{"style":373},[3124],{"type":21,"value":923},{"type":15,"tag":360,"props":3126,"children":3127},{"class":362,"line":482},[3128,3133,3138],{"type":15,"tag":360,"props":3129,"children":3130},{"style":373},[3131],{"type":21,"value":3132},"    maxConcurrent: ",{"type":15,"tag":360,"props":3134,"children":3135},{"style":708},[3136],{"type":21,"value":3137},"10",{"type":15,"tag":360,"props":3139,"children":3140},{"style":486},[3141],{"type":21,"value":3142},"              // never more than 10 in flight at once\n",{"type":15,"tag":360,"props":3144,"children":3145},{"class":362,"line":492},[3146],{"type":15,"tag":360,"props":3147,"children":3148},{"style":373},[3149],{"type":21,"value":944},{"type":15,"tag":360,"props":3151,"children":3152},{"class":362,"line":501},[3153,3157],{"type":15,"tag":360,"props":3154,"children":3155},{"style":367},[3156],{"type":21,"value":417},{"type":15,"tag":360,"props":3158,"children":3159},{"style":373},[3160],{"type":21,"value":422},{"type":15,"tag":360,"props":3162,"children":3163},{"class":362,"line":519},[3164,3168,3173,3177],{"type":15,"tag":360,"props":3165,"children":3166},{"style":367},[3167],{"type":21,"value":431},{"type":15,"tag":360,"props":3169,"children":3170},{"style":373},[3171],{"type":21,"value":3172}," (products.",{"type":15,"tag":360,"props":3174,"children":3175},{"style":389},[3176],{"type":21,"value":441},{"type":15,"tag":360,"props":3178,"children":3179},{"style":373},[3180],{"type":21,"value":446},{"type":15,"tag":360,"props":3182,"children":3183},{"class":362,"line":537},[3184,3188,3192,3196,3201,3206,3210,3214,3218],{"type":15,"tag":360,"props":3185,"children":3186},{"style":373},[3187],{"type":21,"value":677},{"type":15,"tag":360,"props":3189,"children":3190},{"style":389},[3191],{"type":21,"value":682},{"type":15,"tag":360,"props":3193,"children":3194},{"style":373},[3195],{"type":21,"value":397},{"type":15,"tag":360,"props":3197,"children":3198},{"style":400},[3199],{"type":21,"value":3200},"\"syncProductWithStripe\"",{"type":15,"tag":360,"props":3202,"children":3203},{"style":373},[3204],{"type":21,"value":3205},", products.",{"type":15,"tag":360,"props":3207,"children":3208},{"style":389},[3209],{"type":21,"value":474},{"type":15,"tag":360,"props":3211,"children":3212},{"style":373},[3213],{"type":21,"value":705},{"type":15,"tag":360,"props":3215,"children":3216},{"style":708},[3217],{"type":21,"value":711},{"type":15,"tag":360,"props":3219,"children":3220},{"style":373},[3221],{"type":21,"value":408},{"type":15,"tag":360,"props":3223,"children":3224},{"class":362,"line":773},[3225],{"type":15,"tag":360,"props":3226,"children":3227},{"style":373},[3228],{"type":21,"value":498},{"type":15,"tag":360,"props":3230,"children":3231},{"class":362,"line":1016},[3232,3236,3240],{"type":15,"tag":360,"props":3233,"children":3234},{"style":373},[3235],{"type":21,"value":507},{"type":15,"tag":360,"props":3237,"children":3238},{"style":367},[3239],{"type":21,"value":512},{"type":15,"tag":360,"props":3241,"children":3242},{"style":373},[3243],{"type":21,"value":422},{"type":15,"tag":360,"props":3245,"children":3246},{"class":362,"line":1024},[3247,3252,3256],{"type":15,"tag":360,"props":3248,"children":3249},{"style":373},[3250],{"type":21,"value":3251},"    products.",{"type":15,"tag":360,"props":3253,"children":3254},{"style":389},[3255],{"type":21,"value":530},{"type":15,"tag":360,"props":3257,"children":3258},{"style":373},[3259],{"type":21,"value":479},{"type":15,"tag":360,"props":3261,"children":3262},{"class":362,"line":1040},[3263,3267,3271],{"type":15,"tag":360,"props":3264,"children":3265},{"style":373},[3266],{"type":21,"value":761},{"type":15,"tag":360,"props":3268,"children":3269},{"style":389},[3270],{"type":21,"value":766},{"type":15,"tag":360,"props":3272,"children":3273},{"style":373},[3274],{"type":21,"value":479},{"type":15,"tag":360,"props":3276,"children":3277},{"class":362,"line":1056},[3278],{"type":15,"tag":360,"props":3279,"children":3280},{"style":373},[3281],{"type":21,"value":543},{"type":15,"tag":24,"props":3283,"children":3284},{},[3285,3287,3293,3295,3300,3302,3307],{"type":21,"value":3286},"What happens here is subtle but important: each ",{"type":15,"tag":254,"props":3288,"children":3290},{"className":3289},[],[3291],{"type":21,"value":3292},"batch.add()",{"type":21,"value":3294}," call ",{"type":15,"tag":30,"props":3296,"children":3297},{},[3298],{"type":21,"value":3299},"blocks",{"type":21,"value":3301}," until a slot is free. If you've already got 10 in flight, the 11th call to ",{"type":15,"tag":254,"props":3303,"children":3305},{"className":3304},[],[3306],{"type":21,"value":2989},{"type":21,"value":3308}," waits until one of the running children finishes. That's how the cap is enforced.",{"type":15,"tag":24,"props":3310,"children":3311},{},[3312,3314],{"type":21,"value":3313},"This means a producer that's much faster than the workers will naturally slow down to match. ",{"type":15,"tag":30,"props":3315,"children":3316},{},[3317],{"type":21,"value":3318},"You don't need any flow-control logic of your own.",{"type":15,"tag":805,"props":3320,"children":3321},{},[],{"type":15,"tag":126,"props":3323,"children":3325},{"id":3324},"per-child-results-the-four-modes",[3326],{"type":21,"value":3327},"Per-Child Results: The Four Modes",{"type":15,"tag":24,"props":3329,"children":3330},{},[3331,3333,3338],{"type":21,"value":3332},"A batch's counters are great, but sometimes you want to know ",{"type":15,"tag":30,"props":3334,"children":3335},{},[3336],{"type":21,"value":3337},"what",{"type":21,"value":3339}," each child returned. For example: \"show me which 47 invitations failed and why.\" There are four storage modes for child results, ranging from \"free\" to \"expensive.\"",{"type":15,"tag":24,"props":3341,"children":3342},{},[3343],{"type":21,"value":3344},"Pick deliberately — the cheapest and most expensive differ by orders of magnitude in storage cost.",{"type":15,"tag":325,"props":3346,"children":3348},{"id":3347},"count-default",[3349,3355],{"type":15,"tag":254,"props":3350,"children":3352},{"className":3351},[],[3353],{"type":21,"value":3354},"COUNT",{"type":21,"value":3356}," (default)",{"type":15,"tag":24,"props":3358,"children":3359},{},[3360],{"type":21,"value":3361},"Just the counters. The finalizer sees how many succeeded and how many failed, but no details. Use this for the typical case where you don't need to drill in.",{"type":15,"tag":350,"props":3363,"children":3365},{"className":352,"code":3364,"language":354,"meta":7,"style":7},"context.createBatch({ onSuccess: \"done\" });\n// results mode is COUNT by default\n",[3366],{"type":15,"tag":254,"props":3367,"children":3368},{"__ignoreMap":7},[3369,3393],{"type":15,"tag":360,"props":3370,"children":3371},{"class":362,"line":363},[3372,3376,3380,3385,3389],{"type":15,"tag":360,"props":3373,"children":3374},{"style":373},[3375],{"type":21,"value":1234},{"type":15,"tag":360,"props":3377,"children":3378},{"style":389},[3379],{"type":21,"value":259},{"type":15,"tag":360,"props":3381,"children":3382},{"style":373},[3383],{"type":21,"value":3384},"({ onSuccess: ",{"type":15,"tag":360,"props":3386,"children":3387},{"style":400},[3388],{"type":21,"value":2668},{"type":15,"tag":360,"props":3390,"children":3391},{"style":373},[3392],{"type":21,"value":638},{"type":15,"tag":360,"props":3394,"children":3395},{"class":362,"line":411},[3396],{"type":15,"tag":360,"props":3397,"children":3398},{"style":486},[3399],{"type":21,"value":3400},"// results mode is COUNT by default\n",{"type":15,"tag":325,"props":3402,"children":3404},{"id":3403},"failures_only-best-for-debugging",[3405,3411],{"type":15,"tag":254,"props":3406,"children":3408},{"className":3407},[],[3409],{"type":21,"value":3410},"FAILURES_ONLY",{"type":21,"value":3412}," — Best for Debugging",{"type":15,"tag":24,"props":3414,"children":3415},{},[3416,3418,3423],{"type":21,"value":3417},"The platform stores a record for each ",{"type":15,"tag":2248,"props":3419,"children":3420},{},[3421],{"type":21,"value":3422},"failed",{"type":21,"value":3424}," child — successes are not stored. Storage is bounded by your failure rate, which is usually small.",{"type":15,"tag":350,"props":3426,"children":3428},{"className":352,"code":3427,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess:       \"invitationsCompleted\",\n    onError:         \"somethingBroke\",\n    results:         \"FAILURES_ONLY\",\n    resultsTtlHours: 48        // keep failure records for 48h, default 24h\n});\n",[3429],{"type":15,"tag":254,"props":3430,"children":3431},{"__ignoreMap":7},[3432,3459,3475,3491,3508,3526],{"type":15,"tag":360,"props":3433,"children":3434},{"class":362,"line":363},[3435,3439,3443,3447,3451,3455],{"type":15,"tag":360,"props":3436,"children":3437},{"style":367},[3438],{"type":21,"value":370},{"type":15,"tag":360,"props":3440,"children":3441},{"style":373},[3442],{"type":21,"value":611},{"type":15,"tag":360,"props":3444,"children":3445},{"style":367},[3446],{"type":21,"value":381},{"type":15,"tag":360,"props":3448,"children":3449},{"style":373},[3450],{"type":21,"value":386},{"type":15,"tag":360,"props":3452,"children":3453},{"style":389},[3454],{"type":21,"value":259},{"type":15,"tag":360,"props":3456,"children":3457},{"style":373},[3458],{"type":21,"value":905},{"type":15,"tag":360,"props":3460,"children":3461},{"class":362,"line":411},[3462,3467,3471],{"type":15,"tag":360,"props":3463,"children":3464},{"style":373},[3465],{"type":21,"value":3466},"    onSuccess:       ",{"type":15,"tag":360,"props":3468,"children":3469},{"style":400},[3470],{"type":21,"value":918},{"type":15,"tag":360,"props":3472,"children":3473},{"style":373},[3474],{"type":21,"value":923},{"type":15,"tag":360,"props":3476,"children":3477},{"class":362,"line":425},[3478,3483,3487],{"type":15,"tag":360,"props":3479,"children":3480},{"style":373},[3481],{"type":21,"value":3482},"    onError:         ",{"type":15,"tag":360,"props":3484,"children":3485},{"style":400},[3486],{"type":21,"value":2685},{"type":15,"tag":360,"props":3488,"children":3489},{"style":373},[3490],{"type":21,"value":923},{"type":15,"tag":360,"props":3492,"children":3493},{"class":362,"line":449},[3494,3499,3504],{"type":15,"tag":360,"props":3495,"children":3496},{"style":373},[3497],{"type":21,"value":3498},"    results:         ",{"type":15,"tag":360,"props":3500,"children":3501},{"style":400},[3502],{"type":21,"value":3503},"\"FAILURES_ONLY\"",{"type":15,"tag":360,"props":3505,"children":3506},{"style":373},[3507],{"type":21,"value":923},{"type":15,"tag":360,"props":3509,"children":3510},{"class":362,"line":482},[3511,3516,3521],{"type":15,"tag":360,"props":3512,"children":3513},{"style":373},[3514],{"type":21,"value":3515},"    resultsTtlHours: ",{"type":15,"tag":360,"props":3517,"children":3518},{"style":708},[3519],{"type":21,"value":3520},"48",{"type":15,"tag":360,"props":3522,"children":3523},{"style":486},[3524],{"type":21,"value":3525},"        // keep failure records for 48h, default 24h\n",{"type":15,"tag":360,"props":3527,"children":3528},{"class":362,"line":492},[3529],{"type":15,"tag":360,"props":3530,"children":3531},{"style":373},[3532],{"type":21,"value":944},{"type":15,"tag":24,"props":3534,"children":3535},{},[3536,3538,3543],{"type":21,"value":3537},"In the finalizer, the failed records are available through the ",{"type":15,"tag":30,"props":3539,"children":3540},{},[3541],{"type":21,"value":3542},"scratchpad",{"type":21,"value":36},{"type":15,"tag":350,"props":3545,"children":3547},{"className":352,"code":3546,"language":354,"meta":7,"style":7},"// Action: \"invitationsCompleted\"\n\nif (context.getInput(\"failedJobs\") > 0) {\n    let datasetId = context.getInput(\"resultsDatasetId\");\n    let failures = context.scratchpad.getAllRecords(datasetId);\n    failures.forEach(function(record) {\n        let data = record.getData();\n        context.log(\"Invitation failed: outcome={}, attempt={}\",\n            data.get(\"outcome\"), data.get(\"attempt\"));\n    });\n}\n",[3548],{"type":15,"tag":254,"props":3549,"children":3550},{"__ignoreMap":7},[3551,3558,3565,3610,3648,3679,3715,3745,3770,3813,3821],{"type":15,"tag":360,"props":3552,"children":3553},{"class":362,"line":363},[3554],{"type":15,"tag":360,"props":3555,"children":3556},{"style":486},[3557],{"type":21,"value":1399},{"type":15,"tag":360,"props":3559,"children":3560},{"class":362,"line":411},[3561],{"type":15,"tag":360,"props":3562,"children":3563},{"emptyLinePlaceholder":839},[3564],{"type":21,"value":842},{"type":15,"tag":360,"props":3566,"children":3567},{"class":362,"line":425},[3568,3573,3578,3582,3586,3590,3595,3600,3605],{"type":15,"tag":360,"props":3569,"children":3570},{"style":367},[3571],{"type":21,"value":3572},"if",{"type":15,"tag":360,"props":3574,"children":3575},{"style":373},[3576],{"type":21,"value":3577}," (context.",{"type":15,"tag":360,"props":3579,"children":3580},{"style":389},[3581],{"type":21,"value":1444},{"type":15,"tag":360,"props":3583,"children":3584},{"style":373},[3585],{"type":21,"value":397},{"type":15,"tag":360,"props":3587,"children":3588},{"style":400},[3589],{"type":21,"value":1477},{"type":15,"tag":360,"props":3591,"children":3592},{"style":373},[3593],{"type":21,"value":3594},") ",{"type":15,"tag":360,"props":3596,"children":3597},{"style":367},[3598],{"type":21,"value":3599},">",{"type":15,"tag":360,"props":3601,"children":3602},{"style":708},[3603],{"type":21,"value":3604}," 0",{"type":15,"tag":360,"props":3606,"children":3607},{"style":373},[3608],{"type":21,"value":3609},") {\n",{"type":15,"tag":360,"props":3611,"children":3612},{"class":362,"line":449},[3613,3618,3623,3627,3631,3635,3639,3644],{"type":15,"tag":360,"props":3614,"children":3615},{"style":367},[3616],{"type":21,"value":3617},"    let",{"type":15,"tag":360,"props":3619,"children":3620},{"style":373},[3621],{"type":21,"value":3622}," datasetId ",{"type":15,"tag":360,"props":3624,"children":3625},{"style":367},[3626],{"type":21,"value":381},{"type":15,"tag":360,"props":3628,"children":3629},{"style":373},[3630],{"type":21,"value":386},{"type":15,"tag":360,"props":3632,"children":3633},{"style":389},[3634],{"type":21,"value":1444},{"type":15,"tag":360,"props":3636,"children":3637},{"style":373},[3638],{"type":21,"value":397},{"type":15,"tag":360,"props":3640,"children":3641},{"style":400},[3642],{"type":21,"value":3643},"\"resultsDatasetId\"",{"type":15,"tag":360,"props":3645,"children":3646},{"style":373},[3647],{"type":21,"value":408},{"type":15,"tag":360,"props":3649,"children":3650},{"class":362,"line":482},[3651,3655,3660,3664,3669,3674],{"type":15,"tag":360,"props":3652,"children":3653},{"style":367},[3654],{"type":21,"value":3617},{"type":15,"tag":360,"props":3656,"children":3657},{"style":373},[3658],{"type":21,"value":3659}," failures ",{"type":15,"tag":360,"props":3661,"children":3662},{"style":367},[3663],{"type":21,"value":381},{"type":15,"tag":360,"props":3665,"children":3666},{"style":373},[3667],{"type":21,"value":3668}," context.scratchpad.",{"type":15,"tag":360,"props":3670,"children":3671},{"style":389},[3672],{"type":21,"value":3673},"getAllRecords",{"type":15,"tag":360,"props":3675,"children":3676},{"style":373},[3677],{"type":21,"value":3678},"(datasetId);\n",{"type":15,"tag":360,"props":3680,"children":3681},{"class":362,"line":492},[3682,3687,3692,3696,3701,3705,3711],{"type":15,"tag":360,"props":3683,"children":3684},{"style":373},[3685],{"type":21,"value":3686},"    failures.",{"type":15,"tag":360,"props":3688,"children":3689},{"style":389},[3690],{"type":21,"value":3691},"forEach",{"type":15,"tag":360,"props":3693,"children":3694},{"style":373},[3695],{"type":21,"value":397},{"type":15,"tag":360,"props":3697,"children":3698},{"style":367},[3699],{"type":21,"value":3700},"function",{"type":15,"tag":360,"props":3702,"children":3703},{"style":373},[3704],{"type":21,"value":397},{"type":15,"tag":360,"props":3706,"children":3708},{"style":3707},"--shiki-default:#E36209;--shiki-dark:#FFAB70",[3709],{"type":21,"value":3710},"record",{"type":15,"tag":360,"props":3712,"children":3713},{"style":373},[3714],{"type":21,"value":3609},{"type":15,"tag":360,"props":3716,"children":3717},{"class":362,"line":501},[3718,3722,3727,3731,3736,3741],{"type":15,"tag":360,"props":3719,"children":3720},{"style":367},[3721],{"type":21,"value":455},{"type":15,"tag":360,"props":3723,"children":3724},{"style":373},[3725],{"type":21,"value":3726}," data ",{"type":15,"tag":360,"props":3728,"children":3729},{"style":367},[3730],{"type":21,"value":381},{"type":15,"tag":360,"props":3732,"children":3733},{"style":373},[3734],{"type":21,"value":3735}," record.",{"type":15,"tag":360,"props":3737,"children":3738},{"style":389},[3739],{"type":21,"value":3740},"getData",{"type":15,"tag":360,"props":3742,"children":3743},{"style":373},[3744],{"type":21,"value":479},{"type":15,"tag":360,"props":3746,"children":3747},{"class":362,"line":519},[3748,3753,3757,3761,3766],{"type":15,"tag":360,"props":3749,"children":3750},{"style":373},[3751],{"type":21,"value":3752},"        context.",{"type":15,"tag":360,"props":3754,"children":3755},{"style":389},[3756],{"type":21,"value":1418},{"type":15,"tag":360,"props":3758,"children":3759},{"style":373},[3760],{"type":21,"value":397},{"type":15,"tag":360,"props":3762,"children":3763},{"style":400},[3764],{"type":21,"value":3765},"\"Invitation failed: outcome={}, attempt={}\"",{"type":15,"tag":360,"props":3767,"children":3768},{"style":373},[3769],{"type":21,"value":923},{"type":15,"tag":360,"props":3771,"children":3772},{"class":362,"line":537},[3773,3778,3782,3786,3791,3796,3800,3804,3809],{"type":15,"tag":360,"props":3774,"children":3775},{"style":373},[3776],{"type":21,"value":3777},"            data.",{"type":15,"tag":360,"props":3779,"children":3780},{"style":389},[3781],{"type":21,"value":1256},{"type":15,"tag":360,"props":3783,"children":3784},{"style":373},[3785],{"type":21,"value":397},{"type":15,"tag":360,"props":3787,"children":3788},{"style":400},[3789],{"type":21,"value":3790},"\"outcome\"",{"type":15,"tag":360,"props":3792,"children":3793},{"style":373},[3794],{"type":21,"value":3795},"), data.",{"type":15,"tag":360,"props":3797,"children":3798},{"style":389},[3799],{"type":21,"value":1256},{"type":15,"tag":360,"props":3801,"children":3802},{"style":373},[3803],{"type":21,"value":397},{"type":15,"tag":360,"props":3805,"children":3806},{"style":400},[3807],{"type":21,"value":3808},"\"attempt\"",{"type":15,"tag":360,"props":3810,"children":3811},{"style":373},[3812],{"type":21,"value":1506},{"type":15,"tag":360,"props":3814,"children":3815},{"class":362,"line":773},[3816],{"type":15,"tag":360,"props":3817,"children":3818},{"style":373},[3819],{"type":21,"value":3820},"    });\n",{"type":15,"tag":360,"props":3822,"children":3823},{"class":362,"line":1016},[3824],{"type":15,"tag":360,"props":3825,"children":3826},{"style":373},[3827],{"type":21,"value":543},{"type":15,"tag":24,"props":3829,"children":3830},{},[3831,3833,3839],{"type":21,"value":3832},"The TTL is automatic — after ",{"type":15,"tag":254,"props":3834,"children":3836},{"className":3835},[],[3837],{"type":21,"value":3838},"resultsTtlHours",{"type":21,"value":3840}," hours the records vanish, so failure records don't pile up. Default is 24h; you can set anything from 1 to 168 hours.",{"type":15,"tag":325,"props":3842,"children":3844},{"id":3843},"persist-store-every-result",[3845,3851],{"type":15,"tag":254,"props":3846,"children":3848},{"className":3847},[],[3849],{"type":21,"value":3850},"PERSIST",{"type":21,"value":3852}," — Store Every Result",{"type":15,"tag":24,"props":3854,"children":3855},{},[3856,3858,3863],{"type":21,"value":3857},"Same as ",{"type":15,"tag":254,"props":3859,"children":3861},{"className":3860},[],[3862],{"type":21,"value":3410},{"type":21,"value":3864}," but stores every child, succeeded or failed. Use this when you want to do something with the actual return values, not just count them.",{"type":15,"tag":350,"props":3866,"children":3868},{"className":352,"code":3867,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess:       \"done\",\n    results:         \"PERSIST\",\n    resultsTtlHours: 24\n});\n\n// Each child's action returns something useful:\n// In \"computeStats\": context.return({ rowsProcessed: ..., bytesScanned: ... });\n",[3869],{"type":15,"tag":254,"props":3870,"children":3871},{"__ignoreMap":7},[3872,3899,3914,3930,3942,3949,3956,3964],{"type":15,"tag":360,"props":3873,"children":3874},{"class":362,"line":363},[3875,3879,3883,3887,3891,3895],{"type":15,"tag":360,"props":3876,"children":3877},{"style":367},[3878],{"type":21,"value":370},{"type":15,"tag":360,"props":3880,"children":3881},{"style":373},[3882],{"type":21,"value":611},{"type":15,"tag":360,"props":3884,"children":3885},{"style":367},[3886],{"type":21,"value":381},{"type":15,"tag":360,"props":3888,"children":3889},{"style":373},[3890],{"type":21,"value":386},{"type":15,"tag":360,"props":3892,"children":3893},{"style":389},[3894],{"type":21,"value":259},{"type":15,"tag":360,"props":3896,"children":3897},{"style":373},[3898],{"type":21,"value":905},{"type":15,"tag":360,"props":3900,"children":3901},{"class":362,"line":411},[3902,3906,3910],{"type":15,"tag":360,"props":3903,"children":3904},{"style":373},[3905],{"type":21,"value":3466},{"type":15,"tag":360,"props":3907,"children":3908},{"style":400},[3909],{"type":21,"value":2668},{"type":15,"tag":360,"props":3911,"children":3912},{"style":373},[3913],{"type":21,"value":923},{"type":15,"tag":360,"props":3915,"children":3916},{"class":362,"line":425},[3917,3921,3926],{"type":15,"tag":360,"props":3918,"children":3919},{"style":373},[3920],{"type":21,"value":3498},{"type":15,"tag":360,"props":3922,"children":3923},{"style":400},[3924],{"type":21,"value":3925},"\"PERSIST\"",{"type":15,"tag":360,"props":3927,"children":3928},{"style":373},[3929],{"type":21,"value":923},{"type":15,"tag":360,"props":3931,"children":3932},{"class":362,"line":449},[3933,3937],{"type":15,"tag":360,"props":3934,"children":3935},{"style":373},[3936],{"type":21,"value":3515},{"type":15,"tag":360,"props":3938,"children":3939},{"style":708},[3940],{"type":21,"value":3941},"24\n",{"type":15,"tag":360,"props":3943,"children":3944},{"class":362,"line":482},[3945],{"type":15,"tag":360,"props":3946,"children":3947},{"style":373},[3948],{"type":21,"value":944},{"type":15,"tag":360,"props":3950,"children":3951},{"class":362,"line":492},[3952],{"type":15,"tag":360,"props":3953,"children":3954},{"emptyLinePlaceholder":839},[3955],{"type":21,"value":842},{"type":15,"tag":360,"props":3957,"children":3958},{"class":362,"line":501},[3959],{"type":15,"tag":360,"props":3960,"children":3961},{"style":486},[3962],{"type":21,"value":3963},"// Each child's action returns something useful:\n",{"type":15,"tag":360,"props":3965,"children":3966},{"class":362,"line":519},[3967],{"type":15,"tag":360,"props":3968,"children":3969},{"style":486},[3970],{"type":21,"value":3971},"// In \"computeStats\": context.return({ rowsProcessed: ..., bytesScanned: ... });\n",{"type":15,"tag":24,"props":3973,"children":3974},{},[3975],{"type":21,"value":3976},"In the finalizer, prefer a cursor-style read so a million children don't try to load into memory at once:",{"type":15,"tag":350,"props":3978,"children":3980},{"className":352,"code":3979,"language":354,"meta":7,"style":7},"let datasetId = context.getInput(\"resultsDatasetId\");\nlet cursor = context.scratchpad.getRecordsCursor(datasetId);\ntry {\n    while (cursor.hasNext()) {\n        let record = cursor.next();\n        let result = record.get(\"data\").get(\"result\");\n        // ... process each child's return value\n    }\n} finally {\n    cursor.close();\n}\n",[3981],{"type":15,"tag":254,"props":3982,"children":3983},{"__ignoreMap":7},[3984,4019,4048,4059,4079,4108,4161,4169,4176,4191,4207],{"type":15,"tag":360,"props":3985,"children":3986},{"class":362,"line":363},[3987,3991,3995,3999,4003,4007,4011,4015],{"type":15,"tag":360,"props":3988,"children":3989},{"style":367},[3990],{"type":21,"value":370},{"type":15,"tag":360,"props":3992,"children":3993},{"style":373},[3994],{"type":21,"value":3622},{"type":15,"tag":360,"props":3996,"children":3997},{"style":367},[3998],{"type":21,"value":381},{"type":15,"tag":360,"props":4000,"children":4001},{"style":373},[4002],{"type":21,"value":386},{"type":15,"tag":360,"props":4004,"children":4005},{"style":389},[4006],{"type":21,"value":1444},{"type":15,"tag":360,"props":4008,"children":4009},{"style":373},[4010],{"type":21,"value":397},{"type":15,"tag":360,"props":4012,"children":4013},{"style":400},[4014],{"type":21,"value":3643},{"type":15,"tag":360,"props":4016,"children":4017},{"style":373},[4018],{"type":21,"value":408},{"type":15,"tag":360,"props":4020,"children":4021},{"class":362,"line":411},[4022,4026,4031,4035,4039,4044],{"type":15,"tag":360,"props":4023,"children":4024},{"style":367},[4025],{"type":21,"value":370},{"type":15,"tag":360,"props":4027,"children":4028},{"style":373},[4029],{"type":21,"value":4030}," cursor ",{"type":15,"tag":360,"props":4032,"children":4033},{"style":367},[4034],{"type":21,"value":381},{"type":15,"tag":360,"props":4036,"children":4037},{"style":373},[4038],{"type":21,"value":3668},{"type":15,"tag":360,"props":4040,"children":4041},{"style":389},[4042],{"type":21,"value":4043},"getRecordsCursor",{"type":15,"tag":360,"props":4045,"children":4046},{"style":373},[4047],{"type":21,"value":3678},{"type":15,"tag":360,"props":4049,"children":4050},{"class":362,"line":425},[4051,4055],{"type":15,"tag":360,"props":4052,"children":4053},{"style":367},[4054],{"type":21,"value":417},{"type":15,"tag":360,"props":4056,"children":4057},{"style":373},[4058],{"type":21,"value":422},{"type":15,"tag":360,"props":4060,"children":4061},{"class":362,"line":449},[4062,4066,4071,4075],{"type":15,"tag":360,"props":4063,"children":4064},{"style":367},[4065],{"type":21,"value":431},{"type":15,"tag":360,"props":4067,"children":4068},{"style":373},[4069],{"type":21,"value":4070}," (cursor.",{"type":15,"tag":360,"props":4072,"children":4073},{"style":389},[4074],{"type":21,"value":441},{"type":15,"tag":360,"props":4076,"children":4077},{"style":373},[4078],{"type":21,"value":446},{"type":15,"tag":360,"props":4080,"children":4081},{"class":362,"line":482},[4082,4086,4091,4095,4100,4104],{"type":15,"tag":360,"props":4083,"children":4084},{"style":367},[4085],{"type":21,"value":455},{"type":15,"tag":360,"props":4087,"children":4088},{"style":373},[4089],{"type":21,"value":4090}," record ",{"type":15,"tag":360,"props":4092,"children":4093},{"style":367},[4094],{"type":21,"value":381},{"type":15,"tag":360,"props":4096,"children":4097},{"style":373},[4098],{"type":21,"value":4099}," cursor.",{"type":15,"tag":360,"props":4101,"children":4102},{"style":389},[4103],{"type":21,"value":474},{"type":15,"tag":360,"props":4105,"children":4106},{"style":373},[4107],{"type":21,"value":479},{"type":15,"tag":360,"props":4109,"children":4110},{"class":362,"line":492},[4111,4115,4119,4123,4127,4131,4135,4140,4144,4148,4152,4157],{"type":15,"tag":360,"props":4112,"children":4113},{"style":367},[4114],{"type":21,"value":455},{"type":15,"tag":360,"props":4116,"children":4117},{"style":373},[4118],{"type":21,"value":376},{"type":15,"tag":360,"props":4120,"children":4121},{"style":367},[4122],{"type":21,"value":381},{"type":15,"tag":360,"props":4124,"children":4125},{"style":373},[4126],{"type":21,"value":3735},{"type":15,"tag":360,"props":4128,"children":4129},{"style":389},[4130],{"type":21,"value":1256},{"type":15,"tag":360,"props":4132,"children":4133},{"style":373},[4134],{"type":21,"value":397},{"type":15,"tag":360,"props":4136,"children":4137},{"style":400},[4138],{"type":21,"value":4139},"\"data\"",{"type":15,"tag":360,"props":4141,"children":4142},{"style":373},[4143],{"type":21,"value":2758},{"type":15,"tag":360,"props":4145,"children":4146},{"style":389},[4147],{"type":21,"value":1256},{"type":15,"tag":360,"props":4149,"children":4150},{"style":373},[4151],{"type":21,"value":397},{"type":15,"tag":360,"props":4153,"children":4154},{"style":400},[4155],{"type":21,"value":4156},"\"result\"",{"type":15,"tag":360,"props":4158,"children":4159},{"style":373},[4160],{"type":21,"value":408},{"type":15,"tag":360,"props":4162,"children":4163},{"class":362,"line":501},[4164],{"type":15,"tag":360,"props":4165,"children":4166},{"style":486},[4167],{"type":21,"value":4168},"        // ... process each child's return value\n",{"type":15,"tag":360,"props":4170,"children":4171},{"class":362,"line":519},[4172],{"type":15,"tag":360,"props":4173,"children":4174},{"style":373},[4175],{"type":21,"value":498},{"type":15,"tag":360,"props":4177,"children":4178},{"class":362,"line":537},[4179,4183,4187],{"type":15,"tag":360,"props":4180,"children":4181},{"style":373},[4182],{"type":21,"value":507},{"type":15,"tag":360,"props":4184,"children":4185},{"style":367},[4186],{"type":21,"value":512},{"type":15,"tag":360,"props":4188,"children":4189},{"style":373},[4190],{"type":21,"value":422},{"type":15,"tag":360,"props":4192,"children":4193},{"class":362,"line":773},[4194,4199,4203],{"type":15,"tag":360,"props":4195,"children":4196},{"style":373},[4197],{"type":21,"value":4198},"    cursor.",{"type":15,"tag":360,"props":4200,"children":4201},{"style":389},[4202],{"type":21,"value":530},{"type":15,"tag":360,"props":4204,"children":4205},{"style":373},[4206],{"type":21,"value":479},{"type":15,"tag":360,"props":4208,"children":4209},{"class":362,"line":1016},[4210],{"type":15,"tag":360,"props":4211,"children":4212},{"style":373},[4213],{"type":21,"value":543},{"type":15,"tag":24,"props":4215,"children":4216},{},[4217,4219,4225],{"type":21,"value":4218},"The scratchpad cursor is closed in a ",{"type":15,"tag":254,"props":4220,"children":4222},{"className":4221},[],[4223],{"type":21,"value":4224},"try/finally",{"type":21,"value":4226}," for the same reason database results are: it holds an open transaction.",{"type":15,"tag":325,"props":4228,"children":4230},{"id":4229},"reduce-aggregate-as-you-go",[4231,4237],{"type":15,"tag":254,"props":4232,"children":4234},{"className":4233},[],[4235],{"type":21,"value":4236},"REDUCE",{"type":21,"value":4238}," — Aggregate as You Go",{"type":15,"tag":24,"props":4240,"children":4241},{},[4242,4244,4249],{"type":21,"value":4243},"For when you want to ",{"type":15,"tag":30,"props":4245,"children":4246},{},[4247],{"type":21,"value":4248},"aggregate",{"type":21,"value":4250}," child results without storing them all. Each child's result is folded into a running accumulator by a reducer action you write. Memory cost is constant regardless of how many children you have.",{"type":15,"tag":24,"props":4252,"children":4253},{},[4254],{"type":21,"value":4255},"This is the right choice for things like: \"sum the bytes scanned across all 100,000 children\" or \"build a count-by-category histogram.\"",{"type":15,"tag":350,"props":4257,"children":4259},{"className":352,"code":4258,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess:      \"done\",\n    results:        \"REDUCE\",\n    reducer:        \"sumBytes\",\n    reducerInitial: { totalBytes: 0, totalRows: 0 }\n});\n",[4260],{"type":15,"tag":254,"props":4261,"children":4262},{"__ignoreMap":7},[4263,4290,4306,4323,4340,4367],{"type":15,"tag":360,"props":4264,"children":4265},{"class":362,"line":363},[4266,4270,4274,4278,4282,4286],{"type":15,"tag":360,"props":4267,"children":4268},{"style":367},[4269],{"type":21,"value":370},{"type":15,"tag":360,"props":4271,"children":4272},{"style":373},[4273],{"type":21,"value":611},{"type":15,"tag":360,"props":4275,"children":4276},{"style":367},[4277],{"type":21,"value":381},{"type":15,"tag":360,"props":4279,"children":4280},{"style":373},[4281],{"type":21,"value":386},{"type":15,"tag":360,"props":4283,"children":4284},{"style":389},[4285],{"type":21,"value":259},{"type":15,"tag":360,"props":4287,"children":4288},{"style":373},[4289],{"type":21,"value":905},{"type":15,"tag":360,"props":4291,"children":4292},{"class":362,"line":411},[4293,4298,4302],{"type":15,"tag":360,"props":4294,"children":4295},{"style":373},[4296],{"type":21,"value":4297},"    onSuccess:      ",{"type":15,"tag":360,"props":4299,"children":4300},{"style":400},[4301],{"type":21,"value":2668},{"type":15,"tag":360,"props":4303,"children":4304},{"style":373},[4305],{"type":21,"value":923},{"type":15,"tag":360,"props":4307,"children":4308},{"class":362,"line":425},[4309,4314,4319],{"type":15,"tag":360,"props":4310,"children":4311},{"style":373},[4312],{"type":21,"value":4313},"    results:        ",{"type":15,"tag":360,"props":4315,"children":4316},{"style":400},[4317],{"type":21,"value":4318},"\"REDUCE\"",{"type":15,"tag":360,"props":4320,"children":4321},{"style":373},[4322],{"type":21,"value":923},{"type":15,"tag":360,"props":4324,"children":4325},{"class":362,"line":449},[4326,4331,4336],{"type":15,"tag":360,"props":4327,"children":4328},{"style":373},[4329],{"type":21,"value":4330},"    reducer:        ",{"type":15,"tag":360,"props":4332,"children":4333},{"style":400},[4334],{"type":21,"value":4335},"\"sumBytes\"",{"type":15,"tag":360,"props":4337,"children":4338},{"style":373},[4339],{"type":21,"value":923},{"type":15,"tag":360,"props":4341,"children":4342},{"class":362,"line":482},[4343,4348,4353,4358,4362],{"type":15,"tag":360,"props":4344,"children":4345},{"style":373},[4346],{"type":21,"value":4347},"    reducerInitial: { totalBytes: ",{"type":15,"tag":360,"props":4349,"children":4350},{"style":708},[4351],{"type":21,"value":4352},"0",{"type":15,"tag":360,"props":4354,"children":4355},{"style":373},[4356],{"type":21,"value":4357},", totalRows: ",{"type":15,"tag":360,"props":4359,"children":4360},{"style":708},[4361],{"type":21,"value":4352},{"type":15,"tag":360,"props":4363,"children":4364},{"style":373},[4365],{"type":21,"value":4366}," }\n",{"type":15,"tag":360,"props":4368,"children":4369},{"class":362,"line":492},[4370],{"type":15,"tag":360,"props":4371,"children":4372},{"style":373},[4373],{"type":21,"value":944},{"type":15,"tag":24,"props":4375,"children":4376},{},[4377],{"type":21,"value":4378},"The reducer action receives the current accumulator and one child's result, and returns the new accumulator:",{"type":15,"tag":350,"props":4380,"children":4382},{"className":352,"code":4381,"language":354,"meta":7,"style":7},"// Action: \"sumBytes\"\nlet accumulator = context.getInput(\"accumulator\");\nlet childResult = context.getInput(\"result\");\n\ncontext.return({\n    totalBytes: accumulator.get(\"totalBytes\") + childResult.get(\"bytes\"),\n    totalRows:  accumulator.get(\"totalRows\")  + childResult.get(\"rows\")\n});\n",[4383],{"type":15,"tag":254,"props":4384,"children":4385},{"__ignoreMap":7},[4386,4394,4431,4467,4474,4490,4541,4592],{"type":15,"tag":360,"props":4387,"children":4388},{"class":362,"line":363},[4389],{"type":15,"tag":360,"props":4390,"children":4391},{"style":486},[4392],{"type":21,"value":4393},"// Action: \"sumBytes\"\n",{"type":15,"tag":360,"props":4395,"children":4396},{"class":362,"line":411},[4397,4401,4406,4410,4414,4418,4422,4427],{"type":15,"tag":360,"props":4398,"children":4399},{"style":367},[4400],{"type":21,"value":370},{"type":15,"tag":360,"props":4402,"children":4403},{"style":373},[4404],{"type":21,"value":4405}," accumulator ",{"type":15,"tag":360,"props":4407,"children":4408},{"style":367},[4409],{"type":21,"value":381},{"type":15,"tag":360,"props":4411,"children":4412},{"style":373},[4413],{"type":21,"value":386},{"type":15,"tag":360,"props":4415,"children":4416},{"style":389},[4417],{"type":21,"value":1444},{"type":15,"tag":360,"props":4419,"children":4420},{"style":373},[4421],{"type":21,"value":397},{"type":15,"tag":360,"props":4423,"children":4424},{"style":400},[4425],{"type":21,"value":4426},"\"accumulator\"",{"type":15,"tag":360,"props":4428,"children":4429},{"style":373},[4430],{"type":21,"value":408},{"type":15,"tag":360,"props":4432,"children":4433},{"class":362,"line":425},[4434,4438,4443,4447,4451,4455,4459,4463],{"type":15,"tag":360,"props":4435,"children":4436},{"style":367},[4437],{"type":21,"value":370},{"type":15,"tag":360,"props":4439,"children":4440},{"style":373},[4441],{"type":21,"value":4442}," childResult ",{"type":15,"tag":360,"props":4444,"children":4445},{"style":367},[4446],{"type":21,"value":381},{"type":15,"tag":360,"props":4448,"children":4449},{"style":373},[4450],{"type":21,"value":386},{"type":15,"tag":360,"props":4452,"children":4453},{"style":389},[4454],{"type":21,"value":1444},{"type":15,"tag":360,"props":4456,"children":4457},{"style":373},[4458],{"type":21,"value":397},{"type":15,"tag":360,"props":4460,"children":4461},{"style":400},[4462],{"type":21,"value":4156},{"type":15,"tag":360,"props":4464,"children":4465},{"style":373},[4466],{"type":21,"value":408},{"type":15,"tag":360,"props":4468,"children":4469},{"class":362,"line":449},[4470],{"type":15,"tag":360,"props":4471,"children":4472},{"emptyLinePlaceholder":839},[4473],{"type":21,"value":842},{"type":15,"tag":360,"props":4475,"children":4476},{"class":362,"line":482},[4477,4481,4486],{"type":15,"tag":360,"props":4478,"children":4479},{"style":373},[4480],{"type":21,"value":1234},{"type":15,"tag":360,"props":4482,"children":4483},{"style":389},[4484],{"type":21,"value":4485},"return",{"type":15,"tag":360,"props":4487,"children":4488},{"style":373},[4489],{"type":21,"value":905},{"type":15,"tag":360,"props":4491,"children":4492},{"class":362,"line":492},[4493,4498,4502,4506,4511,4515,4519,4524,4528,4532,4537],{"type":15,"tag":360,"props":4494,"children":4495},{"style":373},[4496],{"type":21,"value":4497},"    totalBytes: accumulator.",{"type":15,"tag":360,"props":4499,"children":4500},{"style":389},[4501],{"type":21,"value":1256},{"type":15,"tag":360,"props":4503,"children":4504},{"style":373},[4505],{"type":21,"value":397},{"type":15,"tag":360,"props":4507,"children":4508},{"style":400},[4509],{"type":21,"value":4510},"\"totalBytes\"",{"type":15,"tag":360,"props":4512,"children":4513},{"style":373},[4514],{"type":21,"value":3594},{"type":15,"tag":360,"props":4516,"children":4517},{"style":367},[4518],{"type":21,"value":2909},{"type":15,"tag":360,"props":4520,"children":4521},{"style":373},[4522],{"type":21,"value":4523}," childResult.",{"type":15,"tag":360,"props":4525,"children":4526},{"style":389},[4527],{"type":21,"value":1256},{"type":15,"tag":360,"props":4529,"children":4530},{"style":373},[4531],{"type":21,"value":397},{"type":15,"tag":360,"props":4533,"children":4534},{"style":400},[4535],{"type":21,"value":4536},"\"bytes\"",{"type":15,"tag":360,"props":4538,"children":4539},{"style":373},[4540],{"type":21,"value":1270},{"type":15,"tag":360,"props":4542,"children":4543},{"class":362,"line":501},[4544,4549,4553,4557,4562,4567,4571,4575,4579,4583,4588],{"type":15,"tag":360,"props":4545,"children":4546},{"style":373},[4547],{"type":21,"value":4548},"    totalRows:  accumulator.",{"type":15,"tag":360,"props":4550,"children":4551},{"style":389},[4552],{"type":21,"value":1256},{"type":15,"tag":360,"props":4554,"children":4555},{"style":373},[4556],{"type":21,"value":397},{"type":15,"tag":360,"props":4558,"children":4559},{"style":400},[4560],{"type":21,"value":4561},"\"totalRows\"",{"type":15,"tag":360,"props":4563,"children":4564},{"style":373},[4565],{"type":21,"value":4566},")  ",{"type":15,"tag":360,"props":4568,"children":4569},{"style":367},[4570],{"type":21,"value":2909},{"type":15,"tag":360,"props":4572,"children":4573},{"style":373},[4574],{"type":21,"value":4523},{"type":15,"tag":360,"props":4576,"children":4577},{"style":389},[4578],{"type":21,"value":1256},{"type":15,"tag":360,"props":4580,"children":4581},{"style":373},[4582],{"type":21,"value":397},{"type":15,"tag":360,"props":4584,"children":4585},{"style":400},[4586],{"type":21,"value":4587},"\"rows\"",{"type":15,"tag":360,"props":4589,"children":4590},{"style":373},[4591],{"type":21,"value":1972},{"type":15,"tag":360,"props":4593,"children":4594},{"class":362,"line":519},[4595],{"type":15,"tag":360,"props":4596,"children":4597},{"style":373},[4598],{"type":21,"value":944},{"type":15,"tag":2164,"props":4600,"children":4601},{},[4602],{"type":15,"tag":24,"props":4603,"children":4604},{},[4605,4610,4612,4617],{"type":15,"tag":30,"props":4606,"children":4607},{},[4608],{"type":21,"value":4609},"Critical:",{"type":21,"value":4611}," The reducer must be ",{"type":15,"tag":30,"props":4613,"children":4614},{},[4615],{"type":21,"value":4616},"pure",{"type":21,"value":4618},". If two children report at the same time and the platform retries the reducer to resolve the race, it must be safe to run twice. Don't write to the database, don't call external APIs — just compute the new accumulator from the inputs. Anything else risks duplicate side effects.",{"type":15,"tag":24,"props":4620,"children":4621},{},[4622,4624,4630],{"type":21,"value":4623},"The final accumulator is stored on the execution document; it's available in the finalizer as ",{"type":15,"tag":254,"props":4625,"children":4627},{"className":4626},[],[4628],{"type":21,"value":4629},"context.getInput(\"reducerState\")",{"type":21,"value":1664},{"type":15,"tag":325,"props":4632,"children":4634},{"id":4633},"choosing-a-result-mode",[4635],{"type":21,"value":4636},"Choosing a Result Mode",{"type":15,"tag":208,"props":4638,"children":4639},{},[4640,4661],{"type":15,"tag":212,"props":4641,"children":4642},{},[4643],{"type":15,"tag":216,"props":4644,"children":4645},{},[4646,4651,4656],{"type":15,"tag":220,"props":4647,"children":4648},{},[4649],{"type":21,"value":4650},"Mode",{"type":15,"tag":220,"props":4652,"children":4653},{},[4654],{"type":21,"value":4655},"Storage Cost",{"type":15,"tag":220,"props":4657,"children":4658},{},[4659],{"type":21,"value":4660},"When to Use",{"type":15,"tag":236,"props":4662,"children":4663},{},[4664,4685,4706,4727],{"type":15,"tag":216,"props":4665,"children":4666},{},[4667,4675,4680],{"type":15,"tag":243,"props":4668,"children":4669},{},[4670],{"type":15,"tag":254,"props":4671,"children":4673},{"className":4672},[],[4674],{"type":21,"value":3354},{"type":15,"tag":243,"props":4676,"children":4677},{},[4678],{"type":21,"value":4679},"None",{"type":15,"tag":243,"props":4681,"children":4682},{},[4683],{"type":21,"value":4684},"Default. You only need totals.",{"type":15,"tag":216,"props":4686,"children":4687},{},[4688,4696,4701],{"type":15,"tag":243,"props":4689,"children":4690},{},[4691],{"type":15,"tag":254,"props":4692,"children":4694},{"className":4693},[],[4695],{"type":21,"value":3410},{"type":15,"tag":243,"props":4697,"children":4698},{},[4699],{"type":21,"value":4700},"Proportional to failure rate",{"type":15,"tag":243,"props":4702,"children":4703},{},[4704],{"type":21,"value":4705},"You need to debug or retry failures.",{"type":15,"tag":216,"props":4707,"children":4708},{},[4709,4717,4722],{"type":15,"tag":243,"props":4710,"children":4711},{},[4712],{"type":15,"tag":254,"props":4713,"children":4715},{"className":4714},[],[4716],{"type":21,"value":3850},{"type":15,"tag":243,"props":4718,"children":4719},{},[4720],{"type":21,"value":4721},"Proportional to total children",{"type":15,"tag":243,"props":4723,"children":4724},{},[4725],{"type":21,"value":4726},"You need every return value.",{"type":15,"tag":216,"props":4728,"children":4729},{},[4730,4738,4743],{"type":15,"tag":243,"props":4731,"children":4732},{},[4733],{"type":15,"tag":254,"props":4734,"children":4736},{"className":4735},[],[4737],{"type":21,"value":4236},{"type":15,"tag":243,"props":4739,"children":4740},{},[4741],{"type":21,"value":4742},"Constant",{"type":15,"tag":243,"props":4744,"children":4745},{},[4746],{"type":21,"value":4747},"You need an aggregate (sum, count, histogram).",{"type":15,"tag":805,"props":4749,"children":4750},{},[],{"type":15,"tag":126,"props":4752,"children":4754},{"id":4753},"inspecting-and-cancelling-a-running-batch",[4755],{"type":21,"value":4756},"Inspecting and Cancelling a Running Batch",{"type":15,"tag":24,"props":4758,"children":4759},{},[4760,4762,4767],{"type":21,"value":4761},"The handle returned by ",{"type":15,"tag":254,"props":4763,"children":4765},{"className":4764},[],[4766],{"type":21,"value":259},{"type":21,"value":4768}," lets you check on a running batch or cancel it:",{"type":15,"tag":350,"props":4770,"children":4772},{"className":352,"code":4771,"language":354,"meta":7,"style":7},"let snapshot = batch.snapshot();\ncontext.log(\"Batch progress: {}/{} done, {} failed\",\n    snapshot.get(\"succeededJobs\") + snapshot.get(\"failedJobs\"),\n    snapshot.get(\"totalJobs\"),\n    snapshot.get(\"failedJobs\"));\n\n// Or to abort:\nbatch.cancel();\n",[4773],{"type":15,"tag":254,"props":4774,"children":4775},{"__ignoreMap":7},[4776,4806,4830,4879,4902,4925,4932,4940],{"type":15,"tag":360,"props":4777,"children":4778},{"class":362,"line":363},[4779,4783,4788,4792,4797,4802],{"type":15,"tag":360,"props":4780,"children":4781},{"style":367},[4782],{"type":21,"value":370},{"type":15,"tag":360,"props":4784,"children":4785},{"style":373},[4786],{"type":21,"value":4787}," snapshot ",{"type":15,"tag":360,"props":4789,"children":4790},{"style":367},[4791],{"type":21,"value":381},{"type":15,"tag":360,"props":4793,"children":4794},{"style":373},[4795],{"type":21,"value":4796}," batch.",{"type":15,"tag":360,"props":4798,"children":4799},{"style":389},[4800],{"type":21,"value":4801},"snapshot",{"type":15,"tag":360,"props":4803,"children":4804},{"style":373},[4805],{"type":21,"value":479},{"type":15,"tag":360,"props":4807,"children":4808},{"class":362,"line":411},[4809,4813,4817,4821,4826],{"type":15,"tag":360,"props":4810,"children":4811},{"style":373},[4812],{"type":21,"value":1234},{"type":15,"tag":360,"props":4814,"children":4815},{"style":389},[4816],{"type":21,"value":1418},{"type":15,"tag":360,"props":4818,"children":4819},{"style":373},[4820],{"type":21,"value":397},{"type":15,"tag":360,"props":4822,"children":4823},{"style":400},[4824],{"type":21,"value":4825},"\"Batch progress: {}/{} done, {} failed\"",{"type":15,"tag":360,"props":4827,"children":4828},{"style":373},[4829],{"type":21,"value":923},{"type":15,"tag":360,"props":4831,"children":4832},{"class":362,"line":425},[4833,4838,4842,4846,4850,4854,4858,4863,4867,4871,4875],{"type":15,"tag":360,"props":4834,"children":4835},{"style":373},[4836],{"type":21,"value":4837},"    snapshot.",{"type":15,"tag":360,"props":4839,"children":4840},{"style":389},[4841],{"type":21,"value":1256},{"type":15,"tag":360,"props":4843,"children":4844},{"style":373},[4845],{"type":21,"value":397},{"type":15,"tag":360,"props":4847,"children":4848},{"style":400},[4849],{"type":21,"value":1453},{"type":15,"tag":360,"props":4851,"children":4852},{"style":373},[4853],{"type":21,"value":3594},{"type":15,"tag":360,"props":4855,"children":4856},{"style":367},[4857],{"type":21,"value":2909},{"type":15,"tag":360,"props":4859,"children":4860},{"style":373},[4861],{"type":21,"value":4862}," snapshot.",{"type":15,"tag":360,"props":4864,"children":4865},{"style":389},[4866],{"type":21,"value":1256},{"type":15,"tag":360,"props":4868,"children":4869},{"style":373},[4870],{"type":21,"value":397},{"type":15,"tag":360,"props":4872,"children":4873},{"style":400},[4874],{"type":21,"value":1477},{"type":15,"tag":360,"props":4876,"children":4877},{"style":373},[4878],{"type":21,"value":1270},{"type":15,"tag":360,"props":4880,"children":4881},{"class":362,"line":449},[4882,4886,4890,4894,4898],{"type":15,"tag":360,"props":4883,"children":4884},{"style":373},[4885],{"type":21,"value":4837},{"type":15,"tag":360,"props":4887,"children":4888},{"style":389},[4889],{"type":21,"value":1256},{"type":15,"tag":360,"props":4891,"children":4892},{"style":373},[4893],{"type":21,"value":397},{"type":15,"tag":360,"props":4895,"children":4896},{"style":400},[4897],{"type":21,"value":1501},{"type":15,"tag":360,"props":4899,"children":4900},{"style":373},[4901],{"type":21,"value":1270},{"type":15,"tag":360,"props":4903,"children":4904},{"class":362,"line":482},[4905,4909,4913,4917,4921],{"type":15,"tag":360,"props":4906,"children":4907},{"style":373},[4908],{"type":21,"value":4837},{"type":15,"tag":360,"props":4910,"children":4911},{"style":389},[4912],{"type":21,"value":1256},{"type":15,"tag":360,"props":4914,"children":4915},{"style":373},[4916],{"type":21,"value":397},{"type":15,"tag":360,"props":4918,"children":4919},{"style":400},[4920],{"type":21,"value":1477},{"type":15,"tag":360,"props":4922,"children":4923},{"style":373},[4924],{"type":21,"value":1506},{"type":15,"tag":360,"props":4926,"children":4927},{"class":362,"line":492},[4928],{"type":15,"tag":360,"props":4929,"children":4930},{"emptyLinePlaceholder":839},[4931],{"type":21,"value":842},{"type":15,"tag":360,"props":4933,"children":4934},{"class":362,"line":501},[4935],{"type":15,"tag":360,"props":4936,"children":4937},{"style":486},[4938],{"type":21,"value":4939},"// Or to abort:\n",{"type":15,"tag":360,"props":4941,"children":4942},{"class":362,"line":519},[4943,4948,4953],{"type":15,"tag":360,"props":4944,"children":4945},{"style":373},[4946],{"type":21,"value":4947},"batch.",{"type":15,"tag":360,"props":4949,"children":4950},{"style":389},[4951],{"type":21,"value":4952},"cancel",{"type":15,"tag":360,"props":4954,"children":4955},{"style":373},[4956],{"type":21,"value":479},{"type":15,"tag":24,"props":4958,"children":4959},{},[4960,4962,4967,4969,4974,4976,4981],{"type":21,"value":4961},"Cancelling causes the batch to immediately transition to ",{"type":15,"tag":254,"props":4963,"children":4965},{"className":4964},[],[4966],{"type":21,"value":1662},{"type":21,"value":4968}," and run ",{"type":15,"tag":254,"props":4970,"children":4972},{"className":4971},[],[4973],{"type":21,"value":1538},{"type":21,"value":4975}," with ",{"type":15,"tag":254,"props":4977,"children":4979},{"className":4978},[],[4980],{"type":21,"value":2568},{"type":21,"value":4982},". Children already running will finish (they can't be unsent from the queue), but their results are ignored.",{"type":15,"tag":24,"props":4984,"children":4985},{},[4986,4992],{"type":15,"tag":254,"props":4987,"children":4989},{"className":4988},[],[4990],{"type":21,"value":4991},"snapshot()",{"type":21,"value":4993}," reads from the database, so it's a real-time view across all worker instances — not just what this script knows.",{"type":15,"tag":805,"props":4995,"children":4996},{},[],{"type":15,"tag":126,"props":4998,"children":5000},{"id":4999},"real-world-use-cases",[5001],{"type":21,"value":5002},"Real-World Use Cases",{"type":15,"tag":24,"props":5004,"children":5005},{},[5006],{"type":21,"value":5007},"This is where it all comes together. Each example below is a fully-worked scenario showing how to combine the features above for a common business problem.",{"type":15,"tag":325,"props":5009,"children":5011},{"id":5010},"use-case-1-bulk-email-campaign",[5012],{"type":21,"value":5013},"Use Case 1: Bulk Email Campaign",{"type":15,"tag":24,"props":5015,"children":5016},{},[5017,5022],{"type":15,"tag":30,"props":5018,"children":5019},{},[5020],{"type":21,"value":5021},"The job:",{"type":21,"value":5023}," A marketing team clicks \"Send\" on a campaign that targets 80,000 customers. The button click should return immediately, the emails should send in the background, and the team should be notified when it's done.",{"type":15,"tag":350,"props":5025,"children":5027},{"className":352,"code":5026,"language":354,"meta":7,"style":7},"// Action: \"sendCampaign\" — triggered by the marketing UI\n\nlet campaignId = context.getRecord().get(\"id\");\n\nlet recipients = context.query(\n    \"select c from customer c \" +\n    \"where c.optedInToMarketing = true \" +\n    \"and c.country in ${countries}\",\n    { countries: campaign.get(\"targetCountries\") });\n\nlet batch = context.createBatch({\n    onSuccess: \"campaignFinishedNotification\",\n    onPartial: \"campaignFinishedNotification\",\n    onError:   \"campaignFailedNotification\",\n    results:           \"FAILURES_ONLY\",     // we want to see the bounces\n    failureThreshold:  0.05,                // 5% bounce budget\n    failureMinSamples: 100,\n    maxConcurrent:     50,                  // don't overwhelm the SMTP server\n    deadlineMs:        Date.now() + 4 * 60 * 60 * 1000,\n    context: {\n        campaignId:  campaignId,\n        triggeredBy: context.user.username\n    }\n});\ntry {\n    while (recipients.hasNext()) {\n        batch.add(\"sendOneCampaignEmail\", recipients.next(), {\n            campaignId: campaignId\n        });\n    }\n} finally {\n    recipients.close();\n    batch.seal();\n}\n\ncontext.return({\n    message: \"Campaign queued for \"\n             + batch.snapshot().get(\"totalJobs\") + \" recipients\",\n    batchId: batch.getId()\n});\n",[5028],{"type":15,"tag":254,"props":5029,"children":5030},{"__ignoreMap":7},[5031,5039,5046,5091,5098,5127,5140,5152,5164,5190,5197,5224,5240,5256,5272,5294,5317,5334,5357,5411,5419,5428,5437,5445,5453,5465,5486,5521,5530,5539,5547,5563,5580,5596,5604,5612,5628,5642,5692,5711],{"type":15,"tag":360,"props":5032,"children":5033},{"class":362,"line":363},[5034],{"type":15,"tag":360,"props":5035,"children":5036},{"style":486},[5037],{"type":21,"value":5038},"// Action: \"sendCampaign\" — triggered by the marketing UI\n",{"type":15,"tag":360,"props":5040,"children":5041},{"class":362,"line":411},[5042],{"type":15,"tag":360,"props":5043,"children":5044},{"emptyLinePlaceholder":839},[5045],{"type":21,"value":842},{"type":15,"tag":360,"props":5047,"children":5048},{"class":362,"line":425},[5049,5053,5058,5062,5066,5070,5075,5079,5083,5087],{"type":15,"tag":360,"props":5050,"children":5051},{"style":367},[5052],{"type":21,"value":370},{"type":15,"tag":360,"props":5054,"children":5055},{"style":373},[5056],{"type":21,"value":5057}," campaignId ",{"type":15,"tag":360,"props":5059,"children":5060},{"style":367},[5061],{"type":21,"value":381},{"type":15,"tag":360,"props":5063,"children":5064},{"style":373},[5065],{"type":21,"value":386},{"type":15,"tag":360,"props":5067,"children":5068},{"style":389},[5069],{"type":21,"value":1216},{"type":15,"tag":360,"props":5071,"children":5072},{"style":373},[5073],{"type":21,"value":5074},"().",{"type":15,"tag":360,"props":5076,"children":5077},{"style":389},[5078],{"type":21,"value":1256},{"type":15,"tag":360,"props":5080,"children":5081},{"style":373},[5082],{"type":21,"value":397},{"type":15,"tag":360,"props":5084,"children":5085},{"style":400},[5086],{"type":21,"value":1967},{"type":15,"tag":360,"props":5088,"children":5089},{"style":373},[5090],{"type":21,"value":408},{"type":15,"tag":360,"props":5092,"children":5093},{"class":362,"line":449},[5094],{"type":15,"tag":360,"props":5095,"children":5096},{"emptyLinePlaceholder":839},[5097],{"type":21,"value":842},{"type":15,"tag":360,"props":5099,"children":5100},{"class":362,"line":482},[5101,5105,5110,5114,5118,5122],{"type":15,"tag":360,"props":5102,"children":5103},{"style":367},[5104],{"type":21,"value":370},{"type":15,"tag":360,"props":5106,"children":5107},{"style":373},[5108],{"type":21,"value":5109}," recipients ",{"type":15,"tag":360,"props":5111,"children":5112},{"style":367},[5113],{"type":21,"value":381},{"type":15,"tag":360,"props":5115,"children":5116},{"style":373},[5117],{"type":21,"value":386},{"type":15,"tag":360,"props":5119,"children":5120},{"style":389},[5121],{"type":21,"value":392},{"type":15,"tag":360,"props":5123,"children":5124},{"style":373},[5125],{"type":21,"value":5126},"(\n",{"type":15,"tag":360,"props":5128,"children":5129},{"class":362,"line":492},[5130,5135],{"type":15,"tag":360,"props":5131,"children":5132},{"style":400},[5133],{"type":21,"value":5134},"    \"select c from customer c \"",{"type":15,"tag":360,"props":5136,"children":5137},{"style":367},[5138],{"type":21,"value":5139}," +\n",{"type":15,"tag":360,"props":5141,"children":5142},{"class":362,"line":501},[5143,5148],{"type":15,"tag":360,"props":5144,"children":5145},{"style":400},[5146],{"type":21,"value":5147},"    \"where c.optedInToMarketing = true \"",{"type":15,"tag":360,"props":5149,"children":5150},{"style":367},[5151],{"type":21,"value":5139},{"type":15,"tag":360,"props":5153,"children":5154},{"class":362,"line":519},[5155,5160],{"type":15,"tag":360,"props":5156,"children":5157},{"style":400},[5158],{"type":21,"value":5159},"    \"and c.country in ${countries}\"",{"type":15,"tag":360,"props":5161,"children":5162},{"style":373},[5163],{"type":21,"value":923},{"type":15,"tag":360,"props":5165,"children":5166},{"class":362,"line":537},[5167,5172,5176,5180,5185],{"type":15,"tag":360,"props":5168,"children":5169},{"style":373},[5170],{"type":21,"value":5171},"    { countries: campaign.",{"type":15,"tag":360,"props":5173,"children":5174},{"style":389},[5175],{"type":21,"value":1256},{"type":15,"tag":360,"props":5177,"children":5178},{"style":373},[5179],{"type":21,"value":397},{"type":15,"tag":360,"props":5181,"children":5182},{"style":400},[5183],{"type":21,"value":5184},"\"targetCountries\"",{"type":15,"tag":360,"props":5186,"children":5187},{"style":373},[5188],{"type":21,"value":5189},") });\n",{"type":15,"tag":360,"props":5191,"children":5192},{"class":362,"line":773},[5193],{"type":15,"tag":360,"props":5194,"children":5195},{"emptyLinePlaceholder":839},[5196],{"type":21,"value":842},{"type":15,"tag":360,"props":5198,"children":5199},{"class":362,"line":1016},[5200,5204,5208,5212,5216,5220],{"type":15,"tag":360,"props":5201,"children":5202},{"style":367},[5203],{"type":21,"value":370},{"type":15,"tag":360,"props":5205,"children":5206},{"style":373},[5207],{"type":21,"value":611},{"type":15,"tag":360,"props":5209,"children":5210},{"style":367},[5211],{"type":21,"value":381},{"type":15,"tag":360,"props":5213,"children":5214},{"style":373},[5215],{"type":21,"value":386},{"type":15,"tag":360,"props":5217,"children":5218},{"style":389},[5219],{"type":21,"value":259},{"type":15,"tag":360,"props":5221,"children":5222},{"style":373},[5223],{"type":21,"value":905},{"type":15,"tag":360,"props":5225,"children":5226},{"class":362,"line":1024},[5227,5231,5236],{"type":15,"tag":360,"props":5228,"children":5229},{"style":373},[5230],{"type":21,"value":913},{"type":15,"tag":360,"props":5232,"children":5233},{"style":400},[5234],{"type":21,"value":5235},"\"campaignFinishedNotification\"",{"type":15,"tag":360,"props":5237,"children":5238},{"style":373},[5239],{"type":21,"value":923},{"type":15,"tag":360,"props":5241,"children":5242},{"class":362,"line":1040},[5243,5248,5252],{"type":15,"tag":360,"props":5244,"children":5245},{"style":373},[5246],{"type":21,"value":5247},"    onPartial: ",{"type":15,"tag":360,"props":5249,"children":5250},{"style":400},[5251],{"type":21,"value":5235},{"type":15,"tag":360,"props":5253,"children":5254},{"style":373},[5255],{"type":21,"value":923},{"type":15,"tag":360,"props":5257,"children":5258},{"class":362,"line":1056},[5259,5263,5268],{"type":15,"tag":360,"props":5260,"children":5261},{"style":373},[5262],{"type":21,"value":931},{"type":15,"tag":360,"props":5264,"children":5265},{"style":400},[5266],{"type":21,"value":5267},"\"campaignFailedNotification\"",{"type":15,"tag":360,"props":5269,"children":5270},{"style":373},[5271],{"type":21,"value":923},{"type":15,"tag":360,"props":5273,"children":5274},{"class":362,"line":1072},[5275,5280,5284,5289],{"type":15,"tag":360,"props":5276,"children":5277},{"style":373},[5278],{"type":21,"value":5279},"    results:           ",{"type":15,"tag":360,"props":5281,"children":5282},{"style":400},[5283],{"type":21,"value":3503},{"type":15,"tag":360,"props":5285,"children":5286},{"style":373},[5287],{"type":21,"value":5288},",     ",{"type":15,"tag":360,"props":5290,"children":5291},{"style":486},[5292],{"type":21,"value":5293},"// we want to see the bounces\n",{"type":15,"tag":360,"props":5295,"children":5297},{"class":362,"line":5296},16,[5298,5302,5307,5312],{"type":15,"tag":360,"props":5299,"children":5300},{"style":373},[5301],{"type":21,"value":2697},{"type":15,"tag":360,"props":5303,"children":5304},{"style":708},[5305],{"type":21,"value":5306},"0.05",{"type":15,"tag":360,"props":5308,"children":5309},{"style":373},[5310],{"type":21,"value":5311},",                ",{"type":15,"tag":360,"props":5313,"children":5314},{"style":486},[5315],{"type":21,"value":5316},"// 5% bounce budget\n",{"type":15,"tag":360,"props":5318,"children":5320},{"class":362,"line":5319},17,[5321,5325,5330],{"type":15,"tag":360,"props":5322,"children":5323},{"style":373},[5324],{"type":21,"value":2720},{"type":15,"tag":360,"props":5326,"children":5327},{"style":708},[5328],{"type":21,"value":5329},"100",{"type":15,"tag":360,"props":5331,"children":5332},{"style":373},[5333],{"type":21,"value":923},{"type":15,"tag":360,"props":5335,"children":5337},{"class":362,"line":5336},18,[5338,5343,5347,5352],{"type":15,"tag":360,"props":5339,"children":5340},{"style":373},[5341],{"type":21,"value":5342},"    maxConcurrent:     ",{"type":15,"tag":360,"props":5344,"children":5345},{"style":708},[5346],{"type":21,"value":2725},{"type":15,"tag":360,"props":5348,"children":5349},{"style":373},[5350],{"type":21,"value":5351},",                  ",{"type":15,"tag":360,"props":5353,"children":5354},{"style":486},[5355],{"type":21,"value":5356},"// don't overwhelm the SMTP server\n",{"type":15,"tag":360,"props":5358,"children":5360},{"class":362,"line":5359},19,[5361,5366,5370,5374,5378,5383,5387,5391,5395,5399,5403,5407],{"type":15,"tag":360,"props":5362,"children":5363},{"style":373},[5364],{"type":21,"value":5365},"    deadlineMs:        Date.",{"type":15,"tag":360,"props":5367,"children":5368},{"style":389},[5369],{"type":21,"value":2899},{"type":15,"tag":360,"props":5371,"children":5372},{"style":373},[5373],{"type":21,"value":2904},{"type":15,"tag":360,"props":5375,"children":5376},{"style":367},[5377],{"type":21,"value":2909},{"type":15,"tag":360,"props":5379,"children":5380},{"style":708},[5381],{"type":21,"value":5382}," 4",{"type":15,"tag":360,"props":5384,"children":5385},{"style":367},[5386],{"type":21,"value":2919},{"type":15,"tag":360,"props":5388,"children":5389},{"style":708},[5390],{"type":21,"value":2924},{"type":15,"tag":360,"props":5392,"children":5393},{"style":367},[5394],{"type":21,"value":2919},{"type":15,"tag":360,"props":5396,"children":5397},{"style":708},[5398],{"type":21,"value":2924},{"type":15,"tag":360,"props":5400,"children":5401},{"style":367},[5402],{"type":21,"value":2919},{"type":15,"tag":360,"props":5404,"children":5405},{"style":708},[5406],{"type":21,"value":2933},{"type":15,"tag":360,"props":5408,"children":5409},{"style":373},[5410],{"type":21,"value":923},{"type":15,"tag":360,"props":5412,"children":5414},{"class":362,"line":5413},20,[5415],{"type":15,"tag":360,"props":5416,"children":5417},{"style":373},[5418],{"type":21,"value":1938},{"type":15,"tag":360,"props":5420,"children":5422},{"class":362,"line":5421},21,[5423],{"type":15,"tag":360,"props":5424,"children":5425},{"style":373},[5426],{"type":21,"value":5427},"        campaignId:  campaignId,\n",{"type":15,"tag":360,"props":5429,"children":5431},{"class":362,"line":5430},22,[5432],{"type":15,"tag":360,"props":5433,"children":5434},{"style":373},[5435],{"type":21,"value":5436},"        triggeredBy: context.user.username\n",{"type":15,"tag":360,"props":5438,"children":5440},{"class":362,"line":5439},23,[5441],{"type":15,"tag":360,"props":5442,"children":5443},{"style":373},[5444],{"type":21,"value":498},{"type":15,"tag":360,"props":5446,"children":5448},{"class":362,"line":5447},24,[5449],{"type":15,"tag":360,"props":5450,"children":5451},{"style":373},[5452],{"type":21,"value":944},{"type":15,"tag":360,"props":5454,"children":5456},{"class":362,"line":5455},25,[5457,5461],{"type":15,"tag":360,"props":5458,"children":5459},{"style":367},[5460],{"type":21,"value":417},{"type":15,"tag":360,"props":5462,"children":5463},{"style":373},[5464],{"type":21,"value":422},{"type":15,"tag":360,"props":5466,"children":5468},{"class":362,"line":5467},26,[5469,5473,5478,5482],{"type":15,"tag":360,"props":5470,"children":5471},{"style":367},[5472],{"type":21,"value":431},{"type":15,"tag":360,"props":5474,"children":5475},{"style":373},[5476],{"type":21,"value":5477}," (recipients.",{"type":15,"tag":360,"props":5479,"children":5480},{"style":389},[5481],{"type":21,"value":441},{"type":15,"tag":360,"props":5483,"children":5484},{"style":373},[5485],{"type":21,"value":446},{"type":15,"tag":360,"props":5487,"children":5489},{"class":362,"line":5488},27,[5490,5494,5498,5502,5507,5512,5516],{"type":15,"tag":360,"props":5491,"children":5492},{"style":373},[5493],{"type":21,"value":677},{"type":15,"tag":360,"props":5495,"children":5496},{"style":389},[5497],{"type":21,"value":682},{"type":15,"tag":360,"props":5499,"children":5500},{"style":373},[5501],{"type":21,"value":397},{"type":15,"tag":360,"props":5503,"children":5504},{"style":400},[5505],{"type":21,"value":5506},"\"sendOneCampaignEmail\"",{"type":15,"tag":360,"props":5508,"children":5509},{"style":373},[5510],{"type":21,"value":5511},", recipients.",{"type":15,"tag":360,"props":5513,"children":5514},{"style":389},[5515],{"type":21,"value":474},{"type":15,"tag":360,"props":5517,"children":5518},{"style":373},[5519],{"type":21,"value":5520},"(), {\n",{"type":15,"tag":360,"props":5522,"children":5524},{"class":362,"line":5523},28,[5525],{"type":15,"tag":360,"props":5526,"children":5527},{"style":373},[5528],{"type":21,"value":5529},"            campaignId: campaignId\n",{"type":15,"tag":360,"props":5531,"children":5533},{"class":362,"line":5532},29,[5534],{"type":15,"tag":360,"props":5535,"children":5536},{"style":373},[5537],{"type":21,"value":5538},"        });\n",{"type":15,"tag":360,"props":5540,"children":5542},{"class":362,"line":5541},30,[5543],{"type":15,"tag":360,"props":5544,"children":5545},{"style":373},[5546],{"type":21,"value":498},{"type":15,"tag":360,"props":5548,"children":5550},{"class":362,"line":5549},31,[5551,5555,5559],{"type":15,"tag":360,"props":5552,"children":5553},{"style":373},[5554],{"type":21,"value":507},{"type":15,"tag":360,"props":5556,"children":5557},{"style":367},[5558],{"type":21,"value":512},{"type":15,"tag":360,"props":5560,"children":5561},{"style":373},[5562],{"type":21,"value":422},{"type":15,"tag":360,"props":5564,"children":5566},{"class":362,"line":5565},32,[5567,5572,5576],{"type":15,"tag":360,"props":5568,"children":5569},{"style":373},[5570],{"type":21,"value":5571},"    recipients.",{"type":15,"tag":360,"props":5573,"children":5574},{"style":389},[5575],{"type":21,"value":530},{"type":15,"tag":360,"props":5577,"children":5578},{"style":373},[5579],{"type":21,"value":479},{"type":15,"tag":360,"props":5581,"children":5583},{"class":362,"line":5582},33,[5584,5588,5592],{"type":15,"tag":360,"props":5585,"children":5586},{"style":373},[5587],{"type":21,"value":761},{"type":15,"tag":360,"props":5589,"children":5590},{"style":389},[5591],{"type":21,"value":766},{"type":15,"tag":360,"props":5593,"children":5594},{"style":373},[5595],{"type":21,"value":479},{"type":15,"tag":360,"props":5597,"children":5599},{"class":362,"line":5598},34,[5600],{"type":15,"tag":360,"props":5601,"children":5602},{"style":373},[5603],{"type":21,"value":543},{"type":15,"tag":360,"props":5605,"children":5607},{"class":362,"line":5606},35,[5608],{"type":15,"tag":360,"props":5609,"children":5610},{"emptyLinePlaceholder":839},[5611],{"type":21,"value":842},{"type":15,"tag":360,"props":5613,"children":5615},{"class":362,"line":5614},36,[5616,5620,5624],{"type":15,"tag":360,"props":5617,"children":5618},{"style":373},[5619],{"type":21,"value":1234},{"type":15,"tag":360,"props":5621,"children":5622},{"style":389},[5623],{"type":21,"value":4485},{"type":15,"tag":360,"props":5625,"children":5626},{"style":373},[5627],{"type":21,"value":905},{"type":15,"tag":360,"props":5629,"children":5631},{"class":362,"line":5630},37,[5632,5637],{"type":15,"tag":360,"props":5633,"children":5634},{"style":373},[5635],{"type":21,"value":5636},"    message: ",{"type":15,"tag":360,"props":5638,"children":5639},{"style":400},[5640],{"type":21,"value":5641},"\"Campaign queued for \"\n",{"type":15,"tag":360,"props":5643,"children":5645},{"class":362,"line":5644},38,[5646,5651,5655,5659,5663,5667,5671,5675,5679,5683,5688],{"type":15,"tag":360,"props":5647,"children":5648},{"style":367},[5649],{"type":21,"value":5650},"             +",{"type":15,"tag":360,"props":5652,"children":5653},{"style":373},[5654],{"type":21,"value":4796},{"type":15,"tag":360,"props":5656,"children":5657},{"style":389},[5658],{"type":21,"value":4801},{"type":15,"tag":360,"props":5660,"children":5661},{"style":373},[5662],{"type":21,"value":5074},{"type":15,"tag":360,"props":5664,"children":5665},{"style":389},[5666],{"type":21,"value":1256},{"type":15,"tag":360,"props":5668,"children":5669},{"style":373},[5670],{"type":21,"value":397},{"type":15,"tag":360,"props":5672,"children":5673},{"style":400},[5674],{"type":21,"value":1501},{"type":15,"tag":360,"props":5676,"children":5677},{"style":373},[5678],{"type":21,"value":3594},{"type":15,"tag":360,"props":5680,"children":5681},{"style":367},[5682],{"type":21,"value":2909},{"type":15,"tag":360,"props":5684,"children":5685},{"style":400},[5686],{"type":21,"value":5687}," \" recipients\"",{"type":15,"tag":360,"props":5689,"children":5690},{"style":373},[5691],{"type":21,"value":923},{"type":15,"tag":360,"props":5693,"children":5695},{"class":362,"line":5694},39,[5696,5701,5706],{"type":15,"tag":360,"props":5697,"children":5698},{"style":373},[5699],{"type":21,"value":5700},"    batchId: batch.",{"type":15,"tag":360,"props":5702,"children":5703},{"style":389},[5704],{"type":21,"value":5705},"getId",{"type":15,"tag":360,"props":5707,"children":5708},{"style":373},[5709],{"type":21,"value":5710},"()\n",{"type":15,"tag":360,"props":5712,"children":5714},{"class":362,"line":5713},40,[5715],{"type":15,"tag":360,"props":5716,"children":5717},{"style":373},[5718],{"type":21,"value":944},{"type":15,"tag":350,"props":5720,"children":5722},{"className":352,"code":5721,"language":354,"meta":7,"style":7},"// Action: \"sendOneCampaignEmail\"\n\nlet customer   = context.getRecord();\nlet campaignId = context.getParameter(\"campaignId\");\nlet campaign   = context.getRecord(\"campaign\", campaignId);\n\n// Idempotency: if we've already sent this one, skip it.\n// Re-runs (caused by retries or message redelivery) won't double-send.\nlet alreadySent = context.query(\n    \"select s from sentEmail s \" +\n    \"where s.campaignId = ${cid} and s.customerId = ${uid}\",\n    { cid: campaignId, uid: customer.get(\"id\") });\ntry {\n    if (alreadySent.hasNext()) {\n        return;   // already sent, nothing to do\n    }\n} finally {\n    alreadySent.close();\n}\n\ncontext.sendMail({\n    to:      customer.get(\"email\"),\n    subject: campaign.get(\"subject\"),\n    body:    context.renderTemplate(campaign.get(\"template\"), customer)\n});\n\ncontext.create(\"sentEmail\", {\n    campaignId: campaignId,\n    customerId: customer.get(\"id\"),\n    sentAt:     Date.now()\n});\n",[5723],{"type":15,"tag":254,"props":5724,"children":5725},{"__ignoreMap":7},[5726,5734,5741,5769,5804,5842,5849,5857,5865,5893,5905,5917,5941,5952,5973,5991,5998,6013,6029,6036,6043,6058,6082,6107,6141,6148,6155,6181,6189,6213,6229],{"type":15,"tag":360,"props":5727,"children":5728},{"class":362,"line":363},[5729],{"type":15,"tag":360,"props":5730,"children":5731},{"style":486},[5732],{"type":21,"value":5733},"// Action: \"sendOneCampaignEmail\"\n",{"type":15,"tag":360,"props":5735,"children":5736},{"class":362,"line":411},[5737],{"type":15,"tag":360,"props":5738,"children":5739},{"emptyLinePlaceholder":839},[5740],{"type":21,"value":842},{"type":15,"tag":360,"props":5742,"children":5743},{"class":362,"line":425},[5744,5748,5753,5757,5761,5765],{"type":15,"tag":360,"props":5745,"children":5746},{"style":367},[5747],{"type":21,"value":370},{"type":15,"tag":360,"props":5749,"children":5750},{"style":373},[5751],{"type":21,"value":5752}," customer   ",{"type":15,"tag":360,"props":5754,"children":5755},{"style":367},[5756],{"type":21,"value":381},{"type":15,"tag":360,"props":5758,"children":5759},{"style":373},[5760],{"type":21,"value":386},{"type":15,"tag":360,"props":5762,"children":5763},{"style":389},[5764],{"type":21,"value":1216},{"type":15,"tag":360,"props":5766,"children":5767},{"style":373},[5768],{"type":21,"value":479},{"type":15,"tag":360,"props":5770,"children":5771},{"class":362,"line":449},[5772,5776,5780,5784,5788,5792,5796,5800],{"type":15,"tag":360,"props":5773,"children":5774},{"style":367},[5775],{"type":21,"value":370},{"type":15,"tag":360,"props":5777,"children":5778},{"style":373},[5779],{"type":21,"value":5057},{"type":15,"tag":360,"props":5781,"children":5782},{"style":367},[5783],{"type":21,"value":381},{"type":15,"tag":360,"props":5785,"children":5786},{"style":373},[5787],{"type":21,"value":386},{"type":15,"tag":360,"props":5789,"children":5790},{"style":389},[5791],{"type":21,"value":2067},{"type":15,"tag":360,"props":5793,"children":5794},{"style":373},[5795],{"type":21,"value":397},{"type":15,"tag":360,"props":5797,"children":5798},{"style":400},[5799],{"type":21,"value":2119},{"type":15,"tag":360,"props":5801,"children":5802},{"style":373},[5803],{"type":21,"value":408},{"type":15,"tag":360,"props":5805,"children":5806},{"class":362,"line":482},[5807,5811,5816,5820,5824,5828,5832,5837],{"type":15,"tag":360,"props":5808,"children":5809},{"style":367},[5810],{"type":21,"value":370},{"type":15,"tag":360,"props":5812,"children":5813},{"style":373},[5814],{"type":21,"value":5815}," campaign   ",{"type":15,"tag":360,"props":5817,"children":5818},{"style":367},[5819],{"type":21,"value":381},{"type":15,"tag":360,"props":5821,"children":5822},{"style":373},[5823],{"type":21,"value":386},{"type":15,"tag":360,"props":5825,"children":5826},{"style":389},[5827],{"type":21,"value":1216},{"type":15,"tag":360,"props":5829,"children":5830},{"style":373},[5831],{"type":21,"value":397},{"type":15,"tag":360,"props":5833,"children":5834},{"style":400},[5835],{"type":21,"value":5836},"\"campaign\"",{"type":15,"tag":360,"props":5838,"children":5839},{"style":373},[5840],{"type":21,"value":5841},", campaignId);\n",{"type":15,"tag":360,"props":5843,"children":5844},{"class":362,"line":492},[5845],{"type":15,"tag":360,"props":5846,"children":5847},{"emptyLinePlaceholder":839},[5848],{"type":21,"value":842},{"type":15,"tag":360,"props":5850,"children":5851},{"class":362,"line":501},[5852],{"type":15,"tag":360,"props":5853,"children":5854},{"style":486},[5855],{"type":21,"value":5856},"// Idempotency: if we've already sent this one, skip it.\n",{"type":15,"tag":360,"props":5858,"children":5859},{"class":362,"line":519},[5860],{"type":15,"tag":360,"props":5861,"children":5862},{"style":486},[5863],{"type":21,"value":5864},"// Re-runs (caused by retries or message redelivery) won't double-send.\n",{"type":15,"tag":360,"props":5866,"children":5867},{"class":362,"line":537},[5868,5872,5877,5881,5885,5889],{"type":15,"tag":360,"props":5869,"children":5870},{"style":367},[5871],{"type":21,"value":370},{"type":15,"tag":360,"props":5873,"children":5874},{"style":373},[5875],{"type":21,"value":5876}," alreadySent ",{"type":15,"tag":360,"props":5878,"children":5879},{"style":367},[5880],{"type":21,"value":381},{"type":15,"tag":360,"props":5882,"children":5883},{"style":373},[5884],{"type":21,"value":386},{"type":15,"tag":360,"props":5886,"children":5887},{"style":389},[5888],{"type":21,"value":392},{"type":15,"tag":360,"props":5890,"children":5891},{"style":373},[5892],{"type":21,"value":5126},{"type":15,"tag":360,"props":5894,"children":5895},{"class":362,"line":773},[5896,5901],{"type":15,"tag":360,"props":5897,"children":5898},{"style":400},[5899],{"type":21,"value":5900},"    \"select s from sentEmail s \"",{"type":15,"tag":360,"props":5902,"children":5903},{"style":367},[5904],{"type":21,"value":5139},{"type":15,"tag":360,"props":5906,"children":5907},{"class":362,"line":1016},[5908,5913],{"type":15,"tag":360,"props":5909,"children":5910},{"style":400},[5911],{"type":21,"value":5912},"    \"where s.campaignId = ${cid} and s.customerId = ${uid}\"",{"type":15,"tag":360,"props":5914,"children":5915},{"style":373},[5916],{"type":21,"value":923},{"type":15,"tag":360,"props":5918,"children":5919},{"class":362,"line":1024},[5920,5925,5929,5933,5937],{"type":15,"tag":360,"props":5921,"children":5922},{"style":373},[5923],{"type":21,"value":5924},"    { cid: campaignId, uid: customer.",{"type":15,"tag":360,"props":5926,"children":5927},{"style":389},[5928],{"type":21,"value":1256},{"type":15,"tag":360,"props":5930,"children":5931},{"style":373},[5932],{"type":21,"value":397},{"type":15,"tag":360,"props":5934,"children":5935},{"style":400},[5936],{"type":21,"value":1967},{"type":15,"tag":360,"props":5938,"children":5939},{"style":373},[5940],{"type":21,"value":5189},{"type":15,"tag":360,"props":5942,"children":5943},{"class":362,"line":1040},[5944,5948],{"type":15,"tag":360,"props":5945,"children":5946},{"style":367},[5947],{"type":21,"value":417},{"type":15,"tag":360,"props":5949,"children":5950},{"style":373},[5951],{"type":21,"value":422},{"type":15,"tag":360,"props":5953,"children":5954},{"class":362,"line":1056},[5955,5960,5965,5969],{"type":15,"tag":360,"props":5956,"children":5957},{"style":367},[5958],{"type":21,"value":5959},"    if",{"type":15,"tag":360,"props":5961,"children":5962},{"style":373},[5963],{"type":21,"value":5964}," (alreadySent.",{"type":15,"tag":360,"props":5966,"children":5967},{"style":389},[5968],{"type":21,"value":441},{"type":15,"tag":360,"props":5970,"children":5971},{"style":373},[5972],{"type":21,"value":446},{"type":15,"tag":360,"props":5974,"children":5975},{"class":362,"line":1072},[5976,5981,5986],{"type":15,"tag":360,"props":5977,"children":5978},{"style":367},[5979],{"type":21,"value":5980},"        return",{"type":15,"tag":360,"props":5982,"children":5983},{"style":373},[5984],{"type":21,"value":5985},";   ",{"type":15,"tag":360,"props":5987,"children":5988},{"style":486},[5989],{"type":21,"value":5990},"// already sent, nothing to do\n",{"type":15,"tag":360,"props":5992,"children":5993},{"class":362,"line":5296},[5994],{"type":15,"tag":360,"props":5995,"children":5996},{"style":373},[5997],{"type":21,"value":498},{"type":15,"tag":360,"props":5999,"children":6000},{"class":362,"line":5319},[6001,6005,6009],{"type":15,"tag":360,"props":6002,"children":6003},{"style":373},[6004],{"type":21,"value":507},{"type":15,"tag":360,"props":6006,"children":6007},{"style":367},[6008],{"type":21,"value":512},{"type":15,"tag":360,"props":6010,"children":6011},{"style":373},[6012],{"type":21,"value":422},{"type":15,"tag":360,"props":6014,"children":6015},{"class":362,"line":5336},[6016,6021,6025],{"type":15,"tag":360,"props":6017,"children":6018},{"style":373},[6019],{"type":21,"value":6020},"    alreadySent.",{"type":15,"tag":360,"props":6022,"children":6023},{"style":389},[6024],{"type":21,"value":530},{"type":15,"tag":360,"props":6026,"children":6027},{"style":373},[6028],{"type":21,"value":479},{"type":15,"tag":360,"props":6030,"children":6031},{"class":362,"line":5359},[6032],{"type":15,"tag":360,"props":6033,"children":6034},{"style":373},[6035],{"type":21,"value":543},{"type":15,"tag":360,"props":6037,"children":6038},{"class":362,"line":5413},[6039],{"type":15,"tag":360,"props":6040,"children":6041},{"emptyLinePlaceholder":839},[6042],{"type":21,"value":842},{"type":15,"tag":360,"props":6044,"children":6045},{"class":362,"line":5421},[6046,6050,6054],{"type":15,"tag":360,"props":6047,"children":6048},{"style":373},[6049],{"type":21,"value":1234},{"type":15,"tag":360,"props":6051,"children":6052},{"style":389},[6053],{"type":21,"value":1239},{"type":15,"tag":360,"props":6055,"children":6056},{"style":373},[6057],{"type":21,"value":905},{"type":15,"tag":360,"props":6059,"children":6060},{"class":362,"line":5430},[6061,6066,6070,6074,6078],{"type":15,"tag":360,"props":6062,"children":6063},{"style":373},[6064],{"type":21,"value":6065},"    to:      customer.",{"type":15,"tag":360,"props":6067,"children":6068},{"style":389},[6069],{"type":21,"value":1256},{"type":15,"tag":360,"props":6071,"children":6072},{"style":373},[6073],{"type":21,"value":397},{"type":15,"tag":360,"props":6075,"children":6076},{"style":400},[6077],{"type":21,"value":1265},{"type":15,"tag":360,"props":6079,"children":6080},{"style":373},[6081],{"type":21,"value":1270},{"type":15,"tag":360,"props":6083,"children":6084},{"class":362,"line":5439},[6085,6090,6094,6098,6103],{"type":15,"tag":360,"props":6086,"children":6087},{"style":373},[6088],{"type":21,"value":6089},"    subject: campaign.",{"type":15,"tag":360,"props":6091,"children":6092},{"style":389},[6093],{"type":21,"value":1256},{"type":15,"tag":360,"props":6095,"children":6096},{"style":373},[6097],{"type":21,"value":397},{"type":15,"tag":360,"props":6099,"children":6100},{"style":400},[6101],{"type":21,"value":6102},"\"subject\"",{"type":15,"tag":360,"props":6104,"children":6105},{"style":373},[6106],{"type":21,"value":1270},{"type":15,"tag":360,"props":6108,"children":6109},{"class":362,"line":5447},[6110,6114,6118,6123,6127,6131,6136],{"type":15,"tag":360,"props":6111,"children":6112},{"style":373},[6113],{"type":21,"value":1295},{"type":15,"tag":360,"props":6115,"children":6116},{"style":389},[6117],{"type":21,"value":1300},{"type":15,"tag":360,"props":6119,"children":6120},{"style":373},[6121],{"type":21,"value":6122},"(campaign.",{"type":15,"tag":360,"props":6124,"children":6125},{"style":389},[6126],{"type":21,"value":1256},{"type":15,"tag":360,"props":6128,"children":6129},{"style":373},[6130],{"type":21,"value":397},{"type":15,"tag":360,"props":6132,"children":6133},{"style":400},[6134],{"type":21,"value":6135},"\"template\"",{"type":15,"tag":360,"props":6137,"children":6138},{"style":373},[6139],{"type":21,"value":6140},"), customer)\n",{"type":15,"tag":360,"props":6142,"children":6143},{"class":362,"line":5455},[6144],{"type":15,"tag":360,"props":6145,"children":6146},{"style":373},[6147],{"type":21,"value":944},{"type":15,"tag":360,"props":6149,"children":6150},{"class":362,"line":5467},[6151],{"type":15,"tag":360,"props":6152,"children":6153},{"emptyLinePlaceholder":839},[6154],{"type":21,"value":842},{"type":15,"tag":360,"props":6156,"children":6157},{"class":362,"line":5488},[6158,6162,6167,6171,6176],{"type":15,"tag":360,"props":6159,"children":6160},{"style":373},[6161],{"type":21,"value":1234},{"type":15,"tag":360,"props":6163,"children":6164},{"style":389},[6165],{"type":21,"value":6166},"create",{"type":15,"tag":360,"props":6168,"children":6169},{"style":373},[6170],{"type":21,"value":397},{"type":15,"tag":360,"props":6172,"children":6173},{"style":400},[6174],{"type":21,"value":6175},"\"sentEmail\"",{"type":15,"tag":360,"props":6177,"children":6178},{"style":373},[6179],{"type":21,"value":6180},", {\n",{"type":15,"tag":360,"props":6182,"children":6183},{"class":362,"line":5523},[6184],{"type":15,"tag":360,"props":6185,"children":6186},{"style":373},[6187],{"type":21,"value":6188},"    campaignId: campaignId,\n",{"type":15,"tag":360,"props":6190,"children":6191},{"class":362,"line":5532},[6192,6197,6201,6205,6209],{"type":15,"tag":360,"props":6193,"children":6194},{"style":373},[6195],{"type":21,"value":6196},"    customerId: customer.",{"type":15,"tag":360,"props":6198,"children":6199},{"style":389},[6200],{"type":21,"value":1256},{"type":15,"tag":360,"props":6202,"children":6203},{"style":373},[6204],{"type":21,"value":397},{"type":15,"tag":360,"props":6206,"children":6207},{"style":400},[6208],{"type":21,"value":1967},{"type":15,"tag":360,"props":6210,"children":6211},{"style":373},[6212],{"type":21,"value":1270},{"type":15,"tag":360,"props":6214,"children":6215},{"class":362,"line":5541},[6216,6221,6225],{"type":15,"tag":360,"props":6217,"children":6218},{"style":373},[6219],{"type":21,"value":6220},"    sentAt:     Date.",{"type":15,"tag":360,"props":6222,"children":6223},{"style":389},[6224],{"type":21,"value":2899},{"type":15,"tag":360,"props":6226,"children":6227},{"style":373},[6228],{"type":21,"value":5710},{"type":15,"tag":360,"props":6230,"children":6231},{"class":362,"line":5549},[6232],{"type":15,"tag":360,"props":6233,"children":6234},{"style":373},[6235],{"type":21,"value":944},{"type":15,"tag":350,"props":6237,"children":6239},{"className":352,"code":6238,"language":354,"meta":7,"style":7},"// Action: \"campaignFinishedNotification\"\n\nlet campaignId  = context.getParameter(\"campaignId\");\nlet triggeredBy = context.getParameter(\"triggeredBy\");\nlet succeeded   = context.getInput(\"succeededJobs\");\nlet failed      = context.getInput(\"failedJobs\");\nlet total       = context.getInput(\"totalJobs\");\n\ncontext.sendMail({\n    to:      triggeredBy + \"@example.com\",\n    subject: \"Campaign \" + campaignId + \" complete\",\n    body:    \"Sent: \" + succeeded + \" / \" + total\n             + \", Bounced: \" + failed\n});\n",[6240],{"type":15,"tag":254,"props":6241,"children":6242},{"__ignoreMap":7},[6243,6251,6258,6293,6328,6363,6399,6435,6442,6457,6478,6512,6552,6573],{"type":15,"tag":360,"props":6244,"children":6245},{"class":362,"line":363},[6246],{"type":15,"tag":360,"props":6247,"children":6248},{"style":486},[6249],{"type":21,"value":6250},"// Action: \"campaignFinishedNotification\"\n",{"type":15,"tag":360,"props":6252,"children":6253},{"class":362,"line":411},[6254],{"type":15,"tag":360,"props":6255,"children":6256},{"emptyLinePlaceholder":839},[6257],{"type":21,"value":842},{"type":15,"tag":360,"props":6259,"children":6260},{"class":362,"line":425},[6261,6265,6269,6273,6277,6281,6285,6289],{"type":15,"tag":360,"props":6262,"children":6263},{"style":367},[6264],{"type":21,"value":370},{"type":15,"tag":360,"props":6266,"children":6267},{"style":373},[6268],{"type":21,"value":2098},{"type":15,"tag":360,"props":6270,"children":6271},{"style":367},[6272],{"type":21,"value":381},{"type":15,"tag":360,"props":6274,"children":6275},{"style":373},[6276],{"type":21,"value":386},{"type":15,"tag":360,"props":6278,"children":6279},{"style":389},[6280],{"type":21,"value":2067},{"type":15,"tag":360,"props":6282,"children":6283},{"style":373},[6284],{"type":21,"value":397},{"type":15,"tag":360,"props":6286,"children":6287},{"style":400},[6288],{"type":21,"value":2119},{"type":15,"tag":360,"props":6290,"children":6291},{"style":373},[6292],{"type":21,"value":408},{"type":15,"tag":360,"props":6294,"children":6295},{"class":362,"line":449},[6296,6300,6304,6308,6312,6316,6320,6324],{"type":15,"tag":360,"props":6297,"children":6298},{"style":367},[6299],{"type":21,"value":370},{"type":15,"tag":360,"props":6301,"children":6302},{"style":373},[6303],{"type":21,"value":2054},{"type":15,"tag":360,"props":6305,"children":6306},{"style":367},[6307],{"type":21,"value":381},{"type":15,"tag":360,"props":6309,"children":6310},{"style":373},[6311],{"type":21,"value":386},{"type":15,"tag":360,"props":6313,"children":6314},{"style":389},[6315],{"type":21,"value":2067},{"type":15,"tag":360,"props":6317,"children":6318},{"style":373},[6319],{"type":21,"value":397},{"type":15,"tag":360,"props":6321,"children":6322},{"style":400},[6323],{"type":21,"value":2076},{"type":15,"tag":360,"props":6325,"children":6326},{"style":373},[6327],{"type":21,"value":408},{"type":15,"tag":360,"props":6329,"children":6330},{"class":362,"line":482},[6331,6335,6339,6343,6347,6351,6355,6359],{"type":15,"tag":360,"props":6332,"children":6333},{"style":367},[6334],{"type":21,"value":370},{"type":15,"tag":360,"props":6336,"children":6337},{"style":373},[6338],{"type":21,"value":2012},{"type":15,"tag":360,"props":6340,"children":6341},{"style":367},[6342],{"type":21,"value":381},{"type":15,"tag":360,"props":6344,"children":6345},{"style":373},[6346],{"type":21,"value":386},{"type":15,"tag":360,"props":6348,"children":6349},{"style":389},[6350],{"type":21,"value":1444},{"type":15,"tag":360,"props":6352,"children":6353},{"style":373},[6354],{"type":21,"value":397},{"type":15,"tag":360,"props":6356,"children":6357},{"style":400},[6358],{"type":21,"value":1453},{"type":15,"tag":360,"props":6360,"children":6361},{"style":373},[6362],{"type":21,"value":408},{"type":15,"tag":360,"props":6364,"children":6365},{"class":362,"line":492},[6366,6370,6375,6379,6383,6387,6391,6395],{"type":15,"tag":360,"props":6367,"children":6368},{"style":367},[6369],{"type":21,"value":370},{"type":15,"tag":360,"props":6371,"children":6372},{"style":373},[6373],{"type":21,"value":6374}," failed      ",{"type":15,"tag":360,"props":6376,"children":6377},{"style":367},[6378],{"type":21,"value":381},{"type":15,"tag":360,"props":6380,"children":6381},{"style":373},[6382],{"type":21,"value":386},{"type":15,"tag":360,"props":6384,"children":6385},{"style":389},[6386],{"type":21,"value":1444},{"type":15,"tag":360,"props":6388,"children":6389},{"style":373},[6390],{"type":21,"value":397},{"type":15,"tag":360,"props":6392,"children":6393},{"style":400},[6394],{"type":21,"value":1477},{"type":15,"tag":360,"props":6396,"children":6397},{"style":373},[6398],{"type":21,"value":408},{"type":15,"tag":360,"props":6400,"children":6401},{"class":362,"line":501},[6402,6406,6411,6415,6419,6423,6427,6431],{"type":15,"tag":360,"props":6403,"children":6404},{"style":367},[6405],{"type":21,"value":370},{"type":15,"tag":360,"props":6407,"children":6408},{"style":373},[6409],{"type":21,"value":6410}," total       ",{"type":15,"tag":360,"props":6412,"children":6413},{"style":367},[6414],{"type":21,"value":381},{"type":15,"tag":360,"props":6416,"children":6417},{"style":373},[6418],{"type":21,"value":386},{"type":15,"tag":360,"props":6420,"children":6421},{"style":389},[6422],{"type":21,"value":1444},{"type":15,"tag":360,"props":6424,"children":6425},{"style":373},[6426],{"type":21,"value":397},{"type":15,"tag":360,"props":6428,"children":6429},{"style":400},[6430],{"type":21,"value":1501},{"type":15,"tag":360,"props":6432,"children":6433},{"style":373},[6434],{"type":21,"value":408},{"type":15,"tag":360,"props":6436,"children":6437},{"class":362,"line":519},[6438],{"type":15,"tag":360,"props":6439,"children":6440},{"emptyLinePlaceholder":839},[6441],{"type":21,"value":842},{"type":15,"tag":360,"props":6443,"children":6444},{"class":362,"line":537},[6445,6449,6453],{"type":15,"tag":360,"props":6446,"children":6447},{"style":373},[6448],{"type":21,"value":1234},{"type":15,"tag":360,"props":6450,"children":6451},{"style":389},[6452],{"type":21,"value":1239},{"type":15,"tag":360,"props":6454,"children":6455},{"style":373},[6456],{"type":21,"value":905},{"type":15,"tag":360,"props":6458,"children":6459},{"class":362,"line":773},[6460,6465,6469,6474],{"type":15,"tag":360,"props":6461,"children":6462},{"style":373},[6463],{"type":21,"value":6464},"    to:      triggeredBy ",{"type":15,"tag":360,"props":6466,"children":6467},{"style":367},[6468],{"type":21,"value":2909},{"type":15,"tag":360,"props":6470,"children":6471},{"style":400},[6472],{"type":21,"value":6473}," \"@example.com\"",{"type":15,"tag":360,"props":6475,"children":6476},{"style":373},[6477],{"type":21,"value":923},{"type":15,"tag":360,"props":6479,"children":6480},{"class":362,"line":1016},[6481,6485,6490,6495,6499,6503,6508],{"type":15,"tag":360,"props":6482,"children":6483},{"style":373},[6484],{"type":21,"value":1278},{"type":15,"tag":360,"props":6486,"children":6487},{"style":400},[6488],{"type":21,"value":6489},"\"Campaign \"",{"type":15,"tag":360,"props":6491,"children":6492},{"style":367},[6493],{"type":21,"value":6494}," +",{"type":15,"tag":360,"props":6496,"children":6497},{"style":373},[6498],{"type":21,"value":5057},{"type":15,"tag":360,"props":6500,"children":6501},{"style":367},[6502],{"type":21,"value":2909},{"type":15,"tag":360,"props":6504,"children":6505},{"style":400},[6506],{"type":21,"value":6507}," \" complete\"",{"type":15,"tag":360,"props":6509,"children":6510},{"style":373},[6511],{"type":21,"value":923},{"type":15,"tag":360,"props":6513,"children":6514},{"class":362,"line":1024},[6515,6520,6525,6529,6534,6538,6543,6547],{"type":15,"tag":360,"props":6516,"children":6517},{"style":373},[6518],{"type":21,"value":6519},"    body:    ",{"type":15,"tag":360,"props":6521,"children":6522},{"style":400},[6523],{"type":21,"value":6524},"\"Sent: \"",{"type":15,"tag":360,"props":6526,"children":6527},{"style":367},[6528],{"type":21,"value":6494},{"type":15,"tag":360,"props":6530,"children":6531},{"style":373},[6532],{"type":21,"value":6533}," succeeded ",{"type":15,"tag":360,"props":6535,"children":6536},{"style":367},[6537],{"type":21,"value":2909},{"type":15,"tag":360,"props":6539,"children":6540},{"style":400},[6541],{"type":21,"value":6542}," \" / \"",{"type":15,"tag":360,"props":6544,"children":6545},{"style":367},[6546],{"type":21,"value":6494},{"type":15,"tag":360,"props":6548,"children":6549},{"style":373},[6550],{"type":21,"value":6551}," total\n",{"type":15,"tag":360,"props":6553,"children":6554},{"class":362,"line":1040},[6555,6559,6564,6568],{"type":15,"tag":360,"props":6556,"children":6557},{"style":367},[6558],{"type":21,"value":5650},{"type":15,"tag":360,"props":6560,"children":6561},{"style":400},[6562],{"type":21,"value":6563}," \", Bounced: \"",{"type":15,"tag":360,"props":6565,"children":6566},{"style":367},[6567],{"type":21,"value":6494},{"type":15,"tag":360,"props":6569,"children":6570},{"style":373},[6571],{"type":21,"value":6572}," failed\n",{"type":15,"tag":360,"props":6574,"children":6575},{"class":362,"line":1056},[6576],{"type":15,"tag":360,"props":6577,"children":6578},{"style":373},[6579],{"type":21,"value":944},{"type":15,"tag":24,"props":6581,"children":6582},{},[6583],{"type":21,"value":6584},"What this gives you:",{"type":15,"tag":38,"props":6586,"children":6587},{},[6588,6598,6608,6618],{"type":15,"tag":42,"props":6589,"children":6590},{},[6591,6596],{"type":15,"tag":30,"props":6592,"children":6593},{},[6594],{"type":21,"value":6595},"Instant UI response.",{"type":21,"value":6597}," The user sees \"Campaign queued for 80,000 recipients\" within milliseconds.",{"type":15,"tag":42,"props":6599,"children":6600},{},[6601,6606],{"type":15,"tag":30,"props":6602,"children":6603},{},[6604],{"type":21,"value":6605},"Throttled SMTP load.",{"type":21,"value":6607}," No more than 50 emails in flight at once.",{"type":15,"tag":42,"props":6609,"children":6610},{},[6611,6616],{"type":15,"tag":30,"props":6612,"children":6613},{},[6614],{"type":21,"value":6615},"Bounce protection.",{"type":21,"value":6617}," If more than 5% of emails fail (e.g. SMTP went down), the batch aborts and an alert fires.",{"type":15,"tag":42,"props":6619,"children":6620},{},[6621,6626,6628,6634],{"type":15,"tag":30,"props":6622,"children":6623},{},[6624],{"type":21,"value":6625},"No duplicate sends.",{"type":21,"value":6627}," The ",{"type":15,"tag":254,"props":6629,"children":6631},{"className":6630},[],[6632],{"type":21,"value":6633},"alreadySent",{"type":21,"value":6635}," check makes the child idempotent — perfect for the platform's at-least-once delivery model.",{"type":15,"tag":805,"props":6637,"children":6638},{},[],{"type":15,"tag":325,"props":6640,"children":6642},{"id":6641},"use-case-2-nightly-product-sync-with-rate-limited-api",[6643],{"type":21,"value":6644},"Use Case 2: Nightly Product Sync With Rate-Limited API",{"type":15,"tag":24,"props":6646,"children":6647},{},[6648,6652],{"type":15,"tag":30,"props":6649,"children":6650},{},[6651],{"type":21,"value":5021},{"type":21,"value":6653}," Every night at 2am, sync 5,000 products with Stripe. Stripe's rate limit is 100 requests/second, so we need to throttle.",{"type":15,"tag":350,"props":6655,"children":6657},{"className":352,"code":6656,"language":354,"meta":7,"style":7},"// Action: \"nightlyStripeSync\" — triggered by SCHEDULED rule\n\nlet products = context.query(\"select p from product p where p.active = true\");\n\nlet batch = context.createBatch({\n    onSuccess:        \"stripeSyncCompleted\",\n    onError:          \"stripeSyncFailed\",\n    results:          \"FAILURES_ONLY\",\n    maxConcurrent:    20,                    // ~20 req/s — well under Stripe's limit\n    failureThreshold: 0.02,                  // 2% — Stripe is reliable\n    deadlineMs:       Date.now() + 2 * 60 * 60 * 1000,\n    context: {\n        runDate: new Date().toISOString().slice(0, 10),\n        cron:    \"nightly-stripe-sync\"\n    }\n});\ntry {\n    while (products.hasNext()) {\n        batch.add(\"syncOneProductToStripe\", products.next(), null);\n    }\n} finally {\n    products.close();\n    batch.seal();\n}\n",[6658],{"type":15,"tag":254,"props":6659,"children":6660},{"__ignoreMap":7},[6661,6669,6676,6712,6719,6746,6763,6780,6796,6819,6841,6894,6901,6957,6970,6977,6984,6995,7014,7054,7061,7076,7091,7106],{"type":15,"tag":360,"props":6662,"children":6663},{"class":362,"line":363},[6664],{"type":15,"tag":360,"props":6665,"children":6666},{"style":486},[6667],{"type":21,"value":6668},"// Action: \"nightlyStripeSync\" — triggered by SCHEDULED rule\n",{"type":15,"tag":360,"props":6670,"children":6671},{"class":362,"line":411},[6672],{"type":15,"tag":360,"props":6673,"children":6674},{"emptyLinePlaceholder":839},[6675],{"type":21,"value":842},{"type":15,"tag":360,"props":6677,"children":6678},{"class":362,"line":425},[6679,6683,6687,6691,6695,6699,6703,6708],{"type":15,"tag":360,"props":6680,"children":6681},{"style":367},[6682],{"type":21,"value":370},{"type":15,"tag":360,"props":6684,"children":6685},{"style":373},[6686],{"type":21,"value":3039},{"type":15,"tag":360,"props":6688,"children":6689},{"style":367},[6690],{"type":21,"value":381},{"type":15,"tag":360,"props":6692,"children":6693},{"style":373},[6694],{"type":21,"value":386},{"type":15,"tag":360,"props":6696,"children":6697},{"style":389},[6698],{"type":21,"value":392},{"type":15,"tag":360,"props":6700,"children":6701},{"style":373},[6702],{"type":21,"value":397},{"type":15,"tag":360,"props":6704,"children":6705},{"style":400},[6706],{"type":21,"value":6707},"\"select p from product p where p.active = true\"",{"type":15,"tag":360,"props":6709,"children":6710},{"style":373},[6711],{"type":21,"value":408},{"type":15,"tag":360,"props":6713,"children":6714},{"class":362,"line":449},[6715],{"type":15,"tag":360,"props":6716,"children":6717},{"emptyLinePlaceholder":839},[6718],{"type":21,"value":842},{"type":15,"tag":360,"props":6720,"children":6721},{"class":362,"line":482},[6722,6726,6730,6734,6738,6742],{"type":15,"tag":360,"props":6723,"children":6724},{"style":367},[6725],{"type":21,"value":370},{"type":15,"tag":360,"props":6727,"children":6728},{"style":373},[6729],{"type":21,"value":611},{"type":15,"tag":360,"props":6731,"children":6732},{"style":367},[6733],{"type":21,"value":381},{"type":15,"tag":360,"props":6735,"children":6736},{"style":373},[6737],{"type":21,"value":386},{"type":15,"tag":360,"props":6739,"children":6740},{"style":389},[6741],{"type":21,"value":259},{"type":15,"tag":360,"props":6743,"children":6744},{"style":373},[6745],{"type":21,"value":905},{"type":15,"tag":360,"props":6747,"children":6748},{"class":362,"line":492},[6749,6754,6759],{"type":15,"tag":360,"props":6750,"children":6751},{"style":373},[6752],{"type":21,"value":6753},"    onSuccess:        ",{"type":15,"tag":360,"props":6755,"children":6756},{"style":400},[6757],{"type":21,"value":6758},"\"stripeSyncCompleted\"",{"type":15,"tag":360,"props":6760,"children":6761},{"style":373},[6762],{"type":21,"value":923},{"type":15,"tag":360,"props":6764,"children":6765},{"class":362,"line":501},[6766,6771,6776],{"type":15,"tag":360,"props":6767,"children":6768},{"style":373},[6769],{"type":21,"value":6770},"    onError:          ",{"type":15,"tag":360,"props":6772,"children":6773},{"style":400},[6774],{"type":21,"value":6775},"\"stripeSyncFailed\"",{"type":15,"tag":360,"props":6777,"children":6778},{"style":373},[6779],{"type":21,"value":923},{"type":15,"tag":360,"props":6781,"children":6782},{"class":362,"line":519},[6783,6788,6792],{"type":15,"tag":360,"props":6784,"children":6785},{"style":373},[6786],{"type":21,"value":6787},"    results:          ",{"type":15,"tag":360,"props":6789,"children":6790},{"style":400},[6791],{"type":21,"value":3503},{"type":15,"tag":360,"props":6793,"children":6794},{"style":373},[6795],{"type":21,"value":923},{"type":15,"tag":360,"props":6797,"children":6798},{"class":362,"line":537},[6799,6804,6809,6814],{"type":15,"tag":360,"props":6800,"children":6801},{"style":373},[6802],{"type":21,"value":6803},"    maxConcurrent:    ",{"type":15,"tag":360,"props":6805,"children":6806},{"style":708},[6807],{"type":21,"value":6808},"20",{"type":15,"tag":360,"props":6810,"children":6811},{"style":373},[6812],{"type":21,"value":6813},",                    ",{"type":15,"tag":360,"props":6815,"children":6816},{"style":486},[6817],{"type":21,"value":6818},"// ~20 req/s — well under Stripe's limit\n",{"type":15,"tag":360,"props":6820,"children":6821},{"class":362,"line":773},[6822,6827,6832,6836],{"type":15,"tag":360,"props":6823,"children":6824},{"style":373},[6825],{"type":21,"value":6826},"    failureThreshold: ",{"type":15,"tag":360,"props":6828,"children":6829},{"style":708},[6830],{"type":21,"value":6831},"0.02",{"type":15,"tag":360,"props":6833,"children":6834},{"style":373},[6835],{"type":21,"value":5351},{"type":15,"tag":360,"props":6837,"children":6838},{"style":486},[6839],{"type":21,"value":6840},"// 2% — Stripe is reliable\n",{"type":15,"tag":360,"props":6842,"children":6843},{"class":362,"line":1016},[6844,6849,6853,6857,6861,6866,6870,6874,6878,6882,6886,6890],{"type":15,"tag":360,"props":6845,"children":6846},{"style":373},[6847],{"type":21,"value":6848},"    deadlineMs:       Date.",{"type":15,"tag":360,"props":6850,"children":6851},{"style":389},[6852],{"type":21,"value":2899},{"type":15,"tag":360,"props":6854,"children":6855},{"style":373},[6856],{"type":21,"value":2904},{"type":15,"tag":360,"props":6858,"children":6859},{"style":367},[6860],{"type":21,"value":2909},{"type":15,"tag":360,"props":6862,"children":6863},{"style":708},[6864],{"type":21,"value":6865}," 2",{"type":15,"tag":360,"props":6867,"children":6868},{"style":367},[6869],{"type":21,"value":2919},{"type":15,"tag":360,"props":6871,"children":6872},{"style":708},[6873],{"type":21,"value":2924},{"type":15,"tag":360,"props":6875,"children":6876},{"style":367},[6877],{"type":21,"value":2919},{"type":15,"tag":360,"props":6879,"children":6880},{"style":708},[6881],{"type":21,"value":2924},{"type":15,"tag":360,"props":6883,"children":6884},{"style":367},[6885],{"type":21,"value":2919},{"type":15,"tag":360,"props":6887,"children":6888},{"style":708},[6889],{"type":21,"value":2933},{"type":15,"tag":360,"props":6891,"children":6892},{"style":373},[6893],{"type":21,"value":923},{"type":15,"tag":360,"props":6895,"children":6896},{"class":362,"line":1024},[6897],{"type":15,"tag":360,"props":6898,"children":6899},{"style":373},[6900],{"type":21,"value":1938},{"type":15,"tag":360,"props":6902,"children":6903},{"class":362,"line":1040},[6904,6909,6914,6919,6923,6928,6932,6937,6941,6945,6949,6953],{"type":15,"tag":360,"props":6905,"children":6906},{"style":373},[6907],{"type":21,"value":6908},"        runDate: ",{"type":15,"tag":360,"props":6910,"children":6911},{"style":367},[6912],{"type":21,"value":6913},"new",{"type":15,"tag":360,"props":6915,"children":6916},{"style":389},[6917],{"type":21,"value":6918}," Date",{"type":15,"tag":360,"props":6920,"children":6921},{"style":373},[6922],{"type":21,"value":5074},{"type":15,"tag":360,"props":6924,"children":6925},{"style":389},[6926],{"type":21,"value":6927},"toISOString",{"type":15,"tag":360,"props":6929,"children":6930},{"style":373},[6931],{"type":21,"value":5074},{"type":15,"tag":360,"props":6933,"children":6934},{"style":389},[6935],{"type":21,"value":6936},"slice",{"type":15,"tag":360,"props":6938,"children":6939},{"style":373},[6940],{"type":21,"value":397},{"type":15,"tag":360,"props":6942,"children":6943},{"style":708},[6944],{"type":21,"value":4352},{"type":15,"tag":360,"props":6946,"children":6947},{"style":373},[6948],{"type":21,"value":1348},{"type":15,"tag":360,"props":6950,"children":6951},{"style":708},[6952],{"type":21,"value":3137},{"type":15,"tag":360,"props":6954,"children":6955},{"style":373},[6956],{"type":21,"value":1270},{"type":15,"tag":360,"props":6958,"children":6959},{"class":362,"line":1056},[6960,6965],{"type":15,"tag":360,"props":6961,"children":6962},{"style":373},[6963],{"type":21,"value":6964},"        cron:    ",{"type":15,"tag":360,"props":6966,"children":6967},{"style":400},[6968],{"type":21,"value":6969},"\"nightly-stripe-sync\"\n",{"type":15,"tag":360,"props":6971,"children":6972},{"class":362,"line":1072},[6973],{"type":15,"tag":360,"props":6974,"children":6975},{"style":373},[6976],{"type":21,"value":498},{"type":15,"tag":360,"props":6978,"children":6979},{"class":362,"line":5296},[6980],{"type":15,"tag":360,"props":6981,"children":6982},{"style":373},[6983],{"type":21,"value":944},{"type":15,"tag":360,"props":6985,"children":6986},{"class":362,"line":5319},[6987,6991],{"type":15,"tag":360,"props":6988,"children":6989},{"style":367},[6990],{"type":21,"value":417},{"type":15,"tag":360,"props":6992,"children":6993},{"style":373},[6994],{"type":21,"value":422},{"type":15,"tag":360,"props":6996,"children":6997},{"class":362,"line":5336},[6998,7002,7006,7010],{"type":15,"tag":360,"props":6999,"children":7000},{"style":367},[7001],{"type":21,"value":431},{"type":15,"tag":360,"props":7003,"children":7004},{"style":373},[7005],{"type":21,"value":3172},{"type":15,"tag":360,"props":7007,"children":7008},{"style":389},[7009],{"type":21,"value":441},{"type":15,"tag":360,"props":7011,"children":7012},{"style":373},[7013],{"type":21,"value":446},{"type":15,"tag":360,"props":7015,"children":7016},{"class":362,"line":5359},[7017,7021,7025,7029,7034,7038,7042,7046,7050],{"type":15,"tag":360,"props":7018,"children":7019},{"style":373},[7020],{"type":21,"value":677},{"type":15,"tag":360,"props":7022,"children":7023},{"style":389},[7024],{"type":21,"value":682},{"type":15,"tag":360,"props":7026,"children":7027},{"style":373},[7028],{"type":21,"value":397},{"type":15,"tag":360,"props":7030,"children":7031},{"style":400},[7032],{"type":21,"value":7033},"\"syncOneProductToStripe\"",{"type":15,"tag":360,"props":7035,"children":7036},{"style":373},[7037],{"type":21,"value":3205},{"type":15,"tag":360,"props":7039,"children":7040},{"style":389},[7041],{"type":21,"value":474},{"type":15,"tag":360,"props":7043,"children":7044},{"style":373},[7045],{"type":21,"value":705},{"type":15,"tag":360,"props":7047,"children":7048},{"style":708},[7049],{"type":21,"value":711},{"type":15,"tag":360,"props":7051,"children":7052},{"style":373},[7053],{"type":21,"value":408},{"type":15,"tag":360,"props":7055,"children":7056},{"class":362,"line":5413},[7057],{"type":15,"tag":360,"props":7058,"children":7059},{"style":373},[7060],{"type":21,"value":498},{"type":15,"tag":360,"props":7062,"children":7063},{"class":362,"line":5421},[7064,7068,7072],{"type":15,"tag":360,"props":7065,"children":7066},{"style":373},[7067],{"type":21,"value":507},{"type":15,"tag":360,"props":7069,"children":7070},{"style":367},[7071],{"type":21,"value":512},{"type":15,"tag":360,"props":7073,"children":7074},{"style":373},[7075],{"type":21,"value":422},{"type":15,"tag":360,"props":7077,"children":7078},{"class":362,"line":5430},[7079,7083,7087],{"type":15,"tag":360,"props":7080,"children":7081},{"style":373},[7082],{"type":21,"value":3251},{"type":15,"tag":360,"props":7084,"children":7085},{"style":389},[7086],{"type":21,"value":530},{"type":15,"tag":360,"props":7088,"children":7089},{"style":373},[7090],{"type":21,"value":479},{"type":15,"tag":360,"props":7092,"children":7093},{"class":362,"line":5439},[7094,7098,7102],{"type":15,"tag":360,"props":7095,"children":7096},{"style":373},[7097],{"type":21,"value":761},{"type":15,"tag":360,"props":7099,"children":7100},{"style":389},[7101],{"type":21,"value":766},{"type":15,"tag":360,"props":7103,"children":7104},{"style":373},[7105],{"type":21,"value":479},{"type":15,"tag":360,"props":7107,"children":7108},{"class":362,"line":5447},[7109],{"type":15,"tag":360,"props":7110,"children":7111},{"style":373},[7112],{"type":21,"value":543},{"type":15,"tag":350,"props":7114,"children":7116},{"className":352,"code":7115,"language":354,"meta":7,"style":7},"// Action: \"syncOneProductToStripe\"\n\nlet product = context.getRecord();\nlet stripeApiKey = context.getConfig(\"stripe_api_key\");\n\nlet response = context.httpRequest({\n    method: \"POST\",\n    url:    \"https://api.stripe.com/v1/products/\" + product.get(\"stripeId\"),\n    headers: { \"Authorization\": \"Bearer \" + stripeApiKey },\n    body: {\n        name:        product.get(\"name\"),\n        description: product.get(\"description\"),\n        metadata: { internalId: product.get(\"id\") }\n    }\n});\n\nif (response.statusCode === 429) {\n    // Stripe is telling us to slow down. Throw to trigger retry.\n    throw new Error(\"Stripe rate limit hit, will retry\");\n}\n\nif (response.statusCode >= 400) {\n    throw new Error(\"Stripe error \" + response.statusCode + \": \" + response.body);\n}\n\nproduct.set(\"lastStripeSync\", Date.now());\ncontext.update(product);\n",[7117],{"type":15,"tag":254,"props":7118,"children":7119},{"__ignoreMap":7},[7120,7128,7135,7163,7201,7208,7237,7254,7293,7325,7333,7358,7383,7408,7415,7422,7429,7455,7463,7494,7501,7508,7533,7584,7591,7598,7633],{"type":15,"tag":360,"props":7121,"children":7122},{"class":362,"line":363},[7123],{"type":15,"tag":360,"props":7124,"children":7125},{"style":486},[7126],{"type":21,"value":7127},"// Action: \"syncOneProductToStripe\"\n",{"type":15,"tag":360,"props":7129,"children":7130},{"class":362,"line":411},[7131],{"type":15,"tag":360,"props":7132,"children":7133},{"emptyLinePlaceholder":839},[7134],{"type":21,"value":842},{"type":15,"tag":360,"props":7136,"children":7137},{"class":362,"line":425},[7138,7142,7147,7151,7155,7159],{"type":15,"tag":360,"props":7139,"children":7140},{"style":367},[7141],{"type":21,"value":370},{"type":15,"tag":360,"props":7143,"children":7144},{"style":373},[7145],{"type":21,"value":7146}," product ",{"type":15,"tag":360,"props":7148,"children":7149},{"style":367},[7150],{"type":21,"value":381},{"type":15,"tag":360,"props":7152,"children":7153},{"style":373},[7154],{"type":21,"value":386},{"type":15,"tag":360,"props":7156,"children":7157},{"style":389},[7158],{"type":21,"value":1216},{"type":15,"tag":360,"props":7160,"children":7161},{"style":373},[7162],{"type":21,"value":479},{"type":15,"tag":360,"props":7164,"children":7165},{"class":362,"line":449},[7166,7170,7175,7179,7183,7188,7192,7197],{"type":15,"tag":360,"props":7167,"children":7168},{"style":367},[7169],{"type":21,"value":370},{"type":15,"tag":360,"props":7171,"children":7172},{"style":373},[7173],{"type":21,"value":7174}," stripeApiKey ",{"type":15,"tag":360,"props":7176,"children":7177},{"style":367},[7178],{"type":21,"value":381},{"type":15,"tag":360,"props":7180,"children":7181},{"style":373},[7182],{"type":21,"value":386},{"type":15,"tag":360,"props":7184,"children":7185},{"style":389},[7186],{"type":21,"value":7187},"getConfig",{"type":15,"tag":360,"props":7189,"children":7190},{"style":373},[7191],{"type":21,"value":397},{"type":15,"tag":360,"props":7193,"children":7194},{"style":400},[7195],{"type":21,"value":7196},"\"stripe_api_key\"",{"type":15,"tag":360,"props":7198,"children":7199},{"style":373},[7200],{"type":21,"value":408},{"type":15,"tag":360,"props":7202,"children":7203},{"class":362,"line":482},[7204],{"type":15,"tag":360,"props":7205,"children":7206},{"emptyLinePlaceholder":839},[7207],{"type":21,"value":842},{"type":15,"tag":360,"props":7209,"children":7210},{"class":362,"line":492},[7211,7215,7220,7224,7228,7233],{"type":15,"tag":360,"props":7212,"children":7213},{"style":367},[7214],{"type":21,"value":370},{"type":15,"tag":360,"props":7216,"children":7217},{"style":373},[7218],{"type":21,"value":7219}," response ",{"type":15,"tag":360,"props":7221,"children":7222},{"style":367},[7223],{"type":21,"value":381},{"type":15,"tag":360,"props":7225,"children":7226},{"style":373},[7227],{"type":21,"value":386},{"type":15,"tag":360,"props":7229,"children":7230},{"style":389},[7231],{"type":21,"value":7232},"httpRequest",{"type":15,"tag":360,"props":7234,"children":7235},{"style":373},[7236],{"type":21,"value":905},{"type":15,"tag":360,"props":7238,"children":7239},{"class":362,"line":501},[7240,7245,7250],{"type":15,"tag":360,"props":7241,"children":7242},{"style":373},[7243],{"type":21,"value":7244},"    method: ",{"type":15,"tag":360,"props":7246,"children":7247},{"style":400},[7248],{"type":21,"value":7249},"\"POST\"",{"type":15,"tag":360,"props":7251,"children":7252},{"style":373},[7253],{"type":21,"value":923},{"type":15,"tag":360,"props":7255,"children":7256},{"class":362,"line":519},[7257,7262,7267,7271,7276,7280,7284,7289],{"type":15,"tag":360,"props":7258,"children":7259},{"style":373},[7260],{"type":21,"value":7261},"    url:    ",{"type":15,"tag":360,"props":7263,"children":7264},{"style":400},[7265],{"type":21,"value":7266},"\"https://api.stripe.com/v1/products/\"",{"type":15,"tag":360,"props":7268,"children":7269},{"style":367},[7270],{"type":21,"value":6494},{"type":15,"tag":360,"props":7272,"children":7273},{"style":373},[7274],{"type":21,"value":7275}," product.",{"type":15,"tag":360,"props":7277,"children":7278},{"style":389},[7279],{"type":21,"value":1256},{"type":15,"tag":360,"props":7281,"children":7282},{"style":373},[7283],{"type":21,"value":397},{"type":15,"tag":360,"props":7285,"children":7286},{"style":400},[7287],{"type":21,"value":7288},"\"stripeId\"",{"type":15,"tag":360,"props":7290,"children":7291},{"style":373},[7292],{"type":21,"value":1270},{"type":15,"tag":360,"props":7294,"children":7295},{"class":362,"line":537},[7296,7301,7306,7311,7316,7320],{"type":15,"tag":360,"props":7297,"children":7298},{"style":373},[7299],{"type":21,"value":7300},"    headers: { ",{"type":15,"tag":360,"props":7302,"children":7303},{"style":400},[7304],{"type":21,"value":7305},"\"Authorization\"",{"type":15,"tag":360,"props":7307,"children":7308},{"style":373},[7309],{"type":21,"value":7310},": ",{"type":15,"tag":360,"props":7312,"children":7313},{"style":400},[7314],{"type":21,"value":7315},"\"Bearer \"",{"type":15,"tag":360,"props":7317,"children":7318},{"style":367},[7319],{"type":21,"value":6494},{"type":15,"tag":360,"props":7321,"children":7322},{"style":373},[7323],{"type":21,"value":7324}," stripeApiKey },\n",{"type":15,"tag":360,"props":7326,"children":7327},{"class":362,"line":773},[7328],{"type":15,"tag":360,"props":7329,"children":7330},{"style":373},[7331],{"type":21,"value":7332},"    body: {\n",{"type":15,"tag":360,"props":7334,"children":7335},{"class":362,"line":1016},[7336,7341,7345,7349,7354],{"type":15,"tag":360,"props":7337,"children":7338},{"style":373},[7339],{"type":21,"value":7340},"        name:        product.",{"type":15,"tag":360,"props":7342,"children":7343},{"style":389},[7344],{"type":21,"value":1256},{"type":15,"tag":360,"props":7346,"children":7347},{"style":373},[7348],{"type":21,"value":397},{"type":15,"tag":360,"props":7350,"children":7351},{"style":400},[7352],{"type":21,"value":7353},"\"name\"",{"type":15,"tag":360,"props":7355,"children":7356},{"style":373},[7357],{"type":21,"value":1270},{"type":15,"tag":360,"props":7359,"children":7360},{"class":362,"line":1024},[7361,7366,7370,7374,7379],{"type":15,"tag":360,"props":7362,"children":7363},{"style":373},[7364],{"type":21,"value":7365},"        description: product.",{"type":15,"tag":360,"props":7367,"children":7368},{"style":389},[7369],{"type":21,"value":1256},{"type":15,"tag":360,"props":7371,"children":7372},{"style":373},[7373],{"type":21,"value":397},{"type":15,"tag":360,"props":7375,"children":7376},{"style":400},[7377],{"type":21,"value":7378},"\"description\"",{"type":15,"tag":360,"props":7380,"children":7381},{"style":373},[7382],{"type":21,"value":1270},{"type":15,"tag":360,"props":7384,"children":7385},{"class":362,"line":1040},[7386,7391,7395,7399,7403],{"type":15,"tag":360,"props":7387,"children":7388},{"style":373},[7389],{"type":21,"value":7390},"        metadata: { internalId: product.",{"type":15,"tag":360,"props":7392,"children":7393},{"style":389},[7394],{"type":21,"value":1256},{"type":15,"tag":360,"props":7396,"children":7397},{"style":373},[7398],{"type":21,"value":397},{"type":15,"tag":360,"props":7400,"children":7401},{"style":400},[7402],{"type":21,"value":1967},{"type":15,"tag":360,"props":7404,"children":7405},{"style":373},[7406],{"type":21,"value":7407},") }\n",{"type":15,"tag":360,"props":7409,"children":7410},{"class":362,"line":1056},[7411],{"type":15,"tag":360,"props":7412,"children":7413},{"style":373},[7414],{"type":21,"value":498},{"type":15,"tag":360,"props":7416,"children":7417},{"class":362,"line":1072},[7418],{"type":15,"tag":360,"props":7419,"children":7420},{"style":373},[7421],{"type":21,"value":944},{"type":15,"tag":360,"props":7423,"children":7424},{"class":362,"line":5296},[7425],{"type":15,"tag":360,"props":7426,"children":7427},{"emptyLinePlaceholder":839},[7428],{"type":21,"value":842},{"type":15,"tag":360,"props":7430,"children":7431},{"class":362,"line":5319},[7432,7436,7441,7446,7451],{"type":15,"tag":360,"props":7433,"children":7434},{"style":367},[7435],{"type":21,"value":3572},{"type":15,"tag":360,"props":7437,"children":7438},{"style":373},[7439],{"type":21,"value":7440}," (response.statusCode ",{"type":15,"tag":360,"props":7442,"children":7443},{"style":367},[7444],{"type":21,"value":7445},"===",{"type":15,"tag":360,"props":7447,"children":7448},{"style":708},[7449],{"type":21,"value":7450}," 429",{"type":15,"tag":360,"props":7452,"children":7453},{"style":373},[7454],{"type":21,"value":3609},{"type":15,"tag":360,"props":7456,"children":7457},{"class":362,"line":5336},[7458],{"type":15,"tag":360,"props":7459,"children":7460},{"style":486},[7461],{"type":21,"value":7462},"    // Stripe is telling us to slow down. Throw to trigger retry.\n",{"type":15,"tag":360,"props":7464,"children":7465},{"class":362,"line":5359},[7466,7471,7476,7481,7485,7490],{"type":15,"tag":360,"props":7467,"children":7468},{"style":367},[7469],{"type":21,"value":7470},"    throw",{"type":15,"tag":360,"props":7472,"children":7473},{"style":367},[7474],{"type":21,"value":7475}," new",{"type":15,"tag":360,"props":7477,"children":7478},{"style":389},[7479],{"type":21,"value":7480}," Error",{"type":15,"tag":360,"props":7482,"children":7483},{"style":373},[7484],{"type":21,"value":397},{"type":15,"tag":360,"props":7486,"children":7487},{"style":400},[7488],{"type":21,"value":7489},"\"Stripe rate limit hit, will retry\"",{"type":15,"tag":360,"props":7491,"children":7492},{"style":373},[7493],{"type":21,"value":408},{"type":15,"tag":360,"props":7495,"children":7496},{"class":362,"line":5413},[7497],{"type":15,"tag":360,"props":7498,"children":7499},{"style":373},[7500],{"type":21,"value":543},{"type":15,"tag":360,"props":7502,"children":7503},{"class":362,"line":5421},[7504],{"type":15,"tag":360,"props":7505,"children":7506},{"emptyLinePlaceholder":839},[7507],{"type":21,"value":842},{"type":15,"tag":360,"props":7509,"children":7510},{"class":362,"line":5430},[7511,7515,7519,7524,7529],{"type":15,"tag":360,"props":7512,"children":7513},{"style":367},[7514],{"type":21,"value":3572},{"type":15,"tag":360,"props":7516,"children":7517},{"style":373},[7518],{"type":21,"value":7440},{"type":15,"tag":360,"props":7520,"children":7521},{"style":367},[7522],{"type":21,"value":7523},">=",{"type":15,"tag":360,"props":7525,"children":7526},{"style":708},[7527],{"type":21,"value":7528}," 400",{"type":15,"tag":360,"props":7530,"children":7531},{"style":373},[7532],{"type":21,"value":3609},{"type":15,"tag":360,"props":7534,"children":7535},{"class":362,"line":5439},[7536,7540,7544,7548,7552,7557,7561,7566,7570,7575,7579],{"type":15,"tag":360,"props":7537,"children":7538},{"style":367},[7539],{"type":21,"value":7470},{"type":15,"tag":360,"props":7541,"children":7542},{"style":367},[7543],{"type":21,"value":7475},{"type":15,"tag":360,"props":7545,"children":7546},{"style":389},[7547],{"type":21,"value":7480},{"type":15,"tag":360,"props":7549,"children":7550},{"style":373},[7551],{"type":21,"value":397},{"type":15,"tag":360,"props":7553,"children":7554},{"style":400},[7555],{"type":21,"value":7556},"\"Stripe error \"",{"type":15,"tag":360,"props":7558,"children":7559},{"style":367},[7560],{"type":21,"value":6494},{"type":15,"tag":360,"props":7562,"children":7563},{"style":373},[7564],{"type":21,"value":7565}," response.statusCode ",{"type":15,"tag":360,"props":7567,"children":7568},{"style":367},[7569],{"type":21,"value":2909},{"type":15,"tag":360,"props":7571,"children":7572},{"style":400},[7573],{"type":21,"value":7574}," \": \"",{"type":15,"tag":360,"props":7576,"children":7577},{"style":367},[7578],{"type":21,"value":6494},{"type":15,"tag":360,"props":7580,"children":7581},{"style":373},[7582],{"type":21,"value":7583}," response.body);\n",{"type":15,"tag":360,"props":7585,"children":7586},{"class":362,"line":5447},[7587],{"type":15,"tag":360,"props":7588,"children":7589},{"style":373},[7590],{"type":21,"value":543},{"type":15,"tag":360,"props":7592,"children":7593},{"class":362,"line":5455},[7594],{"type":15,"tag":360,"props":7595,"children":7596},{"emptyLinePlaceholder":839},[7597],{"type":21,"value":842},{"type":15,"tag":360,"props":7599,"children":7600},{"class":362,"line":5467},[7601,7606,7610,7614,7619,7624,7628],{"type":15,"tag":360,"props":7602,"children":7603},{"style":373},[7604],{"type":21,"value":7605},"product.",{"type":15,"tag":360,"props":7607,"children":7608},{"style":389},[7609],{"type":21,"value":1334},{"type":15,"tag":360,"props":7611,"children":7612},{"style":373},[7613],{"type":21,"value":397},{"type":15,"tag":360,"props":7615,"children":7616},{"style":400},[7617],{"type":21,"value":7618},"\"lastStripeSync\"",{"type":15,"tag":360,"props":7620,"children":7621},{"style":373},[7622],{"type":21,"value":7623},", Date.",{"type":15,"tag":360,"props":7625,"children":7626},{"style":389},[7627],{"type":21,"value":2899},{"type":15,"tag":360,"props":7629,"children":7630},{"style":373},[7631],{"type":21,"value":7632},"());\n",{"type":15,"tag":360,"props":7634,"children":7635},{"class":362,"line":5488},[7636,7640,7644],{"type":15,"tag":360,"props":7637,"children":7638},{"style":373},[7639],{"type":21,"value":1234},{"type":15,"tag":360,"props":7641,"children":7642},{"style":389},[7643],{"type":21,"value":1369},{"type":15,"tag":360,"props":7645,"children":7646},{"style":373},[7647],{"type":21,"value":7648},"(product);\n",{"type":15,"tag":24,"props":7650,"children":7651},{},[7652],{"type":21,"value":7653},"The platform's automatic retry with backoff (5/15/30 minutes) handles the rare 429 perfectly without you writing any retry code.",{"type":15,"tag":805,"props":7655,"children":7656},{},[],{"type":15,"tag":325,"props":7658,"children":7660},{"id":7659},"use-case-3-order-processing-with-three-outcomes",[7661],{"type":21,"value":7662},"Use Case 3: Order Processing with Three Outcomes",{"type":15,"tag":24,"props":7664,"children":7665},{},[7666,7670],{"type":15,"tag":30,"props":7667,"children":7668},{},[7669],{"type":21,"value":5021},{"type":21,"value":7671}," Process all pending orders. Most should succeed cleanly. A small number might fail due to validation issues — those need manual review. If the failure rate spikes, page ops immediately.",{"type":15,"tag":350,"props":7673,"children":7675},{"className":352,"code":7674,"language":354,"meta":7,"style":7},"// Action: \"processNewOrders\"\n\nlet orders = context.query(\n    \"select o from order o where o.status = 'pending'\");\n\nlet batch = context.createBatch({\n    onSuccess: \"orderBatchOk\",\n    onPartial: \"orderBatchPartial\",\n    onError:   \"orderBatchFailed\",\n    results:           \"FAILURES_ONLY\",\n    failureThreshold:  0.05,                // 5% failure budget\n    failureMinSamples: 20,\n    maxConcurrent:     50,\n    deadlineMs:        Date.now() + 60 * 60 * 1000,   // 1 hour\n    context: {\n        triggeredAt: Date.now(),\n        triggeredBy: context.user.username,\n        cycleId:     cycle.get(\"id\")\n    }\n});\ntry {\n    while (orders.hasNext()) {\n        batch.add(\"processOneOrder\", orders.next(), null);\n    }\n} finally {\n    orders.close();\n    batch.seal();\n}\n",[7676],{"type":15,"tag":254,"props":7677,"children":7678},{"__ignoreMap":7},[7679,7687,7694,7722,7734,7741,7768,7784,7800,7816,7831,7851,7866,7881,7930,7937,7954,7961,7985,7992,7999,8010,8030,8071,8078,8093,8109,8124],{"type":15,"tag":360,"props":7680,"children":7681},{"class":362,"line":363},[7682],{"type":15,"tag":360,"props":7683,"children":7684},{"style":486},[7685],{"type":21,"value":7686},"// Action: \"processNewOrders\"\n",{"type":15,"tag":360,"props":7688,"children":7689},{"class":362,"line":411},[7690],{"type":15,"tag":360,"props":7691,"children":7692},{"emptyLinePlaceholder":839},[7693],{"type":21,"value":842},{"type":15,"tag":360,"props":7695,"children":7696},{"class":362,"line":425},[7697,7701,7706,7710,7714,7718],{"type":15,"tag":360,"props":7698,"children":7699},{"style":367},[7700],{"type":21,"value":370},{"type":15,"tag":360,"props":7702,"children":7703},{"style":373},[7704],{"type":21,"value":7705}," orders ",{"type":15,"tag":360,"props":7707,"children":7708},{"style":367},[7709],{"type":21,"value":381},{"type":15,"tag":360,"props":7711,"children":7712},{"style":373},[7713],{"type":21,"value":386},{"type":15,"tag":360,"props":7715,"children":7716},{"style":389},[7717],{"type":21,"value":392},{"type":15,"tag":360,"props":7719,"children":7720},{"style":373},[7721],{"type":21,"value":5126},{"type":15,"tag":360,"props":7723,"children":7724},{"class":362,"line":449},[7725,7730],{"type":15,"tag":360,"props":7726,"children":7727},{"style":400},[7728],{"type":21,"value":7729},"    \"select o from order o where o.status = 'pending'\"",{"type":15,"tag":360,"props":7731,"children":7732},{"style":373},[7733],{"type":21,"value":408},{"type":15,"tag":360,"props":7735,"children":7736},{"class":362,"line":482},[7737],{"type":15,"tag":360,"props":7738,"children":7739},{"emptyLinePlaceholder":839},[7740],{"type":21,"value":842},{"type":15,"tag":360,"props":7742,"children":7743},{"class":362,"line":492},[7744,7748,7752,7756,7760,7764],{"type":15,"tag":360,"props":7745,"children":7746},{"style":367},[7747],{"type":21,"value":370},{"type":15,"tag":360,"props":7749,"children":7750},{"style":373},[7751],{"type":21,"value":611},{"type":15,"tag":360,"props":7753,"children":7754},{"style":367},[7755],{"type":21,"value":381},{"type":15,"tag":360,"props":7757,"children":7758},{"style":373},[7759],{"type":21,"value":386},{"type":15,"tag":360,"props":7761,"children":7762},{"style":389},[7763],{"type":21,"value":259},{"type":15,"tag":360,"props":7765,"children":7766},{"style":373},[7767],{"type":21,"value":905},{"type":15,"tag":360,"props":7769,"children":7770},{"class":362,"line":501},[7771,7775,7780],{"type":15,"tag":360,"props":7772,"children":7773},{"style":373},[7774],{"type":21,"value":913},{"type":15,"tag":360,"props":7776,"children":7777},{"style":400},[7778],{"type":21,"value":7779},"\"orderBatchOk\"",{"type":15,"tag":360,"props":7781,"children":7782},{"style":373},[7783],{"type":21,"value":923},{"type":15,"tag":360,"props":7785,"children":7786},{"class":362,"line":519},[7787,7791,7796],{"type":15,"tag":360,"props":7788,"children":7789},{"style":373},[7790],{"type":21,"value":5247},{"type":15,"tag":360,"props":7792,"children":7793},{"style":400},[7794],{"type":21,"value":7795},"\"orderBatchPartial\"",{"type":15,"tag":360,"props":7797,"children":7798},{"style":373},[7799],{"type":21,"value":923},{"type":15,"tag":360,"props":7801,"children":7802},{"class":362,"line":537},[7803,7807,7812],{"type":15,"tag":360,"props":7804,"children":7805},{"style":373},[7806],{"type":21,"value":931},{"type":15,"tag":360,"props":7808,"children":7809},{"style":400},[7810],{"type":21,"value":7811},"\"orderBatchFailed\"",{"type":15,"tag":360,"props":7813,"children":7814},{"style":373},[7815],{"type":21,"value":923},{"type":15,"tag":360,"props":7817,"children":7818},{"class":362,"line":773},[7819,7823,7827],{"type":15,"tag":360,"props":7820,"children":7821},{"style":373},[7822],{"type":21,"value":5279},{"type":15,"tag":360,"props":7824,"children":7825},{"style":400},[7826],{"type":21,"value":3503},{"type":15,"tag":360,"props":7828,"children":7829},{"style":373},[7830],{"type":21,"value":923},{"type":15,"tag":360,"props":7832,"children":7833},{"class":362,"line":1016},[7834,7838,7842,7846],{"type":15,"tag":360,"props":7835,"children":7836},{"style":373},[7837],{"type":21,"value":2697},{"type":15,"tag":360,"props":7839,"children":7840},{"style":708},[7841],{"type":21,"value":5306},{"type":15,"tag":360,"props":7843,"children":7844},{"style":373},[7845],{"type":21,"value":5311},{"type":15,"tag":360,"props":7847,"children":7848},{"style":486},[7849],{"type":21,"value":7850},"// 5% failure budget\n",{"type":15,"tag":360,"props":7852,"children":7853},{"class":362,"line":1024},[7854,7858,7862],{"type":15,"tag":360,"props":7855,"children":7856},{"style":373},[7857],{"type":21,"value":2720},{"type":15,"tag":360,"props":7859,"children":7860},{"style":708},[7861],{"type":21,"value":6808},{"type":15,"tag":360,"props":7863,"children":7864},{"style":373},[7865],{"type":21,"value":923},{"type":15,"tag":360,"props":7867,"children":7868},{"class":362,"line":1040},[7869,7873,7877],{"type":15,"tag":360,"props":7870,"children":7871},{"style":373},[7872],{"type":21,"value":5342},{"type":15,"tag":360,"props":7874,"children":7875},{"style":708},[7876],{"type":21,"value":2725},{"type":15,"tag":360,"props":7878,"children":7879},{"style":373},[7880],{"type":21,"value":923},{"type":15,"tag":360,"props":7882,"children":7883},{"class":362,"line":1056},[7884,7888,7892,7896,7900,7904,7908,7912,7916,7920,7925],{"type":15,"tag":360,"props":7885,"children":7886},{"style":373},[7887],{"type":21,"value":5365},{"type":15,"tag":360,"props":7889,"children":7890},{"style":389},[7891],{"type":21,"value":2899},{"type":15,"tag":360,"props":7893,"children":7894},{"style":373},[7895],{"type":21,"value":2904},{"type":15,"tag":360,"props":7897,"children":7898},{"style":367},[7899],{"type":21,"value":2909},{"type":15,"tag":360,"props":7901,"children":7902},{"style":708},[7903],{"type":21,"value":2924},{"type":15,"tag":360,"props":7905,"children":7906},{"style":367},[7907],{"type":21,"value":2919},{"type":15,"tag":360,"props":7909,"children":7910},{"style":708},[7911],{"type":21,"value":2924},{"type":15,"tag":360,"props":7913,"children":7914},{"style":367},[7915],{"type":21,"value":2919},{"type":15,"tag":360,"props":7917,"children":7918},{"style":708},[7919],{"type":21,"value":2933},{"type":15,"tag":360,"props":7921,"children":7922},{"style":373},[7923],{"type":21,"value":7924},",   ",{"type":15,"tag":360,"props":7926,"children":7927},{"style":486},[7928],{"type":21,"value":7929},"// 1 hour\n",{"type":15,"tag":360,"props":7931,"children":7932},{"class":362,"line":1072},[7933],{"type":15,"tag":360,"props":7934,"children":7935},{"style":373},[7936],{"type":21,"value":1938},{"type":15,"tag":360,"props":7938,"children":7939},{"class":362,"line":5296},[7940,7945,7949],{"type":15,"tag":360,"props":7941,"children":7942},{"style":373},[7943],{"type":21,"value":7944},"        triggeredAt: Date.",{"type":15,"tag":360,"props":7946,"children":7947},{"style":389},[7948],{"type":21,"value":2899},{"type":15,"tag":360,"props":7950,"children":7951},{"style":373},[7952],{"type":21,"value":7953},"(),\n",{"type":15,"tag":360,"props":7955,"children":7956},{"class":362,"line":5319},[7957],{"type":15,"tag":360,"props":7958,"children":7959},{"style":373},[7960],{"type":21,"value":1946},{"type":15,"tag":360,"props":7962,"children":7963},{"class":362,"line":5336},[7964,7969,7973,7977,7981],{"type":15,"tag":360,"props":7965,"children":7966},{"style":373},[7967],{"type":21,"value":7968},"        cycleId:     cycle.",{"type":15,"tag":360,"props":7970,"children":7971},{"style":389},[7972],{"type":21,"value":1256},{"type":15,"tag":360,"props":7974,"children":7975},{"style":373},[7976],{"type":21,"value":397},{"type":15,"tag":360,"props":7978,"children":7979},{"style":400},[7980],{"type":21,"value":1967},{"type":15,"tag":360,"props":7982,"children":7983},{"style":373},[7984],{"type":21,"value":1972},{"type":15,"tag":360,"props":7986,"children":7987},{"class":362,"line":5359},[7988],{"type":15,"tag":360,"props":7989,"children":7990},{"style":373},[7991],{"type":21,"value":498},{"type":15,"tag":360,"props":7993,"children":7994},{"class":362,"line":5413},[7995],{"type":15,"tag":360,"props":7996,"children":7997},{"style":373},[7998],{"type":21,"value":944},{"type":15,"tag":360,"props":8000,"children":8001},{"class":362,"line":5421},[8002,8006],{"type":15,"tag":360,"props":8003,"children":8004},{"style":367},[8005],{"type":21,"value":417},{"type":15,"tag":360,"props":8007,"children":8008},{"style":373},[8009],{"type":21,"value":422},{"type":15,"tag":360,"props":8011,"children":8012},{"class":362,"line":5430},[8013,8017,8022,8026],{"type":15,"tag":360,"props":8014,"children":8015},{"style":367},[8016],{"type":21,"value":431},{"type":15,"tag":360,"props":8018,"children":8019},{"style":373},[8020],{"type":21,"value":8021}," (orders.",{"type":15,"tag":360,"props":8023,"children":8024},{"style":389},[8025],{"type":21,"value":441},{"type":15,"tag":360,"props":8027,"children":8028},{"style":373},[8029],{"type":21,"value":446},{"type":15,"tag":360,"props":8031,"children":8032},{"class":362,"line":5439},[8033,8037,8041,8045,8050,8055,8059,8063,8067],{"type":15,"tag":360,"props":8034,"children":8035},{"style":373},[8036],{"type":21,"value":677},{"type":15,"tag":360,"props":8038,"children":8039},{"style":389},[8040],{"type":21,"value":682},{"type":15,"tag":360,"props":8042,"children":8043},{"style":373},[8044],{"type":21,"value":397},{"type":15,"tag":360,"props":8046,"children":8047},{"style":400},[8048],{"type":21,"value":8049},"\"processOneOrder\"",{"type":15,"tag":360,"props":8051,"children":8052},{"style":373},[8053],{"type":21,"value":8054},", orders.",{"type":15,"tag":360,"props":8056,"children":8057},{"style":389},[8058],{"type":21,"value":474},{"type":15,"tag":360,"props":8060,"children":8061},{"style":373},[8062],{"type":21,"value":705},{"type":15,"tag":360,"props":8064,"children":8065},{"style":708},[8066],{"type":21,"value":711},{"type":15,"tag":360,"props":8068,"children":8069},{"style":373},[8070],{"type":21,"value":408},{"type":15,"tag":360,"props":8072,"children":8073},{"class":362,"line":5447},[8074],{"type":15,"tag":360,"props":8075,"children":8076},{"style":373},[8077],{"type":21,"value":498},{"type":15,"tag":360,"props":8079,"children":8080},{"class":362,"line":5455},[8081,8085,8089],{"type":15,"tag":360,"props":8082,"children":8083},{"style":373},[8084],{"type":21,"value":507},{"type":15,"tag":360,"props":8086,"children":8087},{"style":367},[8088],{"type":21,"value":512},{"type":15,"tag":360,"props":8090,"children":8091},{"style":373},[8092],{"type":21,"value":422},{"type":15,"tag":360,"props":8094,"children":8095},{"class":362,"line":5467},[8096,8101,8105],{"type":15,"tag":360,"props":8097,"children":8098},{"style":373},[8099],{"type":21,"value":8100},"    orders.",{"type":15,"tag":360,"props":8102,"children":8103},{"style":389},[8104],{"type":21,"value":530},{"type":15,"tag":360,"props":8106,"children":8107},{"style":373},[8108],{"type":21,"value":479},{"type":15,"tag":360,"props":8110,"children":8111},{"class":362,"line":5488},[8112,8116,8120],{"type":15,"tag":360,"props":8113,"children":8114},{"style":373},[8115],{"type":21,"value":761},{"type":15,"tag":360,"props":8117,"children":8118},{"style":389},[8119],{"type":21,"value":766},{"type":15,"tag":360,"props":8121,"children":8122},{"style":373},[8123],{"type":21,"value":479},{"type":15,"tag":360,"props":8125,"children":8126},{"class":362,"line":5523},[8127],{"type":15,"tag":360,"props":8128,"children":8129},{"style":373},[8130],{"type":21,"value":543},{"type":15,"tag":24,"props":8132,"children":8133},{},[8134],{"type":21,"value":8135},"Three finalizers, each handling its own outcome:",{"type":15,"tag":350,"props":8137,"children":8139},{"className":352,"code":8138,"language":354,"meta":7,"style":7},"// Action: \"orderBatchOk\" — happy path\ncontext.log(\"Order cycle {} processed {} orders cleanly in {}s\",\n    context.getParameter(\"cycleId\"),\n    context.getInput(\"totalJobs\"),\n    Math.round(context.getInput(\"durationMs\") / 1000));\n",[8140],{"type":15,"tag":254,"props":8141,"children":8142},{"__ignoreMap":7},[8143,8151,8175,8199,8222],{"type":15,"tag":360,"props":8144,"children":8145},{"class":362,"line":363},[8146],{"type":15,"tag":360,"props":8147,"children":8148},{"style":486},[8149],{"type":21,"value":8150},"// Action: \"orderBatchOk\" — happy path\n",{"type":15,"tag":360,"props":8152,"children":8153},{"class":362,"line":411},[8154,8158,8162,8166,8171],{"type":15,"tag":360,"props":8155,"children":8156},{"style":373},[8157],{"type":21,"value":1234},{"type":15,"tag":360,"props":8159,"children":8160},{"style":389},[8161],{"type":21,"value":1418},{"type":15,"tag":360,"props":8163,"children":8164},{"style":373},[8165],{"type":21,"value":397},{"type":15,"tag":360,"props":8167,"children":8168},{"style":400},[8169],{"type":21,"value":8170},"\"Order cycle {} processed {} orders cleanly in {}s\"",{"type":15,"tag":360,"props":8172,"children":8173},{"style":373},[8174],{"type":21,"value":923},{"type":15,"tag":360,"props":8176,"children":8177},{"class":362,"line":425},[8178,8182,8186,8190,8195],{"type":15,"tag":360,"props":8179,"children":8180},{"style":373},[8181],{"type":21,"value":1439},{"type":15,"tag":360,"props":8183,"children":8184},{"style":389},[8185],{"type":21,"value":2067},{"type":15,"tag":360,"props":8187,"children":8188},{"style":373},[8189],{"type":21,"value":397},{"type":15,"tag":360,"props":8191,"children":8192},{"style":400},[8193],{"type":21,"value":8194},"\"cycleId\"",{"type":15,"tag":360,"props":8196,"children":8197},{"style":373},[8198],{"type":21,"value":1270},{"type":15,"tag":360,"props":8200,"children":8201},{"class":362,"line":449},[8202,8206,8210,8214,8218],{"type":15,"tag":360,"props":8203,"children":8204},{"style":373},[8205],{"type":21,"value":1439},{"type":15,"tag":360,"props":8207,"children":8208},{"style":389},[8209],{"type":21,"value":1444},{"type":15,"tag":360,"props":8211,"children":8212},{"style":373},[8213],{"type":21,"value":397},{"type":15,"tag":360,"props":8215,"children":8216},{"style":400},[8217],{"type":21,"value":1501},{"type":15,"tag":360,"props":8219,"children":8220},{"style":373},[8221],{"type":21,"value":1270},{"type":15,"tag":360,"props":8223,"children":8224},{"class":362,"line":482},[8225,8230,8235,8240,8244,8248,8253,8257,8262,8266],{"type":15,"tag":360,"props":8226,"children":8227},{"style":373},[8228],{"type":21,"value":8229},"    Math.",{"type":15,"tag":360,"props":8231,"children":8232},{"style":389},[8233],{"type":21,"value":8234},"round",{"type":15,"tag":360,"props":8236,"children":8237},{"style":373},[8238],{"type":21,"value":8239},"(context.",{"type":15,"tag":360,"props":8241,"children":8242},{"style":389},[8243],{"type":21,"value":1444},{"type":15,"tag":360,"props":8245,"children":8246},{"style":373},[8247],{"type":21,"value":397},{"type":15,"tag":360,"props":8249,"children":8250},{"style":400},[8251],{"type":21,"value":8252},"\"durationMs\"",{"type":15,"tag":360,"props":8254,"children":8255},{"style":373},[8256],{"type":21,"value":3594},{"type":15,"tag":360,"props":8258,"children":8259},{"style":367},[8260],{"type":21,"value":8261},"/",{"type":15,"tag":360,"props":8263,"children":8264},{"style":708},[8265],{"type":21,"value":2933},{"type":15,"tag":360,"props":8267,"children":8268},{"style":373},[8269],{"type":21,"value":1506},{"type":15,"tag":350,"props":8271,"children":8273},{"className":352,"code":8272,"language":354,"meta":7,"style":7},"// Action: \"orderBatchPartial\" — most worked, some didn't\nlet cycleId   = context.getParameter(\"cycleId\");\nlet datasetId = context.getInput(\"resultsDatasetId\");\nlet failures  = context.scratchpad.getAllRecords(datasetId);\n\ncontext.sendMail({\n    to:      \"ops@example.com\",\n    subject: \"Order cycle \" + cycleId + \" had partial failures\",\n    body:    context.getInput(\"failedJobs\") + \" of \" + context.getInput(\"totalJobs\")\n             + \" orders failed; see scratchpad dataset \" + datasetId\n});\n\n// Queue the failed orders for human review\nfailures.forEach(function(rec) {\n    let data = rec.getData();\n    context.create(\"manualReviewQueue\", {\n        cycleId:       cycleId,\n        orderId:       rec.getRecordId(),\n        failureReason: data.get(\"result\")\n    });\n});\n",[8274],{"type":15,"tag":254,"props":8275,"children":8276},{"__ignoreMap":7},[8277,8285,8321,8356,8384,8391,8406,8423,8457,8513,8534,8541,8548,8556,8589,8617,8641,8649,8666,8690,8697],{"type":15,"tag":360,"props":8278,"children":8279},{"class":362,"line":363},[8280],{"type":15,"tag":360,"props":8281,"children":8282},{"style":486},[8283],{"type":21,"value":8284},"// Action: \"orderBatchPartial\" — most worked, some didn't\n",{"type":15,"tag":360,"props":8286,"children":8287},{"class":362,"line":411},[8288,8292,8297,8301,8305,8309,8313,8317],{"type":15,"tag":360,"props":8289,"children":8290},{"style":367},[8291],{"type":21,"value":370},{"type":15,"tag":360,"props":8293,"children":8294},{"style":373},[8295],{"type":21,"value":8296}," cycleId   ",{"type":15,"tag":360,"props":8298,"children":8299},{"style":367},[8300],{"type":21,"value":381},{"type":15,"tag":360,"props":8302,"children":8303},{"style":373},[8304],{"type":21,"value":386},{"type":15,"tag":360,"props":8306,"children":8307},{"style":389},[8308],{"type":21,"value":2067},{"type":15,"tag":360,"props":8310,"children":8311},{"style":373},[8312],{"type":21,"value":397},{"type":15,"tag":360,"props":8314,"children":8315},{"style":400},[8316],{"type":21,"value":8194},{"type":15,"tag":360,"props":8318,"children":8319},{"style":373},[8320],{"type":21,"value":408},{"type":15,"tag":360,"props":8322,"children":8323},{"class":362,"line":425},[8324,8328,8332,8336,8340,8344,8348,8352],{"type":15,"tag":360,"props":8325,"children":8326},{"style":367},[8327],{"type":21,"value":370},{"type":15,"tag":360,"props":8329,"children":8330},{"style":373},[8331],{"type":21,"value":3622},{"type":15,"tag":360,"props":8333,"children":8334},{"style":367},[8335],{"type":21,"value":381},{"type":15,"tag":360,"props":8337,"children":8338},{"style":373},[8339],{"type":21,"value":386},{"type":15,"tag":360,"props":8341,"children":8342},{"style":389},[8343],{"type":21,"value":1444},{"type":15,"tag":360,"props":8345,"children":8346},{"style":373},[8347],{"type":21,"value":397},{"type":15,"tag":360,"props":8349,"children":8350},{"style":400},[8351],{"type":21,"value":3643},{"type":15,"tag":360,"props":8353,"children":8354},{"style":373},[8355],{"type":21,"value":408},{"type":15,"tag":360,"props":8357,"children":8358},{"class":362,"line":449},[8359,8363,8368,8372,8376,8380],{"type":15,"tag":360,"props":8360,"children":8361},{"style":367},[8362],{"type":21,"value":370},{"type":15,"tag":360,"props":8364,"children":8365},{"style":373},[8366],{"type":21,"value":8367}," failures  ",{"type":15,"tag":360,"props":8369,"children":8370},{"style":367},[8371],{"type":21,"value":381},{"type":15,"tag":360,"props":8373,"children":8374},{"style":373},[8375],{"type":21,"value":3668},{"type":15,"tag":360,"props":8377,"children":8378},{"style":389},[8379],{"type":21,"value":3673},{"type":15,"tag":360,"props":8381,"children":8382},{"style":373},[8383],{"type":21,"value":3678},{"type":15,"tag":360,"props":8385,"children":8386},{"class":362,"line":482},[8387],{"type":15,"tag":360,"props":8388,"children":8389},{"emptyLinePlaceholder":839},[8390],{"type":21,"value":842},{"type":15,"tag":360,"props":8392,"children":8393},{"class":362,"line":492},[8394,8398,8402],{"type":15,"tag":360,"props":8395,"children":8396},{"style":373},[8397],{"type":21,"value":1234},{"type":15,"tag":360,"props":8399,"children":8400},{"style":389},[8401],{"type":21,"value":1239},{"type":15,"tag":360,"props":8403,"children":8404},{"style":373},[8405],{"type":21,"value":905},{"type":15,"tag":360,"props":8407,"children":8408},{"class":362,"line":501},[8409,8414,8419],{"type":15,"tag":360,"props":8410,"children":8411},{"style":373},[8412],{"type":21,"value":8413},"    to:      ",{"type":15,"tag":360,"props":8415,"children":8416},{"style":400},[8417],{"type":21,"value":8418},"\"ops@example.com\"",{"type":15,"tag":360,"props":8420,"children":8421},{"style":373},[8422],{"type":21,"value":923},{"type":15,"tag":360,"props":8424,"children":8425},{"class":362,"line":519},[8426,8430,8435,8439,8444,8448,8453],{"type":15,"tag":360,"props":8427,"children":8428},{"style":373},[8429],{"type":21,"value":1278},{"type":15,"tag":360,"props":8431,"children":8432},{"style":400},[8433],{"type":21,"value":8434},"\"Order cycle \"",{"type":15,"tag":360,"props":8436,"children":8437},{"style":367},[8438],{"type":21,"value":6494},{"type":15,"tag":360,"props":8440,"children":8441},{"style":373},[8442],{"type":21,"value":8443}," cycleId ",{"type":15,"tag":360,"props":8445,"children":8446},{"style":367},[8447],{"type":21,"value":2909},{"type":15,"tag":360,"props":8449,"children":8450},{"style":400},[8451],{"type":21,"value":8452}," \" had partial failures\"",{"type":15,"tag":360,"props":8454,"children":8455},{"style":373},[8456],{"type":21,"value":923},{"type":15,"tag":360,"props":8458,"children":8459},{"class":362,"line":537},[8460,8464,8468,8472,8476,8480,8484,8489,8493,8497,8501,8505,8509],{"type":15,"tag":360,"props":8461,"children":8462},{"style":373},[8463],{"type":21,"value":1295},{"type":15,"tag":360,"props":8465,"children":8466},{"style":389},[8467],{"type":21,"value":1444},{"type":15,"tag":360,"props":8469,"children":8470},{"style":373},[8471],{"type":21,"value":397},{"type":15,"tag":360,"props":8473,"children":8474},{"style":400},[8475],{"type":21,"value":1477},{"type":15,"tag":360,"props":8477,"children":8478},{"style":373},[8479],{"type":21,"value":3594},{"type":15,"tag":360,"props":8481,"children":8482},{"style":367},[8483],{"type":21,"value":2909},{"type":15,"tag":360,"props":8485,"children":8486},{"style":400},[8487],{"type":21,"value":8488}," \" of \"",{"type":15,"tag":360,"props":8490,"children":8491},{"style":367},[8492],{"type":21,"value":6494},{"type":15,"tag":360,"props":8494,"children":8495},{"style":373},[8496],{"type":21,"value":386},{"type":15,"tag":360,"props":8498,"children":8499},{"style":389},[8500],{"type":21,"value":1444},{"type":15,"tag":360,"props":8502,"children":8503},{"style":373},[8504],{"type":21,"value":397},{"type":15,"tag":360,"props":8506,"children":8507},{"style":400},[8508],{"type":21,"value":1501},{"type":15,"tag":360,"props":8510,"children":8511},{"style":373},[8512],{"type":21,"value":1972},{"type":15,"tag":360,"props":8514,"children":8515},{"class":362,"line":773},[8516,8520,8525,8529],{"type":15,"tag":360,"props":8517,"children":8518},{"style":367},[8519],{"type":21,"value":5650},{"type":15,"tag":360,"props":8521,"children":8522},{"style":400},[8523],{"type":21,"value":8524}," \" orders failed; see scratchpad dataset \"",{"type":15,"tag":360,"props":8526,"children":8527},{"style":367},[8528],{"type":21,"value":6494},{"type":15,"tag":360,"props":8530,"children":8531},{"style":373},[8532],{"type":21,"value":8533}," datasetId\n",{"type":15,"tag":360,"props":8535,"children":8536},{"class":362,"line":1016},[8537],{"type":15,"tag":360,"props":8538,"children":8539},{"style":373},[8540],{"type":21,"value":944},{"type":15,"tag":360,"props":8542,"children":8543},{"class":362,"line":1024},[8544],{"type":15,"tag":360,"props":8545,"children":8546},{"emptyLinePlaceholder":839},[8547],{"type":21,"value":842},{"type":15,"tag":360,"props":8549,"children":8550},{"class":362,"line":1040},[8551],{"type":15,"tag":360,"props":8552,"children":8553},{"style":486},[8554],{"type":21,"value":8555},"// Queue the failed orders for human review\n",{"type":15,"tag":360,"props":8557,"children":8558},{"class":362,"line":1056},[8559,8564,8568,8572,8576,8580,8585],{"type":15,"tag":360,"props":8560,"children":8561},{"style":373},[8562],{"type":21,"value":8563},"failures.",{"type":15,"tag":360,"props":8565,"children":8566},{"style":389},[8567],{"type":21,"value":3691},{"type":15,"tag":360,"props":8569,"children":8570},{"style":373},[8571],{"type":21,"value":397},{"type":15,"tag":360,"props":8573,"children":8574},{"style":367},[8575],{"type":21,"value":3700},{"type":15,"tag":360,"props":8577,"children":8578},{"style":373},[8579],{"type":21,"value":397},{"type":15,"tag":360,"props":8581,"children":8582},{"style":3707},[8583],{"type":21,"value":8584},"rec",{"type":15,"tag":360,"props":8586,"children":8587},{"style":373},[8588],{"type":21,"value":3609},{"type":15,"tag":360,"props":8590,"children":8591},{"class":362,"line":1072},[8592,8596,8600,8604,8609,8613],{"type":15,"tag":360,"props":8593,"children":8594},{"style":367},[8595],{"type":21,"value":3617},{"type":15,"tag":360,"props":8597,"children":8598},{"style":373},[8599],{"type":21,"value":3726},{"type":15,"tag":360,"props":8601,"children":8602},{"style":367},[8603],{"type":21,"value":381},{"type":15,"tag":360,"props":8605,"children":8606},{"style":373},[8607],{"type":21,"value":8608}," rec.",{"type":15,"tag":360,"props":8610,"children":8611},{"style":389},[8612],{"type":21,"value":3740},{"type":15,"tag":360,"props":8614,"children":8615},{"style":373},[8616],{"type":21,"value":479},{"type":15,"tag":360,"props":8618,"children":8619},{"class":362,"line":5296},[8620,8624,8628,8632,8637],{"type":15,"tag":360,"props":8621,"children":8622},{"style":373},[8623],{"type":21,"value":1439},{"type":15,"tag":360,"props":8625,"children":8626},{"style":389},[8627],{"type":21,"value":6166},{"type":15,"tag":360,"props":8629,"children":8630},{"style":373},[8631],{"type":21,"value":397},{"type":15,"tag":360,"props":8633,"children":8634},{"style":400},[8635],{"type":21,"value":8636},"\"manualReviewQueue\"",{"type":15,"tag":360,"props":8638,"children":8639},{"style":373},[8640],{"type":21,"value":6180},{"type":15,"tag":360,"props":8642,"children":8643},{"class":362,"line":5319},[8644],{"type":15,"tag":360,"props":8645,"children":8646},{"style":373},[8647],{"type":21,"value":8648},"        cycleId:       cycleId,\n",{"type":15,"tag":360,"props":8650,"children":8651},{"class":362,"line":5336},[8652,8657,8662],{"type":15,"tag":360,"props":8653,"children":8654},{"style":373},[8655],{"type":21,"value":8656},"        orderId:       rec.",{"type":15,"tag":360,"props":8658,"children":8659},{"style":389},[8660],{"type":21,"value":8661},"getRecordId",{"type":15,"tag":360,"props":8663,"children":8664},{"style":373},[8665],{"type":21,"value":7953},{"type":15,"tag":360,"props":8667,"children":8668},{"class":362,"line":5359},[8669,8674,8678,8682,8686],{"type":15,"tag":360,"props":8670,"children":8671},{"style":373},[8672],{"type":21,"value":8673},"        failureReason: data.",{"type":15,"tag":360,"props":8675,"children":8676},{"style":389},[8677],{"type":21,"value":1256},{"type":15,"tag":360,"props":8679,"children":8680},{"style":373},[8681],{"type":21,"value":397},{"type":15,"tag":360,"props":8683,"children":8684},{"style":400},[8685],{"type":21,"value":4156},{"type":15,"tag":360,"props":8687,"children":8688},{"style":373},[8689],{"type":21,"value":1972},{"type":15,"tag":360,"props":8691,"children":8692},{"class":362,"line":5413},[8693],{"type":15,"tag":360,"props":8694,"children":8695},{"style":373},[8696],{"type":21,"value":3820},{"type":15,"tag":360,"props":8698,"children":8699},{"class":362,"line":5421},[8700],{"type":15,"tag":360,"props":8701,"children":8702},{"style":373},[8703],{"type":21,"value":944},{"type":15,"tag":350,"props":8705,"children":8707},{"className":352,"code":8706,"language":354,"meta":7,"style":7},"// Action: \"orderBatchFailed\" — something is seriously wrong\nlet cycleId = context.getParameter(\"cycleId\");\n\ncontext.sendMail({\n    to:      \"ops@example.com\",\n    subject: \"URGENT: Order cycle \" + cycleId + \" FAILED\",\n    body:    \"State: \"  + context.getInput(\"state\")\n           + \", reason: \" + context.getInput(\"reason\")\n           + \".  \" + context.getInput(\"failedJobs\") + \"/\"\n           + context.getInput(\"totalJobs\")\n           + \" failed.  Investigate before retrying.\"\n});\n\n// Optionally page on-call via your incident management webhook\ncontext.httpRequest({\n    method: \"POST\",\n    url:    context.getConfig(\"pagerduty_webhook\"),\n    body: {\n        severity: \"critical\",\n        summary:  \"Order processing failed: cycle \" + cycleId\n    }\n});\n",[8708],{"type":15,"tag":254,"props":8709,"children":8710},{"__ignoreMap":7},[8711,8719,8754,8761,8776,8791,8824,8862,8900,8945,8972,8984,8991,8998,9006,9021,9036,9061,9068,9085,9107,9114],{"type":15,"tag":360,"props":8712,"children":8713},{"class":362,"line":363},[8714],{"type":15,"tag":360,"props":8715,"children":8716},{"style":486},[8717],{"type":21,"value":8718},"// Action: \"orderBatchFailed\" — something is seriously wrong\n",{"type":15,"tag":360,"props":8720,"children":8721},{"class":362,"line":411},[8722,8726,8730,8734,8738,8742,8746,8750],{"type":15,"tag":360,"props":8723,"children":8724},{"style":367},[8725],{"type":21,"value":370},{"type":15,"tag":360,"props":8727,"children":8728},{"style":373},[8729],{"type":21,"value":8443},{"type":15,"tag":360,"props":8731,"children":8732},{"style":367},[8733],{"type":21,"value":381},{"type":15,"tag":360,"props":8735,"children":8736},{"style":373},[8737],{"type":21,"value":386},{"type":15,"tag":360,"props":8739,"children":8740},{"style":389},[8741],{"type":21,"value":2067},{"type":15,"tag":360,"props":8743,"children":8744},{"style":373},[8745],{"type":21,"value":397},{"type":15,"tag":360,"props":8747,"children":8748},{"style":400},[8749],{"type":21,"value":8194},{"type":15,"tag":360,"props":8751,"children":8752},{"style":373},[8753],{"type":21,"value":408},{"type":15,"tag":360,"props":8755,"children":8756},{"class":362,"line":425},[8757],{"type":15,"tag":360,"props":8758,"children":8759},{"emptyLinePlaceholder":839},[8760],{"type":21,"value":842},{"type":15,"tag":360,"props":8762,"children":8763},{"class":362,"line":449},[8764,8768,8772],{"type":15,"tag":360,"props":8765,"children":8766},{"style":373},[8767],{"type":21,"value":1234},{"type":15,"tag":360,"props":8769,"children":8770},{"style":389},[8771],{"type":21,"value":1239},{"type":15,"tag":360,"props":8773,"children":8774},{"style":373},[8775],{"type":21,"value":905},{"type":15,"tag":360,"props":8777,"children":8778},{"class":362,"line":482},[8779,8783,8787],{"type":15,"tag":360,"props":8780,"children":8781},{"style":373},[8782],{"type":21,"value":8413},{"type":15,"tag":360,"props":8784,"children":8785},{"style":400},[8786],{"type":21,"value":8418},{"type":15,"tag":360,"props":8788,"children":8789},{"style":373},[8790],{"type":21,"value":923},{"type":15,"tag":360,"props":8792,"children":8793},{"class":362,"line":492},[8794,8798,8803,8807,8811,8815,8820],{"type":15,"tag":360,"props":8795,"children":8796},{"style":373},[8797],{"type":21,"value":1278},{"type":15,"tag":360,"props":8799,"children":8800},{"style":400},[8801],{"type":21,"value":8802},"\"URGENT: Order cycle \"",{"type":15,"tag":360,"props":8804,"children":8805},{"style":367},[8806],{"type":21,"value":6494},{"type":15,"tag":360,"props":8808,"children":8809},{"style":373},[8810],{"type":21,"value":8443},{"type":15,"tag":360,"props":8812,"children":8813},{"style":367},[8814],{"type":21,"value":2909},{"type":15,"tag":360,"props":8816,"children":8817},{"style":400},[8818],{"type":21,"value":8819}," \" FAILED\"",{"type":15,"tag":360,"props":8821,"children":8822},{"style":373},[8823],{"type":21,"value":923},{"type":15,"tag":360,"props":8825,"children":8826},{"class":362,"line":501},[8827,8831,8836,8841,8845,8849,8853,8858],{"type":15,"tag":360,"props":8828,"children":8829},{"style":373},[8830],{"type":21,"value":6519},{"type":15,"tag":360,"props":8832,"children":8833},{"style":400},[8834],{"type":21,"value":8835},"\"State: \"",{"type":15,"tag":360,"props":8837,"children":8838},{"style":367},[8839],{"type":21,"value":8840},"  +",{"type":15,"tag":360,"props":8842,"children":8843},{"style":373},[8844],{"type":21,"value":386},{"type":15,"tag":360,"props":8846,"children":8847},{"style":389},[8848],{"type":21,"value":1444},{"type":15,"tag":360,"props":8850,"children":8851},{"style":373},[8852],{"type":21,"value":397},{"type":15,"tag":360,"props":8854,"children":8855},{"style":400},[8856],{"type":21,"value":8857},"\"state\"",{"type":15,"tag":360,"props":8859,"children":8860},{"style":373},[8861],{"type":21,"value":1972},{"type":15,"tag":360,"props":8863,"children":8864},{"class":362,"line":519},[8865,8870,8875,8879,8883,8887,8891,8896],{"type":15,"tag":360,"props":8866,"children":8867},{"style":367},[8868],{"type":21,"value":8869},"           +",{"type":15,"tag":360,"props":8871,"children":8872},{"style":400},[8873],{"type":21,"value":8874}," \", reason: \"",{"type":15,"tag":360,"props":8876,"children":8877},{"style":367},[8878],{"type":21,"value":6494},{"type":15,"tag":360,"props":8880,"children":8881},{"style":373},[8882],{"type":21,"value":386},{"type":15,"tag":360,"props":8884,"children":8885},{"style":389},[8886],{"type":21,"value":1444},{"type":15,"tag":360,"props":8888,"children":8889},{"style":373},[8890],{"type":21,"value":397},{"type":15,"tag":360,"props":8892,"children":8893},{"style":400},[8894],{"type":21,"value":8895},"\"reason\"",{"type":15,"tag":360,"props":8897,"children":8898},{"style":373},[8899],{"type":21,"value":1972},{"type":15,"tag":360,"props":8901,"children":8902},{"class":362,"line":537},[8903,8907,8912,8916,8920,8924,8928,8932,8936,8940],{"type":15,"tag":360,"props":8904,"children":8905},{"style":367},[8906],{"type":21,"value":8869},{"type":15,"tag":360,"props":8908,"children":8909},{"style":400},[8910],{"type":21,"value":8911}," \".  \"",{"type":15,"tag":360,"props":8913,"children":8914},{"style":367},[8915],{"type":21,"value":6494},{"type":15,"tag":360,"props":8917,"children":8918},{"style":373},[8919],{"type":21,"value":386},{"type":15,"tag":360,"props":8921,"children":8922},{"style":389},[8923],{"type":21,"value":1444},{"type":15,"tag":360,"props":8925,"children":8926},{"style":373},[8927],{"type":21,"value":397},{"type":15,"tag":360,"props":8929,"children":8930},{"style":400},[8931],{"type":21,"value":1477},{"type":15,"tag":360,"props":8933,"children":8934},{"style":373},[8935],{"type":21,"value":3594},{"type":15,"tag":360,"props":8937,"children":8938},{"style":367},[8939],{"type":21,"value":2909},{"type":15,"tag":360,"props":8941,"children":8942},{"style":400},[8943],{"type":21,"value":8944}," \"/\"\n",{"type":15,"tag":360,"props":8946,"children":8947},{"class":362,"line":773},[8948,8952,8956,8960,8964,8968],{"type":15,"tag":360,"props":8949,"children":8950},{"style":367},[8951],{"type":21,"value":8869},{"type":15,"tag":360,"props":8953,"children":8954},{"style":373},[8955],{"type":21,"value":386},{"type":15,"tag":360,"props":8957,"children":8958},{"style":389},[8959],{"type":21,"value":1444},{"type":15,"tag":360,"props":8961,"children":8962},{"style":373},[8963],{"type":21,"value":397},{"type":15,"tag":360,"props":8965,"children":8966},{"style":400},[8967],{"type":21,"value":1501},{"type":15,"tag":360,"props":8969,"children":8970},{"style":373},[8971],{"type":21,"value":1972},{"type":15,"tag":360,"props":8973,"children":8974},{"class":362,"line":1016},[8975,8979],{"type":15,"tag":360,"props":8976,"children":8977},{"style":367},[8978],{"type":21,"value":8869},{"type":15,"tag":360,"props":8980,"children":8981},{"style":400},[8982],{"type":21,"value":8983}," \" failed.  Investigate before retrying.\"\n",{"type":15,"tag":360,"props":8985,"children":8986},{"class":362,"line":1024},[8987],{"type":15,"tag":360,"props":8988,"children":8989},{"style":373},[8990],{"type":21,"value":944},{"type":15,"tag":360,"props":8992,"children":8993},{"class":362,"line":1040},[8994],{"type":15,"tag":360,"props":8995,"children":8996},{"emptyLinePlaceholder":839},[8997],{"type":21,"value":842},{"type":15,"tag":360,"props":8999,"children":9000},{"class":362,"line":1056},[9001],{"type":15,"tag":360,"props":9002,"children":9003},{"style":486},[9004],{"type":21,"value":9005},"// Optionally page on-call via your incident management webhook\n",{"type":15,"tag":360,"props":9007,"children":9008},{"class":362,"line":1072},[9009,9013,9017],{"type":15,"tag":360,"props":9010,"children":9011},{"style":373},[9012],{"type":21,"value":1234},{"type":15,"tag":360,"props":9014,"children":9015},{"style":389},[9016],{"type":21,"value":7232},{"type":15,"tag":360,"props":9018,"children":9019},{"style":373},[9020],{"type":21,"value":905},{"type":15,"tag":360,"props":9022,"children":9023},{"class":362,"line":5296},[9024,9028,9032],{"type":15,"tag":360,"props":9025,"children":9026},{"style":373},[9027],{"type":21,"value":7244},{"type":15,"tag":360,"props":9029,"children":9030},{"style":400},[9031],{"type":21,"value":7249},{"type":15,"tag":360,"props":9033,"children":9034},{"style":373},[9035],{"type":21,"value":923},{"type":15,"tag":360,"props":9037,"children":9038},{"class":362,"line":5319},[9039,9044,9048,9052,9057],{"type":15,"tag":360,"props":9040,"children":9041},{"style":373},[9042],{"type":21,"value":9043},"    url:    context.",{"type":15,"tag":360,"props":9045,"children":9046},{"style":389},[9047],{"type":21,"value":7187},{"type":15,"tag":360,"props":9049,"children":9050},{"style":373},[9051],{"type":21,"value":397},{"type":15,"tag":360,"props":9053,"children":9054},{"style":400},[9055],{"type":21,"value":9056},"\"pagerduty_webhook\"",{"type":15,"tag":360,"props":9058,"children":9059},{"style":373},[9060],{"type":21,"value":1270},{"type":15,"tag":360,"props":9062,"children":9063},{"class":362,"line":5336},[9064],{"type":15,"tag":360,"props":9065,"children":9066},{"style":373},[9067],{"type":21,"value":7332},{"type":15,"tag":360,"props":9069,"children":9070},{"class":362,"line":5359},[9071,9076,9081],{"type":15,"tag":360,"props":9072,"children":9073},{"style":373},[9074],{"type":21,"value":9075},"        severity: ",{"type":15,"tag":360,"props":9077,"children":9078},{"style":400},[9079],{"type":21,"value":9080},"\"critical\"",{"type":15,"tag":360,"props":9082,"children":9083},{"style":373},[9084],{"type":21,"value":923},{"type":15,"tag":360,"props":9086,"children":9087},{"class":362,"line":5413},[9088,9093,9098,9102],{"type":15,"tag":360,"props":9089,"children":9090},{"style":373},[9091],{"type":21,"value":9092},"        summary:  ",{"type":15,"tag":360,"props":9094,"children":9095},{"style":400},[9096],{"type":21,"value":9097},"\"Order processing failed: cycle \"",{"type":15,"tag":360,"props":9099,"children":9100},{"style":367},[9101],{"type":21,"value":6494},{"type":15,"tag":360,"props":9103,"children":9104},{"style":373},[9105],{"type":21,"value":9106}," cycleId\n",{"type":15,"tag":360,"props":9108,"children":9109},{"class":362,"line":5421},[9110],{"type":15,"tag":360,"props":9111,"children":9112},{"style":373},[9113],{"type":21,"value":498},{"type":15,"tag":360,"props":9115,"children":9116},{"class":362,"line":5430},[9117],{"type":15,"tag":360,"props":9118,"children":9119},{"style":373},[9120],{"type":21,"value":944},{"type":15,"tag":24,"props":9122,"children":9123},{},[9124,9126,9131],{"type":21,"value":9125},"The three finalizers give each outcome ",{"type":15,"tag":30,"props":9127,"children":9128},{},[9129],{"type":21,"value":9130},"distinct, useful behavior",{"type":21,"value":9132},". Happy path just logs. Partial logs and queues for review. Total failure pages someone. This is the entire point of having three hooks.",{"type":15,"tag":2164,"props":9134,"children":9135},{},[9136],{"type":15,"tag":24,"props":9137,"children":9138},{},[9139,9144,9146,9151,9153,9159],{"type":15,"tag":30,"props":9140,"children":9141},{},[9142],{"type":21,"value":9143},"Pattern:",{"type":21,"value":9145}," If your post-processing logic is largely shared and only the messaging differs, point all three hooks at the ",{"type":15,"tag":2248,"props":9147,"children":9148},{},[9149],{"type":21,"value":9150},"same",{"type":21,"value":9152}," action and switch on ",{"type":15,"tag":254,"props":9154,"children":9156},{"className":9155},[],[9157],{"type":21,"value":9158},"context.getInput(\"state\")",{"type":21,"value":9160}," inside it. Use three separate finalizers when each branch does substantially different work.",{"type":15,"tag":805,"props":9162,"children":9163},{},[],{"type":15,"tag":325,"props":9165,"children":9167},{"id":9166},"use-case-4-aggregation-with-reduce-storage-audit",[9168],{"type":21,"value":9169},"Use Case 4: Aggregation with REDUCE — Storage Audit",{"type":15,"tag":24,"props":9171,"children":9172},{},[9173,9177],{"type":15,"tag":30,"props":9174,"children":9175},{},[9176],{"type":21,"value":5021},{"type":21,"value":9178}," Once a week, audit storage usage across all customers. Sum up bytes used, count files, and find the top consumers — without storing 2 million per-customer result records.",{"type":15,"tag":350,"props":9180,"children":9182},{"className":352,"code":9181,"language":354,"meta":7,"style":7},"// Action: \"weeklyStorageAudit\"\n\nlet customers = context.query(\"select c from customer c where c.active = true\");\n\nlet batch = context.createBatch({\n    onSuccess: \"storageAuditDone\",\n    results:   \"REDUCE\",\n    reducer:   \"accumulateStorageStats\",\n    reducerInitial: {\n        totalBytes:    0,\n        totalFiles:    0,\n        totalCustomers: 0,\n        topConsumers:  []           // top 10 by bytes\n    }\n});\ntry {\n    while (customers.hasNext()) {\n        batch.add(\"countCustomerStorage\", customers.next(), null);\n    }\n} finally {\n    customers.close();\n    batch.seal();\n}\n",[9183],{"type":15,"tag":254,"props":9184,"children":9185},{"__ignoreMap":7},[9186,9194,9201,9238,9245,9272,9288,9304,9321,9329,9345,9361,9377,9390,9397,9404,9415,9435,9476,9483,9498,9514,9529],{"type":15,"tag":360,"props":9187,"children":9188},{"class":362,"line":363},[9189],{"type":15,"tag":360,"props":9190,"children":9191},{"style":486},[9192],{"type":21,"value":9193},"// Action: \"weeklyStorageAudit\"\n",{"type":15,"tag":360,"props":9195,"children":9196},{"class":362,"line":411},[9197],{"type":15,"tag":360,"props":9198,"children":9199},{"emptyLinePlaceholder":839},[9200],{"type":21,"value":842},{"type":15,"tag":360,"props":9202,"children":9203},{"class":362,"line":425},[9204,9208,9213,9217,9221,9225,9229,9234],{"type":15,"tag":360,"props":9205,"children":9206},{"style":367},[9207],{"type":21,"value":370},{"type":15,"tag":360,"props":9209,"children":9210},{"style":373},[9211],{"type":21,"value":9212}," customers ",{"type":15,"tag":360,"props":9214,"children":9215},{"style":367},[9216],{"type":21,"value":381},{"type":15,"tag":360,"props":9218,"children":9219},{"style":373},[9220],{"type":21,"value":386},{"type":15,"tag":360,"props":9222,"children":9223},{"style":389},[9224],{"type":21,"value":392},{"type":15,"tag":360,"props":9226,"children":9227},{"style":373},[9228],{"type":21,"value":397},{"type":15,"tag":360,"props":9230,"children":9231},{"style":400},[9232],{"type":21,"value":9233},"\"select c from customer c where c.active = true\"",{"type":15,"tag":360,"props":9235,"children":9236},{"style":373},[9237],{"type":21,"value":408},{"type":15,"tag":360,"props":9239,"children":9240},{"class":362,"line":449},[9241],{"type":15,"tag":360,"props":9242,"children":9243},{"emptyLinePlaceholder":839},[9244],{"type":21,"value":842},{"type":15,"tag":360,"props":9246,"children":9247},{"class":362,"line":482},[9248,9252,9256,9260,9264,9268],{"type":15,"tag":360,"props":9249,"children":9250},{"style":367},[9251],{"type":21,"value":370},{"type":15,"tag":360,"props":9253,"children":9254},{"style":373},[9255],{"type":21,"value":611},{"type":15,"tag":360,"props":9257,"children":9258},{"style":367},[9259],{"type":21,"value":381},{"type":15,"tag":360,"props":9261,"children":9262},{"style":373},[9263],{"type":21,"value":386},{"type":15,"tag":360,"props":9265,"children":9266},{"style":389},[9267],{"type":21,"value":259},{"type":15,"tag":360,"props":9269,"children":9270},{"style":373},[9271],{"type":21,"value":905},{"type":15,"tag":360,"props":9273,"children":9274},{"class":362,"line":492},[9275,9279,9284],{"type":15,"tag":360,"props":9276,"children":9277},{"style":373},[9278],{"type":21,"value":913},{"type":15,"tag":360,"props":9280,"children":9281},{"style":400},[9282],{"type":21,"value":9283},"\"storageAuditDone\"",{"type":15,"tag":360,"props":9285,"children":9286},{"style":373},[9287],{"type":21,"value":923},{"type":15,"tag":360,"props":9289,"children":9290},{"class":362,"line":501},[9291,9296,9300],{"type":15,"tag":360,"props":9292,"children":9293},{"style":373},[9294],{"type":21,"value":9295},"    results:   ",{"type":15,"tag":360,"props":9297,"children":9298},{"style":400},[9299],{"type":21,"value":4318},{"type":15,"tag":360,"props":9301,"children":9302},{"style":373},[9303],{"type":21,"value":923},{"type":15,"tag":360,"props":9305,"children":9306},{"class":362,"line":519},[9307,9312,9317],{"type":15,"tag":360,"props":9308,"children":9309},{"style":373},[9310],{"type":21,"value":9311},"    reducer:   ",{"type":15,"tag":360,"props":9313,"children":9314},{"style":400},[9315],{"type":21,"value":9316},"\"accumulateStorageStats\"",{"type":15,"tag":360,"props":9318,"children":9319},{"style":373},[9320],{"type":21,"value":923},{"type":15,"tag":360,"props":9322,"children":9323},{"class":362,"line":537},[9324],{"type":15,"tag":360,"props":9325,"children":9326},{"style":373},[9327],{"type":21,"value":9328},"    reducerInitial: {\n",{"type":15,"tag":360,"props":9330,"children":9331},{"class":362,"line":773},[9332,9337,9341],{"type":15,"tag":360,"props":9333,"children":9334},{"style":373},[9335],{"type":21,"value":9336},"        totalBytes:    ",{"type":15,"tag":360,"props":9338,"children":9339},{"style":708},[9340],{"type":21,"value":4352},{"type":15,"tag":360,"props":9342,"children":9343},{"style":373},[9344],{"type":21,"value":923},{"type":15,"tag":360,"props":9346,"children":9347},{"class":362,"line":1016},[9348,9353,9357],{"type":15,"tag":360,"props":9349,"children":9350},{"style":373},[9351],{"type":21,"value":9352},"        totalFiles:    ",{"type":15,"tag":360,"props":9354,"children":9355},{"style":708},[9356],{"type":21,"value":4352},{"type":15,"tag":360,"props":9358,"children":9359},{"style":373},[9360],{"type":21,"value":923},{"type":15,"tag":360,"props":9362,"children":9363},{"class":362,"line":1024},[9364,9369,9373],{"type":15,"tag":360,"props":9365,"children":9366},{"style":373},[9367],{"type":21,"value":9368},"        totalCustomers: ",{"type":15,"tag":360,"props":9370,"children":9371},{"style":708},[9372],{"type":21,"value":4352},{"type":15,"tag":360,"props":9374,"children":9375},{"style":373},[9376],{"type":21,"value":923},{"type":15,"tag":360,"props":9378,"children":9379},{"class":362,"line":1040},[9380,9385],{"type":15,"tag":360,"props":9381,"children":9382},{"style":373},[9383],{"type":21,"value":9384},"        topConsumers:  []           ",{"type":15,"tag":360,"props":9386,"children":9387},{"style":486},[9388],{"type":21,"value":9389},"// top 10 by bytes\n",{"type":15,"tag":360,"props":9391,"children":9392},{"class":362,"line":1056},[9393],{"type":15,"tag":360,"props":9394,"children":9395},{"style":373},[9396],{"type":21,"value":498},{"type":15,"tag":360,"props":9398,"children":9399},{"class":362,"line":1072},[9400],{"type":15,"tag":360,"props":9401,"children":9402},{"style":373},[9403],{"type":21,"value":944},{"type":15,"tag":360,"props":9405,"children":9406},{"class":362,"line":5296},[9407,9411],{"type":15,"tag":360,"props":9408,"children":9409},{"style":367},[9410],{"type":21,"value":417},{"type":15,"tag":360,"props":9412,"children":9413},{"style":373},[9414],{"type":21,"value":422},{"type":15,"tag":360,"props":9416,"children":9417},{"class":362,"line":5319},[9418,9422,9427,9431],{"type":15,"tag":360,"props":9419,"children":9420},{"style":367},[9421],{"type":21,"value":431},{"type":15,"tag":360,"props":9423,"children":9424},{"style":373},[9425],{"type":21,"value":9426}," (customers.",{"type":15,"tag":360,"props":9428,"children":9429},{"style":389},[9430],{"type":21,"value":441},{"type":15,"tag":360,"props":9432,"children":9433},{"style":373},[9434],{"type":21,"value":446},{"type":15,"tag":360,"props":9436,"children":9437},{"class":362,"line":5336},[9438,9442,9446,9450,9455,9460,9464,9468,9472],{"type":15,"tag":360,"props":9439,"children":9440},{"style":373},[9441],{"type":21,"value":677},{"type":15,"tag":360,"props":9443,"children":9444},{"style":389},[9445],{"type":21,"value":682},{"type":15,"tag":360,"props":9447,"children":9448},{"style":373},[9449],{"type":21,"value":397},{"type":15,"tag":360,"props":9451,"children":9452},{"style":400},[9453],{"type":21,"value":9454},"\"countCustomerStorage\"",{"type":15,"tag":360,"props":9456,"children":9457},{"style":373},[9458],{"type":21,"value":9459},", customers.",{"type":15,"tag":360,"props":9461,"children":9462},{"style":389},[9463],{"type":21,"value":474},{"type":15,"tag":360,"props":9465,"children":9466},{"style":373},[9467],{"type":21,"value":705},{"type":15,"tag":360,"props":9469,"children":9470},{"style":708},[9471],{"type":21,"value":711},{"type":15,"tag":360,"props":9473,"children":9474},{"style":373},[9475],{"type":21,"value":408},{"type":15,"tag":360,"props":9477,"children":9478},{"class":362,"line":5359},[9479],{"type":15,"tag":360,"props":9480,"children":9481},{"style":373},[9482],{"type":21,"value":498},{"type":15,"tag":360,"props":9484,"children":9485},{"class":362,"line":5413},[9486,9490,9494],{"type":15,"tag":360,"props":9487,"children":9488},{"style":373},[9489],{"type":21,"value":507},{"type":15,"tag":360,"props":9491,"children":9492},{"style":367},[9493],{"type":21,"value":512},{"type":15,"tag":360,"props":9495,"children":9496},{"style":373},[9497],{"type":21,"value":422},{"type":15,"tag":360,"props":9499,"children":9500},{"class":362,"line":5421},[9501,9506,9510],{"type":15,"tag":360,"props":9502,"children":9503},{"style":373},[9504],{"type":21,"value":9505},"    customers.",{"type":15,"tag":360,"props":9507,"children":9508},{"style":389},[9509],{"type":21,"value":530},{"type":15,"tag":360,"props":9511,"children":9512},{"style":373},[9513],{"type":21,"value":479},{"type":15,"tag":360,"props":9515,"children":9516},{"class":362,"line":5430},[9517,9521,9525],{"type":15,"tag":360,"props":9518,"children":9519},{"style":373},[9520],{"type":21,"value":761},{"type":15,"tag":360,"props":9522,"children":9523},{"style":389},[9524],{"type":21,"value":766},{"type":15,"tag":360,"props":9526,"children":9527},{"style":373},[9528],{"type":21,"value":479},{"type":15,"tag":360,"props":9530,"children":9531},{"class":362,"line":5439},[9532],{"type":15,"tag":360,"props":9533,"children":9534},{"style":373},[9535],{"type":21,"value":543},{"type":15,"tag":350,"props":9537,"children":9539},{"className":352,"code":9538,"language":354,"meta":7,"style":7},"// Action: \"countCustomerStorage\" — runs once per customer\nlet customer = context.getRecord();\nlet files = context.query(\n    \"select f from file f where f.customerId = ${cid}\",\n    { cid: customer.get(\"id\") });\nlet bytes = 0;\nlet fileCount = 0;\ntry {\n    while (files.hasNext()) {\n        let file = files.next();\n        bytes += file.get(\"size\");\n        fileCount++;\n    }\n} finally {\n    files.close();\n}\n\ncontext.return({\n    customerId: customer.get(\"id\"),\n    bytes:      bytes,\n    files:      fileCount\n});\n",[9540],{"type":15,"tag":254,"props":9541,"children":9542},{"__ignoreMap":7},[9543,9551,9579,9607,9619,9643,9668,9692,9703,9723,9752,9787,9804,9811,9826,9842,9849,9856,9871,9894,9902,9910],{"type":15,"tag":360,"props":9544,"children":9545},{"class":362,"line":363},[9546],{"type":15,"tag":360,"props":9547,"children":9548},{"style":486},[9549],{"type":21,"value":9550},"// Action: \"countCustomerStorage\" — runs once per customer\n",{"type":15,"tag":360,"props":9552,"children":9553},{"class":362,"line":411},[9554,9558,9563,9567,9571,9575],{"type":15,"tag":360,"props":9555,"children":9556},{"style":367},[9557],{"type":21,"value":370},{"type":15,"tag":360,"props":9559,"children":9560},{"style":373},[9561],{"type":21,"value":9562}," customer ",{"type":15,"tag":360,"props":9564,"children":9565},{"style":367},[9566],{"type":21,"value":381},{"type":15,"tag":360,"props":9568,"children":9569},{"style":373},[9570],{"type":21,"value":386},{"type":15,"tag":360,"props":9572,"children":9573},{"style":389},[9574],{"type":21,"value":1216},{"type":15,"tag":360,"props":9576,"children":9577},{"style":373},[9578],{"type":21,"value":479},{"type":15,"tag":360,"props":9580,"children":9581},{"class":362,"line":425},[9582,9586,9591,9595,9599,9603],{"type":15,"tag":360,"props":9583,"children":9584},{"style":367},[9585],{"type":21,"value":370},{"type":15,"tag":360,"props":9587,"children":9588},{"style":373},[9589],{"type":21,"value":9590}," files ",{"type":15,"tag":360,"props":9592,"children":9593},{"style":367},[9594],{"type":21,"value":381},{"type":15,"tag":360,"props":9596,"children":9597},{"style":373},[9598],{"type":21,"value":386},{"type":15,"tag":360,"props":9600,"children":9601},{"style":389},[9602],{"type":21,"value":392},{"type":15,"tag":360,"props":9604,"children":9605},{"style":373},[9606],{"type":21,"value":5126},{"type":15,"tag":360,"props":9608,"children":9609},{"class":362,"line":449},[9610,9615],{"type":15,"tag":360,"props":9611,"children":9612},{"style":400},[9613],{"type":21,"value":9614},"    \"select f from file f where f.customerId = ${cid}\"",{"type":15,"tag":360,"props":9616,"children":9617},{"style":373},[9618],{"type":21,"value":923},{"type":15,"tag":360,"props":9620,"children":9621},{"class":362,"line":482},[9622,9627,9631,9635,9639],{"type":15,"tag":360,"props":9623,"children":9624},{"style":373},[9625],{"type":21,"value":9626},"    { cid: customer.",{"type":15,"tag":360,"props":9628,"children":9629},{"style":389},[9630],{"type":21,"value":1256},{"type":15,"tag":360,"props":9632,"children":9633},{"style":373},[9634],{"type":21,"value":397},{"type":15,"tag":360,"props":9636,"children":9637},{"style":400},[9638],{"type":21,"value":1967},{"type":15,"tag":360,"props":9640,"children":9641},{"style":373},[9642],{"type":21,"value":5189},{"type":15,"tag":360,"props":9644,"children":9645},{"class":362,"line":492},[9646,9650,9655,9659,9663],{"type":15,"tag":360,"props":9647,"children":9648},{"style":367},[9649],{"type":21,"value":370},{"type":15,"tag":360,"props":9651,"children":9652},{"style":373},[9653],{"type":21,"value":9654}," bytes ",{"type":15,"tag":360,"props":9656,"children":9657},{"style":367},[9658],{"type":21,"value":381},{"type":15,"tag":360,"props":9660,"children":9661},{"style":708},[9662],{"type":21,"value":3604},{"type":15,"tag":360,"props":9664,"children":9665},{"style":373},[9666],{"type":21,"value":9667},";\n",{"type":15,"tag":360,"props":9669,"children":9670},{"class":362,"line":501},[9671,9675,9680,9684,9688],{"type":15,"tag":360,"props":9672,"children":9673},{"style":367},[9674],{"type":21,"value":370},{"type":15,"tag":360,"props":9676,"children":9677},{"style":373},[9678],{"type":21,"value":9679}," fileCount ",{"type":15,"tag":360,"props":9681,"children":9682},{"style":367},[9683],{"type":21,"value":381},{"type":15,"tag":360,"props":9685,"children":9686},{"style":708},[9687],{"type":21,"value":3604},{"type":15,"tag":360,"props":9689,"children":9690},{"style":373},[9691],{"type":21,"value":9667},{"type":15,"tag":360,"props":9693,"children":9694},{"class":362,"line":519},[9695,9699],{"type":15,"tag":360,"props":9696,"children":9697},{"style":367},[9698],{"type":21,"value":417},{"type":15,"tag":360,"props":9700,"children":9701},{"style":373},[9702],{"type":21,"value":422},{"type":15,"tag":360,"props":9704,"children":9705},{"class":362,"line":537},[9706,9710,9715,9719],{"type":15,"tag":360,"props":9707,"children":9708},{"style":367},[9709],{"type":21,"value":431},{"type":15,"tag":360,"props":9711,"children":9712},{"style":373},[9713],{"type":21,"value":9714}," (files.",{"type":15,"tag":360,"props":9716,"children":9717},{"style":389},[9718],{"type":21,"value":441},{"type":15,"tag":360,"props":9720,"children":9721},{"style":373},[9722],{"type":21,"value":446},{"type":15,"tag":360,"props":9724,"children":9725},{"class":362,"line":773},[9726,9730,9735,9739,9744,9748],{"type":15,"tag":360,"props":9727,"children":9728},{"style":367},[9729],{"type":21,"value":455},{"type":15,"tag":360,"props":9731,"children":9732},{"style":373},[9733],{"type":21,"value":9734}," file ",{"type":15,"tag":360,"props":9736,"children":9737},{"style":367},[9738],{"type":21,"value":381},{"type":15,"tag":360,"props":9740,"children":9741},{"style":373},[9742],{"type":21,"value":9743}," files.",{"type":15,"tag":360,"props":9745,"children":9746},{"style":389},[9747],{"type":21,"value":474},{"type":15,"tag":360,"props":9749,"children":9750},{"style":373},[9751],{"type":21,"value":479},{"type":15,"tag":360,"props":9753,"children":9754},{"class":362,"line":1016},[9755,9760,9765,9770,9774,9778,9783],{"type":15,"tag":360,"props":9756,"children":9757},{"style":373},[9758],{"type":21,"value":9759},"        bytes ",{"type":15,"tag":360,"props":9761,"children":9762},{"style":367},[9763],{"type":21,"value":9764},"+=",{"type":15,"tag":360,"props":9766,"children":9767},{"style":373},[9768],{"type":21,"value":9769}," file.",{"type":15,"tag":360,"props":9771,"children":9772},{"style":389},[9773],{"type":21,"value":1256},{"type":15,"tag":360,"props":9775,"children":9776},{"style":373},[9777],{"type":21,"value":397},{"type":15,"tag":360,"props":9779,"children":9780},{"style":400},[9781],{"type":21,"value":9782},"\"size\"",{"type":15,"tag":360,"props":9784,"children":9785},{"style":373},[9786],{"type":21,"value":408},{"type":15,"tag":360,"props":9788,"children":9789},{"class":362,"line":1024},[9790,9795,9800],{"type":15,"tag":360,"props":9791,"children":9792},{"style":373},[9793],{"type":21,"value":9794},"        fileCount",{"type":15,"tag":360,"props":9796,"children":9797},{"style":367},[9798],{"type":21,"value":9799},"++",{"type":15,"tag":360,"props":9801,"children":9802},{"style":373},[9803],{"type":21,"value":9667},{"type":15,"tag":360,"props":9805,"children":9806},{"class":362,"line":1040},[9807],{"type":15,"tag":360,"props":9808,"children":9809},{"style":373},[9810],{"type":21,"value":498},{"type":15,"tag":360,"props":9812,"children":9813},{"class":362,"line":1056},[9814,9818,9822],{"type":15,"tag":360,"props":9815,"children":9816},{"style":373},[9817],{"type":21,"value":507},{"type":15,"tag":360,"props":9819,"children":9820},{"style":367},[9821],{"type":21,"value":512},{"type":15,"tag":360,"props":9823,"children":9824},{"style":373},[9825],{"type":21,"value":422},{"type":15,"tag":360,"props":9827,"children":9828},{"class":362,"line":1072},[9829,9834,9838],{"type":15,"tag":360,"props":9830,"children":9831},{"style":373},[9832],{"type":21,"value":9833},"    files.",{"type":15,"tag":360,"props":9835,"children":9836},{"style":389},[9837],{"type":21,"value":530},{"type":15,"tag":360,"props":9839,"children":9840},{"style":373},[9841],{"type":21,"value":479},{"type":15,"tag":360,"props":9843,"children":9844},{"class":362,"line":5296},[9845],{"type":15,"tag":360,"props":9846,"children":9847},{"style":373},[9848],{"type":21,"value":543},{"type":15,"tag":360,"props":9850,"children":9851},{"class":362,"line":5319},[9852],{"type":15,"tag":360,"props":9853,"children":9854},{"emptyLinePlaceholder":839},[9855],{"type":21,"value":842},{"type":15,"tag":360,"props":9857,"children":9858},{"class":362,"line":5336},[9859,9863,9867],{"type":15,"tag":360,"props":9860,"children":9861},{"style":373},[9862],{"type":21,"value":1234},{"type":15,"tag":360,"props":9864,"children":9865},{"style":389},[9866],{"type":21,"value":4485},{"type":15,"tag":360,"props":9868,"children":9869},{"style":373},[9870],{"type":21,"value":905},{"type":15,"tag":360,"props":9872,"children":9873},{"class":362,"line":5359},[9874,9878,9882,9886,9890],{"type":15,"tag":360,"props":9875,"children":9876},{"style":373},[9877],{"type":21,"value":6196},{"type":15,"tag":360,"props":9879,"children":9880},{"style":389},[9881],{"type":21,"value":1256},{"type":15,"tag":360,"props":9883,"children":9884},{"style":373},[9885],{"type":21,"value":397},{"type":15,"tag":360,"props":9887,"children":9888},{"style":400},[9889],{"type":21,"value":1967},{"type":15,"tag":360,"props":9891,"children":9892},{"style":373},[9893],{"type":21,"value":1270},{"type":15,"tag":360,"props":9895,"children":9896},{"class":362,"line":5413},[9897],{"type":15,"tag":360,"props":9898,"children":9899},{"style":373},[9900],{"type":21,"value":9901},"    bytes:      bytes,\n",{"type":15,"tag":360,"props":9903,"children":9904},{"class":362,"line":5421},[9905],{"type":15,"tag":360,"props":9906,"children":9907},{"style":373},[9908],{"type":21,"value":9909},"    files:      fileCount\n",{"type":15,"tag":360,"props":9911,"children":9912},{"class":362,"line":5430},[9913],{"type":15,"tag":360,"props":9914,"children":9915},{"style":373},[9916],{"type":21,"value":944},{"type":15,"tag":350,"props":9918,"children":9920},{"className":352,"code":9919,"language":354,"meta":7,"style":7},"// Action: \"accumulateStorageStats\" — REDUCER (must be pure!)\nlet acc    = context.getInput(\"accumulator\");\nlet result = context.getInput(\"result\");\n\n// Maintain top-10 list\nlet top = acc.get(\"topConsumers\");\ntop.push({ customerId: result.get(\"customerId\"), bytes: result.get(\"bytes\") });\ntop.sort(function(a, b) { return b.bytes - a.bytes; });\nif (top.length > 10) top = top.slice(0, 10);\n\ncontext.return({\n    totalBytes:     acc.get(\"totalBytes\") + result.get(\"bytes\"),\n    totalFiles:     acc.get(\"totalFiles\") + result.get(\"files\"),\n    totalCustomers: acc.get(\"totalCustomers\") + 1,\n    topConsumers:   top\n});\n",[9921],{"type":15,"tag":254,"props":9922,"children":9923},{"__ignoreMap":7},[9924,9932,9968,10003,10010,10018,10056,10108,10170,10235,10242,10257,10305,10355,10393,10401],{"type":15,"tag":360,"props":9925,"children":9926},{"class":362,"line":363},[9927],{"type":15,"tag":360,"props":9928,"children":9929},{"style":486},[9930],{"type":21,"value":9931},"// Action: \"accumulateStorageStats\" — REDUCER (must be pure!)\n",{"type":15,"tag":360,"props":9933,"children":9934},{"class":362,"line":411},[9935,9939,9944,9948,9952,9956,9960,9964],{"type":15,"tag":360,"props":9936,"children":9937},{"style":367},[9938],{"type":21,"value":370},{"type":15,"tag":360,"props":9940,"children":9941},{"style":373},[9942],{"type":21,"value":9943}," acc    ",{"type":15,"tag":360,"props":9945,"children":9946},{"style":367},[9947],{"type":21,"value":381},{"type":15,"tag":360,"props":9949,"children":9950},{"style":373},[9951],{"type":21,"value":386},{"type":15,"tag":360,"props":9953,"children":9954},{"style":389},[9955],{"type":21,"value":1444},{"type":15,"tag":360,"props":9957,"children":9958},{"style":373},[9959],{"type":21,"value":397},{"type":15,"tag":360,"props":9961,"children":9962},{"style":400},[9963],{"type":21,"value":4426},{"type":15,"tag":360,"props":9965,"children":9966},{"style":373},[9967],{"type":21,"value":408},{"type":15,"tag":360,"props":9969,"children":9970},{"class":362,"line":425},[9971,9975,9979,9983,9987,9991,9995,9999],{"type":15,"tag":360,"props":9972,"children":9973},{"style":367},[9974],{"type":21,"value":370},{"type":15,"tag":360,"props":9976,"children":9977},{"style":373},[9978],{"type":21,"value":376},{"type":15,"tag":360,"props":9980,"children":9981},{"style":367},[9982],{"type":21,"value":381},{"type":15,"tag":360,"props":9984,"children":9985},{"style":373},[9986],{"type":21,"value":386},{"type":15,"tag":360,"props":9988,"children":9989},{"style":389},[9990],{"type":21,"value":1444},{"type":15,"tag":360,"props":9992,"children":9993},{"style":373},[9994],{"type":21,"value":397},{"type":15,"tag":360,"props":9996,"children":9997},{"style":400},[9998],{"type":21,"value":4156},{"type":15,"tag":360,"props":10000,"children":10001},{"style":373},[10002],{"type":21,"value":408},{"type":15,"tag":360,"props":10004,"children":10005},{"class":362,"line":449},[10006],{"type":15,"tag":360,"props":10007,"children":10008},{"emptyLinePlaceholder":839},[10009],{"type":21,"value":842},{"type":15,"tag":360,"props":10011,"children":10012},{"class":362,"line":482},[10013],{"type":15,"tag":360,"props":10014,"children":10015},{"style":486},[10016],{"type":21,"value":10017},"// Maintain top-10 list\n",{"type":15,"tag":360,"props":10019,"children":10020},{"class":362,"line":492},[10021,10025,10030,10034,10039,10043,10047,10052],{"type":15,"tag":360,"props":10022,"children":10023},{"style":367},[10024],{"type":21,"value":370},{"type":15,"tag":360,"props":10026,"children":10027},{"style":373},[10028],{"type":21,"value":10029}," top ",{"type":15,"tag":360,"props":10031,"children":10032},{"style":367},[10033],{"type":21,"value":381},{"type":15,"tag":360,"props":10035,"children":10036},{"style":373},[10037],{"type":21,"value":10038}," acc.",{"type":15,"tag":360,"props":10040,"children":10041},{"style":389},[10042],{"type":21,"value":1256},{"type":15,"tag":360,"props":10044,"children":10045},{"style":373},[10046],{"type":21,"value":397},{"type":15,"tag":360,"props":10048,"children":10049},{"style":400},[10050],{"type":21,"value":10051},"\"topConsumers\"",{"type":15,"tag":360,"props":10053,"children":10054},{"style":373},[10055],{"type":21,"value":408},{"type":15,"tag":360,"props":10057,"children":10058},{"class":362,"line":501},[10059,10064,10069,10074,10078,10082,10087,10092,10096,10100,10104],{"type":15,"tag":360,"props":10060,"children":10061},{"style":373},[10062],{"type":21,"value":10063},"top.",{"type":15,"tag":360,"props":10065,"children":10066},{"style":389},[10067],{"type":21,"value":10068},"push",{"type":15,"tag":360,"props":10070,"children":10071},{"style":373},[10072],{"type":21,"value":10073},"({ customerId: result.",{"type":15,"tag":360,"props":10075,"children":10076},{"style":389},[10077],{"type":21,"value":1256},{"type":15,"tag":360,"props":10079,"children":10080},{"style":373},[10081],{"type":21,"value":397},{"type":15,"tag":360,"props":10083,"children":10084},{"style":400},[10085],{"type":21,"value":10086},"\"customerId\"",{"type":15,"tag":360,"props":10088,"children":10089},{"style":373},[10090],{"type":21,"value":10091},"), bytes: result.",{"type":15,"tag":360,"props":10093,"children":10094},{"style":389},[10095],{"type":21,"value":1256},{"type":15,"tag":360,"props":10097,"children":10098},{"style":373},[10099],{"type":21,"value":397},{"type":15,"tag":360,"props":10101,"children":10102},{"style":400},[10103],{"type":21,"value":4536},{"type":15,"tag":360,"props":10105,"children":10106},{"style":373},[10107],{"type":21,"value":5189},{"type":15,"tag":360,"props":10109,"children":10110},{"class":362,"line":519},[10111,10115,10120,10124,10128,10132,10137,10141,10146,10151,10155,10160,10165],{"type":15,"tag":360,"props":10112,"children":10113},{"style":373},[10114],{"type":21,"value":10063},{"type":15,"tag":360,"props":10116,"children":10117},{"style":389},[10118],{"type":21,"value":10119},"sort",{"type":15,"tag":360,"props":10121,"children":10122},{"style":373},[10123],{"type":21,"value":397},{"type":15,"tag":360,"props":10125,"children":10126},{"style":367},[10127],{"type":21,"value":3700},{"type":15,"tag":360,"props":10129,"children":10130},{"style":373},[10131],{"type":21,"value":397},{"type":15,"tag":360,"props":10133,"children":10134},{"style":3707},[10135],{"type":21,"value":10136},"a",{"type":15,"tag":360,"props":10138,"children":10139},{"style":373},[10140],{"type":21,"value":1348},{"type":15,"tag":360,"props":10142,"children":10143},{"style":3707},[10144],{"type":21,"value":10145},"b",{"type":15,"tag":360,"props":10147,"children":10148},{"style":373},[10149],{"type":21,"value":10150},") { ",{"type":15,"tag":360,"props":10152,"children":10153},{"style":367},[10154],{"type":21,"value":4485},{"type":15,"tag":360,"props":10156,"children":10157},{"style":373},[10158],{"type":21,"value":10159}," b.bytes ",{"type":15,"tag":360,"props":10161,"children":10162},{"style":367},[10163],{"type":21,"value":10164},"-",{"type":15,"tag":360,"props":10166,"children":10167},{"style":373},[10168],{"type":21,"value":10169}," a.bytes; });\n",{"type":15,"tag":360,"props":10171,"children":10172},{"class":362,"line":537},[10173,10177,10182,10187,10192,10197,10202,10206,10211,10215,10219,10223,10227,10231],{"type":15,"tag":360,"props":10174,"children":10175},{"style":367},[10176],{"type":21,"value":3572},{"type":15,"tag":360,"props":10178,"children":10179},{"style":373},[10180],{"type":21,"value":10181}," (top.",{"type":15,"tag":360,"props":10183,"children":10184},{"style":708},[10185],{"type":21,"value":10186},"length",{"type":15,"tag":360,"props":10188,"children":10189},{"style":367},[10190],{"type":21,"value":10191}," >",{"type":15,"tag":360,"props":10193,"children":10194},{"style":708},[10195],{"type":21,"value":10196}," 10",{"type":15,"tag":360,"props":10198,"children":10199},{"style":373},[10200],{"type":21,"value":10201},") top ",{"type":15,"tag":360,"props":10203,"children":10204},{"style":367},[10205],{"type":21,"value":381},{"type":15,"tag":360,"props":10207,"children":10208},{"style":373},[10209],{"type":21,"value":10210}," top.",{"type":15,"tag":360,"props":10212,"children":10213},{"style":389},[10214],{"type":21,"value":6936},{"type":15,"tag":360,"props":10216,"children":10217},{"style":373},[10218],{"type":21,"value":397},{"type":15,"tag":360,"props":10220,"children":10221},{"style":708},[10222],{"type":21,"value":4352},{"type":15,"tag":360,"props":10224,"children":10225},{"style":373},[10226],{"type":21,"value":1348},{"type":15,"tag":360,"props":10228,"children":10229},{"style":708},[10230],{"type":21,"value":3137},{"type":15,"tag":360,"props":10232,"children":10233},{"style":373},[10234],{"type":21,"value":408},{"type":15,"tag":360,"props":10236,"children":10237},{"class":362,"line":773},[10238],{"type":15,"tag":360,"props":10239,"children":10240},{"emptyLinePlaceholder":839},[10241],{"type":21,"value":842},{"type":15,"tag":360,"props":10243,"children":10244},{"class":362,"line":1016},[10245,10249,10253],{"type":15,"tag":360,"props":10246,"children":10247},{"style":373},[10248],{"type":21,"value":1234},{"type":15,"tag":360,"props":10250,"children":10251},{"style":389},[10252],{"type":21,"value":4485},{"type":15,"tag":360,"props":10254,"children":10255},{"style":373},[10256],{"type":21,"value":905},{"type":15,"tag":360,"props":10258,"children":10259},{"class":362,"line":1024},[10260,10265,10269,10273,10277,10281,10285,10289,10293,10297,10301],{"type":15,"tag":360,"props":10261,"children":10262},{"style":373},[10263],{"type":21,"value":10264},"    totalBytes:     acc.",{"type":15,"tag":360,"props":10266,"children":10267},{"style":389},[10268],{"type":21,"value":1256},{"type":15,"tag":360,"props":10270,"children":10271},{"style":373},[10272],{"type":21,"value":397},{"type":15,"tag":360,"props":10274,"children":10275},{"style":400},[10276],{"type":21,"value":4510},{"type":15,"tag":360,"props":10278,"children":10279},{"style":373},[10280],{"type":21,"value":3594},{"type":15,"tag":360,"props":10282,"children":10283},{"style":367},[10284],{"type":21,"value":2909},{"type":15,"tag":360,"props":10286,"children":10287},{"style":373},[10288],{"type":21,"value":469},{"type":15,"tag":360,"props":10290,"children":10291},{"style":389},[10292],{"type":21,"value":1256},{"type":15,"tag":360,"props":10294,"children":10295},{"style":373},[10296],{"type":21,"value":397},{"type":15,"tag":360,"props":10298,"children":10299},{"style":400},[10300],{"type":21,"value":4536},{"type":15,"tag":360,"props":10302,"children":10303},{"style":373},[10304],{"type":21,"value":1270},{"type":15,"tag":360,"props":10306,"children":10307},{"class":362,"line":1040},[10308,10313,10317,10321,10326,10330,10334,10338,10342,10346,10351],{"type":15,"tag":360,"props":10309,"children":10310},{"style":373},[10311],{"type":21,"value":10312},"    totalFiles:     acc.",{"type":15,"tag":360,"props":10314,"children":10315},{"style":389},[10316],{"type":21,"value":1256},{"type":15,"tag":360,"props":10318,"children":10319},{"style":373},[10320],{"type":21,"value":397},{"type":15,"tag":360,"props":10322,"children":10323},{"style":400},[10324],{"type":21,"value":10325},"\"totalFiles\"",{"type":15,"tag":360,"props":10327,"children":10328},{"style":373},[10329],{"type":21,"value":3594},{"type":15,"tag":360,"props":10331,"children":10332},{"style":367},[10333],{"type":21,"value":2909},{"type":15,"tag":360,"props":10335,"children":10336},{"style":373},[10337],{"type":21,"value":469},{"type":15,"tag":360,"props":10339,"children":10340},{"style":389},[10341],{"type":21,"value":1256},{"type":15,"tag":360,"props":10343,"children":10344},{"style":373},[10345],{"type":21,"value":397},{"type":15,"tag":360,"props":10347,"children":10348},{"style":400},[10349],{"type":21,"value":10350},"\"files\"",{"type":15,"tag":360,"props":10352,"children":10353},{"style":373},[10354],{"type":21,"value":1270},{"type":15,"tag":360,"props":10356,"children":10357},{"class":362,"line":1056},[10358,10363,10367,10371,10376,10380,10384,10389],{"type":15,"tag":360,"props":10359,"children":10360},{"style":373},[10361],{"type":21,"value":10362},"    totalCustomers: acc.",{"type":15,"tag":360,"props":10364,"children":10365},{"style":389},[10366],{"type":21,"value":1256},{"type":15,"tag":360,"props":10368,"children":10369},{"style":373},[10370],{"type":21,"value":397},{"type":15,"tag":360,"props":10372,"children":10373},{"style":400},[10374],{"type":21,"value":10375},"\"totalCustomers\"",{"type":15,"tag":360,"props":10377,"children":10378},{"style":373},[10379],{"type":21,"value":3594},{"type":15,"tag":360,"props":10381,"children":10382},{"style":367},[10383],{"type":21,"value":2909},{"type":15,"tag":360,"props":10385,"children":10386},{"style":708},[10387],{"type":21,"value":10388}," 1",{"type":15,"tag":360,"props":10390,"children":10391},{"style":373},[10392],{"type":21,"value":923},{"type":15,"tag":360,"props":10394,"children":10395},{"class":362,"line":1072},[10396],{"type":15,"tag":360,"props":10397,"children":10398},{"style":373},[10399],{"type":21,"value":10400},"    topConsumers:   top\n",{"type":15,"tag":360,"props":10402,"children":10403},{"class":362,"line":5296},[10404],{"type":15,"tag":360,"props":10405,"children":10406},{"style":373},[10407],{"type":21,"value":944},{"type":15,"tag":350,"props":10409,"children":10411},{"className":352,"code":10410,"language":354,"meta":7,"style":7},"// Action: \"storageAuditDone\"\nlet stats = context.getInput(\"reducerState\");\n\ncontext.create(\"storageReport\", {\n    runDate:        new Date(),\n    totalBytes:     stats.get(\"totalBytes\"),\n    totalFiles:     stats.get(\"totalFiles\"),\n    totalCustomers: stats.get(\"totalCustomers\"),\n    topConsumers:   JSON.stringify(stats.get(\"topConsumers\"))\n});\n",[10412],{"type":15,"tag":254,"props":10413,"children":10414},{"__ignoreMap":7},[10415,10423,10460,10467,10491,10511,10535,10559,10583,10627],{"type":15,"tag":360,"props":10416,"children":10417},{"class":362,"line":363},[10418],{"type":15,"tag":360,"props":10419,"children":10420},{"style":486},[10421],{"type":21,"value":10422},"// Action: \"storageAuditDone\"\n",{"type":15,"tag":360,"props":10424,"children":10425},{"class":362,"line":411},[10426,10430,10435,10439,10443,10447,10451,10456],{"type":15,"tag":360,"props":10427,"children":10428},{"style":367},[10429],{"type":21,"value":370},{"type":15,"tag":360,"props":10431,"children":10432},{"style":373},[10433],{"type":21,"value":10434}," stats ",{"type":15,"tag":360,"props":10436,"children":10437},{"style":367},[10438],{"type":21,"value":381},{"type":15,"tag":360,"props":10440,"children":10441},{"style":373},[10442],{"type":21,"value":386},{"type":15,"tag":360,"props":10444,"children":10445},{"style":389},[10446],{"type":21,"value":1444},{"type":15,"tag":360,"props":10448,"children":10449},{"style":373},[10450],{"type":21,"value":397},{"type":15,"tag":360,"props":10452,"children":10453},{"style":400},[10454],{"type":21,"value":10455},"\"reducerState\"",{"type":15,"tag":360,"props":10457,"children":10458},{"style":373},[10459],{"type":21,"value":408},{"type":15,"tag":360,"props":10461,"children":10462},{"class":362,"line":425},[10463],{"type":15,"tag":360,"props":10464,"children":10465},{"emptyLinePlaceholder":839},[10466],{"type":21,"value":842},{"type":15,"tag":360,"props":10468,"children":10469},{"class":362,"line":449},[10470,10474,10478,10482,10487],{"type":15,"tag":360,"props":10471,"children":10472},{"style":373},[10473],{"type":21,"value":1234},{"type":15,"tag":360,"props":10475,"children":10476},{"style":389},[10477],{"type":21,"value":6166},{"type":15,"tag":360,"props":10479,"children":10480},{"style":373},[10481],{"type":21,"value":397},{"type":15,"tag":360,"props":10483,"children":10484},{"style":400},[10485],{"type":21,"value":10486},"\"storageReport\"",{"type":15,"tag":360,"props":10488,"children":10489},{"style":373},[10490],{"type":21,"value":6180},{"type":15,"tag":360,"props":10492,"children":10493},{"class":362,"line":482},[10494,10499,10503,10507],{"type":15,"tag":360,"props":10495,"children":10496},{"style":373},[10497],{"type":21,"value":10498},"    runDate:        ",{"type":15,"tag":360,"props":10500,"children":10501},{"style":367},[10502],{"type":21,"value":6913},{"type":15,"tag":360,"props":10504,"children":10505},{"style":389},[10506],{"type":21,"value":6918},{"type":15,"tag":360,"props":10508,"children":10509},{"style":373},[10510],{"type":21,"value":7953},{"type":15,"tag":360,"props":10512,"children":10513},{"class":362,"line":492},[10514,10519,10523,10527,10531],{"type":15,"tag":360,"props":10515,"children":10516},{"style":373},[10517],{"type":21,"value":10518},"    totalBytes:     stats.",{"type":15,"tag":360,"props":10520,"children":10521},{"style":389},[10522],{"type":21,"value":1256},{"type":15,"tag":360,"props":10524,"children":10525},{"style":373},[10526],{"type":21,"value":397},{"type":15,"tag":360,"props":10528,"children":10529},{"style":400},[10530],{"type":21,"value":4510},{"type":15,"tag":360,"props":10532,"children":10533},{"style":373},[10534],{"type":21,"value":1270},{"type":15,"tag":360,"props":10536,"children":10537},{"class":362,"line":501},[10538,10543,10547,10551,10555],{"type":15,"tag":360,"props":10539,"children":10540},{"style":373},[10541],{"type":21,"value":10542},"    totalFiles:     stats.",{"type":15,"tag":360,"props":10544,"children":10545},{"style":389},[10546],{"type":21,"value":1256},{"type":15,"tag":360,"props":10548,"children":10549},{"style":373},[10550],{"type":21,"value":397},{"type":15,"tag":360,"props":10552,"children":10553},{"style":400},[10554],{"type":21,"value":10325},{"type":15,"tag":360,"props":10556,"children":10557},{"style":373},[10558],{"type":21,"value":1270},{"type":15,"tag":360,"props":10560,"children":10561},{"class":362,"line":519},[10562,10567,10571,10575,10579],{"type":15,"tag":360,"props":10563,"children":10564},{"style":373},[10565],{"type":21,"value":10566},"    totalCustomers: stats.",{"type":15,"tag":360,"props":10568,"children":10569},{"style":389},[10570],{"type":21,"value":1256},{"type":15,"tag":360,"props":10572,"children":10573},{"style":373},[10574],{"type":21,"value":397},{"type":15,"tag":360,"props":10576,"children":10577},{"style":400},[10578],{"type":21,"value":10375},{"type":15,"tag":360,"props":10580,"children":10581},{"style":373},[10582],{"type":21,"value":1270},{"type":15,"tag":360,"props":10584,"children":10585},{"class":362,"line":537},[10586,10591,10596,10600,10605,10610,10614,10618,10622],{"type":15,"tag":360,"props":10587,"children":10588},{"style":373},[10589],{"type":21,"value":10590},"    topConsumers:   ",{"type":15,"tag":360,"props":10592,"children":10593},{"style":708},[10594],{"type":21,"value":10595},"JSON",{"type":15,"tag":360,"props":10597,"children":10598},{"style":373},[10599],{"type":21,"value":1664},{"type":15,"tag":360,"props":10601,"children":10602},{"style":389},[10603],{"type":21,"value":10604},"stringify",{"type":15,"tag":360,"props":10606,"children":10607},{"style":373},[10608],{"type":21,"value":10609},"(stats.",{"type":15,"tag":360,"props":10611,"children":10612},{"style":389},[10613],{"type":21,"value":1256},{"type":15,"tag":360,"props":10615,"children":10616},{"style":373},[10617],{"type":21,"value":397},{"type":15,"tag":360,"props":10619,"children":10620},{"style":400},[10621],{"type":21,"value":10051},{"type":15,"tag":360,"props":10623,"children":10624},{"style":373},[10625],{"type":21,"value":10626},"))\n",{"type":15,"tag":360,"props":10628,"children":10629},{"class":362,"line":773},[10630],{"type":15,"tag":360,"props":10631,"children":10632},{"style":373},[10633],{"type":21,"value":944},{"type":15,"tag":24,"props":10635,"children":10636},{},[10637,10639,10644],{"type":21,"value":10638},"Memory cost is ",{"type":15,"tag":30,"props":10640,"children":10641},{},[10642],{"type":21,"value":10643},"constant",{"type":21,"value":10645}," regardless of whether you have 1,000 or 10,000,000 customers. The reducer is invoked once per child, folding the result into the running accumulator.",{"type":15,"tag":805,"props":10647,"children":10648},{},[],{"type":15,"tag":325,"props":10650,"children":10652},{"id":10651},"use-case-5-multi-tenant-fan-out-nested-batches",[10653],{"type":21,"value":10654},"Use Case 5: Multi-Tenant Fan-Out (Nested Batches)",{"type":15,"tag":24,"props":10656,"children":10657},{},[10658,10662],{"type":15,"tag":30,"props":10659,"children":10660},{},[10661],{"type":21,"value":5021},{"type":21,"value":10663}," Nightly sync for every active tenant. Each tenant has its own per-customer fan-out. We want both levels visible in the dashboards and trackable as a single hierarchy.",{"type":15,"tag":24,"props":10665,"children":10666},{},[10667,10669,10674],{"type":21,"value":10668},"A batch can launch another batch from inside one of its children. ",{"type":15,"tag":30,"props":10670,"children":10671},{},[10672],{"type":21,"value":10673},"The platform automatically wires the inner batch as a child of the outer.",{"type":21,"value":10675}," From the outer batch's point of view, the tenant's child action is \"done\" only when the inner batch reaches a terminal state.",{"type":15,"tag":350,"props":10677,"children":10679},{"className":352,"code":10678,"language":354,"meta":7,"style":7},"// Action: \"nightlySyncAllTenants\" — triggered by SCHEDULED rule\n\nlet tenants = context.query(\"select t from tenant t where t.active = true\");\nlet outer = context.createBatch({\n    onSuccess: \"allTenantsSynced\",\n    onError:   \"syncFailed\"\n});\ntry {\n    while (tenants.hasNext()) {\n        outer.add(\"syncOneTenant\", tenants.next(), null);\n    }\n} finally {\n    tenants.close();\n    outer.seal();\n}\n",[10680],{"type":15,"tag":254,"props":10681,"children":10682},{"__ignoreMap":7},[10683,10691,10698,10735,10763,10779,10791,10798,10809,10829,10871,10878,10893,10909,10925],{"type":15,"tag":360,"props":10684,"children":10685},{"class":362,"line":363},[10686],{"type":15,"tag":360,"props":10687,"children":10688},{"style":486},[10689],{"type":21,"value":10690},"// Action: \"nightlySyncAllTenants\" — triggered by SCHEDULED rule\n",{"type":15,"tag":360,"props":10692,"children":10693},{"class":362,"line":411},[10694],{"type":15,"tag":360,"props":10695,"children":10696},{"emptyLinePlaceholder":839},[10697],{"type":21,"value":842},{"type":15,"tag":360,"props":10699,"children":10700},{"class":362,"line":425},[10701,10705,10710,10714,10718,10722,10726,10731],{"type":15,"tag":360,"props":10702,"children":10703},{"style":367},[10704],{"type":21,"value":370},{"type":15,"tag":360,"props":10706,"children":10707},{"style":373},[10708],{"type":21,"value":10709}," tenants ",{"type":15,"tag":360,"props":10711,"children":10712},{"style":367},[10713],{"type":21,"value":381},{"type":15,"tag":360,"props":10715,"children":10716},{"style":373},[10717],{"type":21,"value":386},{"type":15,"tag":360,"props":10719,"children":10720},{"style":389},[10721],{"type":21,"value":392},{"type":15,"tag":360,"props":10723,"children":10724},{"style":373},[10725],{"type":21,"value":397},{"type":15,"tag":360,"props":10727,"children":10728},{"style":400},[10729],{"type":21,"value":10730},"\"select t from tenant t where t.active = true\"",{"type":15,"tag":360,"props":10732,"children":10733},{"style":373},[10734],{"type":21,"value":408},{"type":15,"tag":360,"props":10736,"children":10737},{"class":362,"line":449},[10738,10742,10747,10751,10755,10759],{"type":15,"tag":360,"props":10739,"children":10740},{"style":367},[10741],{"type":21,"value":370},{"type":15,"tag":360,"props":10743,"children":10744},{"style":373},[10745],{"type":21,"value":10746}," outer ",{"type":15,"tag":360,"props":10748,"children":10749},{"style":367},[10750],{"type":21,"value":381},{"type":15,"tag":360,"props":10752,"children":10753},{"style":373},[10754],{"type":21,"value":386},{"type":15,"tag":360,"props":10756,"children":10757},{"style":389},[10758],{"type":21,"value":259},{"type":15,"tag":360,"props":10760,"children":10761},{"style":373},[10762],{"type":21,"value":905},{"type":15,"tag":360,"props":10764,"children":10765},{"class":362,"line":482},[10766,10770,10775],{"type":15,"tag":360,"props":10767,"children":10768},{"style":373},[10769],{"type":21,"value":913},{"type":15,"tag":360,"props":10771,"children":10772},{"style":400},[10773],{"type":21,"value":10774},"\"allTenantsSynced\"",{"type":15,"tag":360,"props":10776,"children":10777},{"style":373},[10778],{"type":21,"value":923},{"type":15,"tag":360,"props":10780,"children":10781},{"class":362,"line":492},[10782,10786],{"type":15,"tag":360,"props":10783,"children":10784},{"style":373},[10785],{"type":21,"value":931},{"type":15,"tag":360,"props":10787,"children":10788},{"style":400},[10789],{"type":21,"value":10790},"\"syncFailed\"\n",{"type":15,"tag":360,"props":10792,"children":10793},{"class":362,"line":501},[10794],{"type":15,"tag":360,"props":10795,"children":10796},{"style":373},[10797],{"type":21,"value":944},{"type":15,"tag":360,"props":10799,"children":10800},{"class":362,"line":519},[10801,10805],{"type":15,"tag":360,"props":10802,"children":10803},{"style":367},[10804],{"type":21,"value":417},{"type":15,"tag":360,"props":10806,"children":10807},{"style":373},[10808],{"type":21,"value":422},{"type":15,"tag":360,"props":10810,"children":10811},{"class":362,"line":537},[10812,10816,10821,10825],{"type":15,"tag":360,"props":10813,"children":10814},{"style":367},[10815],{"type":21,"value":431},{"type":15,"tag":360,"props":10817,"children":10818},{"style":373},[10819],{"type":21,"value":10820}," (tenants.",{"type":15,"tag":360,"props":10822,"children":10823},{"style":389},[10824],{"type":21,"value":441},{"type":15,"tag":360,"props":10826,"children":10827},{"style":373},[10828],{"type":21,"value":446},{"type":15,"tag":360,"props":10830,"children":10831},{"class":362,"line":773},[10832,10837,10841,10845,10850,10855,10859,10863,10867],{"type":15,"tag":360,"props":10833,"children":10834},{"style":373},[10835],{"type":21,"value":10836},"        outer.",{"type":15,"tag":360,"props":10838,"children":10839},{"style":389},[10840],{"type":21,"value":682},{"type":15,"tag":360,"props":10842,"children":10843},{"style":373},[10844],{"type":21,"value":397},{"type":15,"tag":360,"props":10846,"children":10847},{"style":400},[10848],{"type":21,"value":10849},"\"syncOneTenant\"",{"type":15,"tag":360,"props":10851,"children":10852},{"style":373},[10853],{"type":21,"value":10854},", tenants.",{"type":15,"tag":360,"props":10856,"children":10857},{"style":389},[10858],{"type":21,"value":474},{"type":15,"tag":360,"props":10860,"children":10861},{"style":373},[10862],{"type":21,"value":705},{"type":15,"tag":360,"props":10864,"children":10865},{"style":708},[10866],{"type":21,"value":711},{"type":15,"tag":360,"props":10868,"children":10869},{"style":373},[10870],{"type":21,"value":408},{"type":15,"tag":360,"props":10872,"children":10873},{"class":362,"line":1016},[10874],{"type":15,"tag":360,"props":10875,"children":10876},{"style":373},[10877],{"type":21,"value":498},{"type":15,"tag":360,"props":10879,"children":10880},{"class":362,"line":1024},[10881,10885,10889],{"type":15,"tag":360,"props":10882,"children":10883},{"style":373},[10884],{"type":21,"value":507},{"type":15,"tag":360,"props":10886,"children":10887},{"style":367},[10888],{"type":21,"value":512},{"type":15,"tag":360,"props":10890,"children":10891},{"style":373},[10892],{"type":21,"value":422},{"type":15,"tag":360,"props":10894,"children":10895},{"class":362,"line":1040},[10896,10901,10905],{"type":15,"tag":360,"props":10897,"children":10898},{"style":373},[10899],{"type":21,"value":10900},"    tenants.",{"type":15,"tag":360,"props":10902,"children":10903},{"style":389},[10904],{"type":21,"value":530},{"type":15,"tag":360,"props":10906,"children":10907},{"style":373},[10908],{"type":21,"value":479},{"type":15,"tag":360,"props":10910,"children":10911},{"class":362,"line":1056},[10912,10917,10921],{"type":15,"tag":360,"props":10913,"children":10914},{"style":373},[10915],{"type":21,"value":10916},"    outer.",{"type":15,"tag":360,"props":10918,"children":10919},{"style":389},[10920],{"type":21,"value":766},{"type":15,"tag":360,"props":10922,"children":10923},{"style":373},[10924],{"type":21,"value":479},{"type":15,"tag":360,"props":10926,"children":10927},{"class":362,"line":1072},[10928],{"type":15,"tag":360,"props":10929,"children":10930},{"style":373},[10931],{"type":21,"value":543},{"type":15,"tag":350,"props":10933,"children":10935},{"className":352,"code":10934,"language":354,"meta":7,"style":7},"// Action: \"syncOneTenant\" — runs once per tenant\n\nlet tenant = context.getRecord();\nlet customers = context.query(\n    \"select c from customer c where c.tenantId = ${tenantId}\",\n    { tenantId: tenant.get(\"id\") });\n\n// This inner batch is automatically wired as a child of the outer batch.\n// You don't have to do anything special.\nlet inner = context.createBatch({\n    onSuccess: \"tenantSyncDone\",\n    onError:   \"tenantSyncFailed\",\n    context: { tenantId: tenant.get(\"id\") }\n});\ntry {\n    while (customers.hasNext()) {\n        inner.add(\"syncOneCustomer\", customers.next(), null);\n    }\n} finally {\n    customers.close();\n    inner.seal();\n}\n// Note: this action returns NOW, but the outer batch is told to wait\n// until the inner batch completes. Reporting back is automatic.\n",[10936],{"type":15,"tag":254,"props":10937,"children":10938},{"__ignoreMap":7},[10939,10947,10954,10982,11009,11021,11045,11052,11060,11068,11096,11112,11128,11152,11159,11170,11189,11230,11237,11252,11267,11283,11290,11298],{"type":15,"tag":360,"props":10940,"children":10941},{"class":362,"line":363},[10942],{"type":15,"tag":360,"props":10943,"children":10944},{"style":486},[10945],{"type":21,"value":10946},"// Action: \"syncOneTenant\" — runs once per tenant\n",{"type":15,"tag":360,"props":10948,"children":10949},{"class":362,"line":411},[10950],{"type":15,"tag":360,"props":10951,"children":10952},{"emptyLinePlaceholder":839},[10953],{"type":21,"value":842},{"type":15,"tag":360,"props":10955,"children":10956},{"class":362,"line":425},[10957,10961,10966,10970,10974,10978],{"type":15,"tag":360,"props":10958,"children":10959},{"style":367},[10960],{"type":21,"value":370},{"type":15,"tag":360,"props":10962,"children":10963},{"style":373},[10964],{"type":21,"value":10965}," tenant ",{"type":15,"tag":360,"props":10967,"children":10968},{"style":367},[10969],{"type":21,"value":381},{"type":15,"tag":360,"props":10971,"children":10972},{"style":373},[10973],{"type":21,"value":386},{"type":15,"tag":360,"props":10975,"children":10976},{"style":389},[10977],{"type":21,"value":1216},{"type":15,"tag":360,"props":10979,"children":10980},{"style":373},[10981],{"type":21,"value":479},{"type":15,"tag":360,"props":10983,"children":10984},{"class":362,"line":449},[10985,10989,10993,10997,11001,11005],{"type":15,"tag":360,"props":10986,"children":10987},{"style":367},[10988],{"type":21,"value":370},{"type":15,"tag":360,"props":10990,"children":10991},{"style":373},[10992],{"type":21,"value":9212},{"type":15,"tag":360,"props":10994,"children":10995},{"style":367},[10996],{"type":21,"value":381},{"type":15,"tag":360,"props":10998,"children":10999},{"style":373},[11000],{"type":21,"value":386},{"type":15,"tag":360,"props":11002,"children":11003},{"style":389},[11004],{"type":21,"value":392},{"type":15,"tag":360,"props":11006,"children":11007},{"style":373},[11008],{"type":21,"value":5126},{"type":15,"tag":360,"props":11010,"children":11011},{"class":362,"line":482},[11012,11017],{"type":15,"tag":360,"props":11013,"children":11014},{"style":400},[11015],{"type":21,"value":11016},"    \"select c from customer c where c.tenantId = ${tenantId}\"",{"type":15,"tag":360,"props":11018,"children":11019},{"style":373},[11020],{"type":21,"value":923},{"type":15,"tag":360,"props":11022,"children":11023},{"class":362,"line":492},[11024,11029,11033,11037,11041],{"type":15,"tag":360,"props":11025,"children":11026},{"style":373},[11027],{"type":21,"value":11028},"    { tenantId: tenant.",{"type":15,"tag":360,"props":11030,"children":11031},{"style":389},[11032],{"type":21,"value":1256},{"type":15,"tag":360,"props":11034,"children":11035},{"style":373},[11036],{"type":21,"value":397},{"type":15,"tag":360,"props":11038,"children":11039},{"style":400},[11040],{"type":21,"value":1967},{"type":15,"tag":360,"props":11042,"children":11043},{"style":373},[11044],{"type":21,"value":5189},{"type":15,"tag":360,"props":11046,"children":11047},{"class":362,"line":501},[11048],{"type":15,"tag":360,"props":11049,"children":11050},{"emptyLinePlaceholder":839},[11051],{"type":21,"value":842},{"type":15,"tag":360,"props":11053,"children":11054},{"class":362,"line":519},[11055],{"type":15,"tag":360,"props":11056,"children":11057},{"style":486},[11058],{"type":21,"value":11059},"// This inner batch is automatically wired as a child of the outer batch.\n",{"type":15,"tag":360,"props":11061,"children":11062},{"class":362,"line":537},[11063],{"type":15,"tag":360,"props":11064,"children":11065},{"style":486},[11066],{"type":21,"value":11067},"// You don't have to do anything special.\n",{"type":15,"tag":360,"props":11069,"children":11070},{"class":362,"line":773},[11071,11075,11080,11084,11088,11092],{"type":15,"tag":360,"props":11072,"children":11073},{"style":367},[11074],{"type":21,"value":370},{"type":15,"tag":360,"props":11076,"children":11077},{"style":373},[11078],{"type":21,"value":11079}," inner ",{"type":15,"tag":360,"props":11081,"children":11082},{"style":367},[11083],{"type":21,"value":381},{"type":15,"tag":360,"props":11085,"children":11086},{"style":373},[11087],{"type":21,"value":386},{"type":15,"tag":360,"props":11089,"children":11090},{"style":389},[11091],{"type":21,"value":259},{"type":15,"tag":360,"props":11093,"children":11094},{"style":373},[11095],{"type":21,"value":905},{"type":15,"tag":360,"props":11097,"children":11098},{"class":362,"line":1016},[11099,11103,11108],{"type":15,"tag":360,"props":11100,"children":11101},{"style":373},[11102],{"type":21,"value":913},{"type":15,"tag":360,"props":11104,"children":11105},{"style":400},[11106],{"type":21,"value":11107},"\"tenantSyncDone\"",{"type":15,"tag":360,"props":11109,"children":11110},{"style":373},[11111],{"type":21,"value":923},{"type":15,"tag":360,"props":11113,"children":11114},{"class":362,"line":1024},[11115,11119,11124],{"type":15,"tag":360,"props":11116,"children":11117},{"style":373},[11118],{"type":21,"value":931},{"type":15,"tag":360,"props":11120,"children":11121},{"style":400},[11122],{"type":21,"value":11123},"\"tenantSyncFailed\"",{"type":15,"tag":360,"props":11125,"children":11126},{"style":373},[11127],{"type":21,"value":923},{"type":15,"tag":360,"props":11129,"children":11130},{"class":362,"line":1040},[11131,11136,11140,11144,11148],{"type":15,"tag":360,"props":11132,"children":11133},{"style":373},[11134],{"type":21,"value":11135},"    context: { tenantId: tenant.",{"type":15,"tag":360,"props":11137,"children":11138},{"style":389},[11139],{"type":21,"value":1256},{"type":15,"tag":360,"props":11141,"children":11142},{"style":373},[11143],{"type":21,"value":397},{"type":15,"tag":360,"props":11145,"children":11146},{"style":400},[11147],{"type":21,"value":1967},{"type":15,"tag":360,"props":11149,"children":11150},{"style":373},[11151],{"type":21,"value":7407},{"type":15,"tag":360,"props":11153,"children":11154},{"class":362,"line":1056},[11155],{"type":15,"tag":360,"props":11156,"children":11157},{"style":373},[11158],{"type":21,"value":944},{"type":15,"tag":360,"props":11160,"children":11161},{"class":362,"line":1072},[11162,11166],{"type":15,"tag":360,"props":11163,"children":11164},{"style":367},[11165],{"type":21,"value":417},{"type":15,"tag":360,"props":11167,"children":11168},{"style":373},[11169],{"type":21,"value":422},{"type":15,"tag":360,"props":11171,"children":11172},{"class":362,"line":5296},[11173,11177,11181,11185],{"type":15,"tag":360,"props":11174,"children":11175},{"style":367},[11176],{"type":21,"value":431},{"type":15,"tag":360,"props":11178,"children":11179},{"style":373},[11180],{"type":21,"value":9426},{"type":15,"tag":360,"props":11182,"children":11183},{"style":389},[11184],{"type":21,"value":441},{"type":15,"tag":360,"props":11186,"children":11187},{"style":373},[11188],{"type":21,"value":446},{"type":15,"tag":360,"props":11190,"children":11191},{"class":362,"line":5319},[11192,11197,11201,11205,11210,11214,11218,11222,11226],{"type":15,"tag":360,"props":11193,"children":11194},{"style":373},[11195],{"type":21,"value":11196},"        inner.",{"type":15,"tag":360,"props":11198,"children":11199},{"style":389},[11200],{"type":21,"value":682},{"type":15,"tag":360,"props":11202,"children":11203},{"style":373},[11204],{"type":21,"value":397},{"type":15,"tag":360,"props":11206,"children":11207},{"style":400},[11208],{"type":21,"value":11209},"\"syncOneCustomer\"",{"type":15,"tag":360,"props":11211,"children":11212},{"style":373},[11213],{"type":21,"value":9459},{"type":15,"tag":360,"props":11215,"children":11216},{"style":389},[11217],{"type":21,"value":474},{"type":15,"tag":360,"props":11219,"children":11220},{"style":373},[11221],{"type":21,"value":705},{"type":15,"tag":360,"props":11223,"children":11224},{"style":708},[11225],{"type":21,"value":711},{"type":15,"tag":360,"props":11227,"children":11228},{"style":373},[11229],{"type":21,"value":408},{"type":15,"tag":360,"props":11231,"children":11232},{"class":362,"line":5336},[11233],{"type":15,"tag":360,"props":11234,"children":11235},{"style":373},[11236],{"type":21,"value":498},{"type":15,"tag":360,"props":11238,"children":11239},{"class":362,"line":5359},[11240,11244,11248],{"type":15,"tag":360,"props":11241,"children":11242},{"style":373},[11243],{"type":21,"value":507},{"type":15,"tag":360,"props":11245,"children":11246},{"style":367},[11247],{"type":21,"value":512},{"type":15,"tag":360,"props":11249,"children":11250},{"style":373},[11251],{"type":21,"value":422},{"type":15,"tag":360,"props":11253,"children":11254},{"class":362,"line":5413},[11255,11259,11263],{"type":15,"tag":360,"props":11256,"children":11257},{"style":373},[11258],{"type":21,"value":9505},{"type":15,"tag":360,"props":11260,"children":11261},{"style":389},[11262],{"type":21,"value":530},{"type":15,"tag":360,"props":11264,"children":11265},{"style":373},[11266],{"type":21,"value":479},{"type":15,"tag":360,"props":11268,"children":11269},{"class":362,"line":5421},[11270,11275,11279],{"type":15,"tag":360,"props":11271,"children":11272},{"style":373},[11273],{"type":21,"value":11274},"    inner.",{"type":15,"tag":360,"props":11276,"children":11277},{"style":389},[11278],{"type":21,"value":766},{"type":15,"tag":360,"props":11280,"children":11281},{"style":373},[11282],{"type":21,"value":479},{"type":15,"tag":360,"props":11284,"children":11285},{"class":362,"line":5430},[11286],{"type":15,"tag":360,"props":11287,"children":11288},{"style":373},[11289],{"type":21,"value":543},{"type":15,"tag":360,"props":11291,"children":11292},{"class":362,"line":5439},[11293],{"type":15,"tag":360,"props":11294,"children":11295},{"style":486},[11296],{"type":21,"value":11297},"// Note: this action returns NOW, but the outer batch is told to wait\n",{"type":15,"tag":360,"props":11299,"children":11300},{"class":362,"line":5447},[11301],{"type":15,"tag":360,"props":11302,"children":11303},{"style":486},[11304],{"type":21,"value":11305},"// until the inner batch completes. Reporting back is automatic.\n",{"type":15,"tag":24,"props":11307,"children":11308},{},[11309],{"type":21,"value":11310},"This pattern composes to arbitrary depth.",{"type":15,"tag":805,"props":11312,"children":11313},{},[],{"type":15,"tag":325,"props":11315,"children":11317},{"id":11316},"use-case-6-replay-just-the-failures",[11318],{"type":21,"value":11319},"Use Case 6: Replay Just the Failures",{"type":15,"tag":24,"props":11321,"children":11322},{},[11323,11327],{"type":15,"tag":30,"props":11324,"children":11325},{},[11326],{"type":21,"value":5021},{"type":21,"value":11328}," Last night's batch finished with 47 failures. The cause has been fixed. We don't want to re-run the 50,000 successful ones — just the failures.",{"type":15,"tag":24,"props":11330,"children":11331},{},[11332,11334,11339],{"type":21,"value":11333},"If you used ",{"type":15,"tag":254,"props":11335,"children":11337},{"className":11336},[],[11338],{"type":21,"value":3410},{"type":21,"value":11340}," mode, the failures are recorded in the scratchpad. Iterate them in a follow-up:",{"type":15,"tag":350,"props":11342,"children":11344},{"className":352,"code":11343,"language":354,"meta":7,"style":7},"// Action: \"retryFailedOrders\" — manually triggered\n\nlet originalDatasetId = params.datasetId;   // passed from admin UI\nlet failures = context.scratchpad.getAllRecords(originalDatasetId);\n\nlet retry = context.createBatch({\n    onSuccess: \"retryDone\",\n    onError:   \"retryFailed\",\n    context:   { reason: \"manual-retry-of-\" + originalDatasetId }\n});\ntry {\n    failures.forEach(function(rec) {\n        let originalId = rec.getRecordId();\n        let lookup = context.query(\n            \"select o from order o where o.id = ${id}\",\n            { id: originalId });\n        try {\n            if (lookup.hasNext()) {\n                retry.add(\"processOneOrder\", lookup.next(), null);\n            }\n        } finally {\n            lookup.close();\n        }\n    });\n} finally {\n    retry.seal();\n}\n",[11345],{"type":15,"tag":254,"props":11346,"children":11347},{"__ignoreMap":7},[11348,11356,11363,11389,11417,11424,11452,11468,11484,11506,11513,11524,11555,11583,11611,11623,11631,11643,11664,11705,11713,11729,11745,11753,11760,11775,11791],{"type":15,"tag":360,"props":11349,"children":11350},{"class":362,"line":363},[11351],{"type":15,"tag":360,"props":11352,"children":11353},{"style":486},[11354],{"type":21,"value":11355},"// Action: \"retryFailedOrders\" — manually triggered\n",{"type":15,"tag":360,"props":11357,"children":11358},{"class":362,"line":411},[11359],{"type":15,"tag":360,"props":11360,"children":11361},{"emptyLinePlaceholder":839},[11362],{"type":21,"value":842},{"type":15,"tag":360,"props":11364,"children":11365},{"class":362,"line":425},[11366,11370,11375,11379,11384],{"type":15,"tag":360,"props":11367,"children":11368},{"style":367},[11369],{"type":21,"value":370},{"type":15,"tag":360,"props":11371,"children":11372},{"style":373},[11373],{"type":21,"value":11374}," originalDatasetId ",{"type":15,"tag":360,"props":11376,"children":11377},{"style":367},[11378],{"type":21,"value":381},{"type":15,"tag":360,"props":11380,"children":11381},{"style":373},[11382],{"type":21,"value":11383}," params.datasetId;   ",{"type":15,"tag":360,"props":11385,"children":11386},{"style":486},[11387],{"type":21,"value":11388},"// passed from admin UI\n",{"type":15,"tag":360,"props":11390,"children":11391},{"class":362,"line":449},[11392,11396,11400,11404,11408,11412],{"type":15,"tag":360,"props":11393,"children":11394},{"style":367},[11395],{"type":21,"value":370},{"type":15,"tag":360,"props":11397,"children":11398},{"style":373},[11399],{"type":21,"value":3659},{"type":15,"tag":360,"props":11401,"children":11402},{"style":367},[11403],{"type":21,"value":381},{"type":15,"tag":360,"props":11405,"children":11406},{"style":373},[11407],{"type":21,"value":3668},{"type":15,"tag":360,"props":11409,"children":11410},{"style":389},[11411],{"type":21,"value":3673},{"type":15,"tag":360,"props":11413,"children":11414},{"style":373},[11415],{"type":21,"value":11416},"(originalDatasetId);\n",{"type":15,"tag":360,"props":11418,"children":11419},{"class":362,"line":482},[11420],{"type":15,"tag":360,"props":11421,"children":11422},{"emptyLinePlaceholder":839},[11423],{"type":21,"value":842},{"type":15,"tag":360,"props":11425,"children":11426},{"class":362,"line":492},[11427,11431,11436,11440,11444,11448],{"type":15,"tag":360,"props":11428,"children":11429},{"style":367},[11430],{"type":21,"value":370},{"type":15,"tag":360,"props":11432,"children":11433},{"style":373},[11434],{"type":21,"value":11435}," retry ",{"type":15,"tag":360,"props":11437,"children":11438},{"style":367},[11439],{"type":21,"value":381},{"type":15,"tag":360,"props":11441,"children":11442},{"style":373},[11443],{"type":21,"value":386},{"type":15,"tag":360,"props":11445,"children":11446},{"style":389},[11447],{"type":21,"value":259},{"type":15,"tag":360,"props":11449,"children":11450},{"style":373},[11451],{"type":21,"value":905},{"type":15,"tag":360,"props":11453,"children":11454},{"class":362,"line":501},[11455,11459,11464],{"type":15,"tag":360,"props":11456,"children":11457},{"style":373},[11458],{"type":21,"value":913},{"type":15,"tag":360,"props":11460,"children":11461},{"style":400},[11462],{"type":21,"value":11463},"\"retryDone\"",{"type":15,"tag":360,"props":11465,"children":11466},{"style":373},[11467],{"type":21,"value":923},{"type":15,"tag":360,"props":11469,"children":11470},{"class":362,"line":519},[11471,11475,11480],{"type":15,"tag":360,"props":11472,"children":11473},{"style":373},[11474],{"type":21,"value":931},{"type":15,"tag":360,"props":11476,"children":11477},{"style":400},[11478],{"type":21,"value":11479},"\"retryFailed\"",{"type":15,"tag":360,"props":11481,"children":11482},{"style":373},[11483],{"type":21,"value":923},{"type":15,"tag":360,"props":11485,"children":11486},{"class":362,"line":537},[11487,11492,11497,11501],{"type":15,"tag":360,"props":11488,"children":11489},{"style":373},[11490],{"type":21,"value":11491},"    context:   { reason: ",{"type":15,"tag":360,"props":11493,"children":11494},{"style":400},[11495],{"type":21,"value":11496},"\"manual-retry-of-\"",{"type":15,"tag":360,"props":11498,"children":11499},{"style":367},[11500],{"type":21,"value":6494},{"type":15,"tag":360,"props":11502,"children":11503},{"style":373},[11504],{"type":21,"value":11505}," originalDatasetId }\n",{"type":15,"tag":360,"props":11507,"children":11508},{"class":362,"line":773},[11509],{"type":15,"tag":360,"props":11510,"children":11511},{"style":373},[11512],{"type":21,"value":944},{"type":15,"tag":360,"props":11514,"children":11515},{"class":362,"line":1016},[11516,11520],{"type":15,"tag":360,"props":11517,"children":11518},{"style":367},[11519],{"type":21,"value":417},{"type":15,"tag":360,"props":11521,"children":11522},{"style":373},[11523],{"type":21,"value":422},{"type":15,"tag":360,"props":11525,"children":11526},{"class":362,"line":1024},[11527,11531,11535,11539,11543,11547,11551],{"type":15,"tag":360,"props":11528,"children":11529},{"style":373},[11530],{"type":21,"value":3686},{"type":15,"tag":360,"props":11532,"children":11533},{"style":389},[11534],{"type":21,"value":3691},{"type":15,"tag":360,"props":11536,"children":11537},{"style":373},[11538],{"type":21,"value":397},{"type":15,"tag":360,"props":11540,"children":11541},{"style":367},[11542],{"type":21,"value":3700},{"type":15,"tag":360,"props":11544,"children":11545},{"style":373},[11546],{"type":21,"value":397},{"type":15,"tag":360,"props":11548,"children":11549},{"style":3707},[11550],{"type":21,"value":8584},{"type":15,"tag":360,"props":11552,"children":11553},{"style":373},[11554],{"type":21,"value":3609},{"type":15,"tag":360,"props":11556,"children":11557},{"class":362,"line":1040},[11558,11562,11567,11571,11575,11579],{"type":15,"tag":360,"props":11559,"children":11560},{"style":367},[11561],{"type":21,"value":455},{"type":15,"tag":360,"props":11563,"children":11564},{"style":373},[11565],{"type":21,"value":11566}," originalId ",{"type":15,"tag":360,"props":11568,"children":11569},{"style":367},[11570],{"type":21,"value":381},{"type":15,"tag":360,"props":11572,"children":11573},{"style":373},[11574],{"type":21,"value":8608},{"type":15,"tag":360,"props":11576,"children":11577},{"style":389},[11578],{"type":21,"value":8661},{"type":15,"tag":360,"props":11580,"children":11581},{"style":373},[11582],{"type":21,"value":479},{"type":15,"tag":360,"props":11584,"children":11585},{"class":362,"line":1056},[11586,11590,11595,11599,11603,11607],{"type":15,"tag":360,"props":11587,"children":11588},{"style":367},[11589],{"type":21,"value":455},{"type":15,"tag":360,"props":11591,"children":11592},{"style":373},[11593],{"type":21,"value":11594}," lookup ",{"type":15,"tag":360,"props":11596,"children":11597},{"style":367},[11598],{"type":21,"value":381},{"type":15,"tag":360,"props":11600,"children":11601},{"style":373},[11602],{"type":21,"value":386},{"type":15,"tag":360,"props":11604,"children":11605},{"style":389},[11606],{"type":21,"value":392},{"type":15,"tag":360,"props":11608,"children":11609},{"style":373},[11610],{"type":21,"value":5126},{"type":15,"tag":360,"props":11612,"children":11613},{"class":362,"line":1072},[11614,11619],{"type":15,"tag":360,"props":11615,"children":11616},{"style":400},[11617],{"type":21,"value":11618},"            \"select o from order o where o.id = ${id}\"",{"type":15,"tag":360,"props":11620,"children":11621},{"style":373},[11622],{"type":21,"value":923},{"type":15,"tag":360,"props":11624,"children":11625},{"class":362,"line":5296},[11626],{"type":15,"tag":360,"props":11627,"children":11628},{"style":373},[11629],{"type":21,"value":11630},"            { id: originalId });\n",{"type":15,"tag":360,"props":11632,"children":11633},{"class":362,"line":5319},[11634,11639],{"type":15,"tag":360,"props":11635,"children":11636},{"style":367},[11637],{"type":21,"value":11638},"        try",{"type":15,"tag":360,"props":11640,"children":11641},{"style":373},[11642],{"type":21,"value":422},{"type":15,"tag":360,"props":11644,"children":11645},{"class":362,"line":5336},[11646,11651,11656,11660],{"type":15,"tag":360,"props":11647,"children":11648},{"style":367},[11649],{"type":21,"value":11650},"            if",{"type":15,"tag":360,"props":11652,"children":11653},{"style":373},[11654],{"type":21,"value":11655}," (lookup.",{"type":15,"tag":360,"props":11657,"children":11658},{"style":389},[11659],{"type":21,"value":441},{"type":15,"tag":360,"props":11661,"children":11662},{"style":373},[11663],{"type":21,"value":446},{"type":15,"tag":360,"props":11665,"children":11666},{"class":362,"line":5359},[11667,11672,11676,11680,11684,11689,11693,11697,11701],{"type":15,"tag":360,"props":11668,"children":11669},{"style":373},[11670],{"type":21,"value":11671},"                retry.",{"type":15,"tag":360,"props":11673,"children":11674},{"style":389},[11675],{"type":21,"value":682},{"type":15,"tag":360,"props":11677,"children":11678},{"style":373},[11679],{"type":21,"value":397},{"type":15,"tag":360,"props":11681,"children":11682},{"style":400},[11683],{"type":21,"value":8049},{"type":15,"tag":360,"props":11685,"children":11686},{"style":373},[11687],{"type":21,"value":11688},", lookup.",{"type":15,"tag":360,"props":11690,"children":11691},{"style":389},[11692],{"type":21,"value":474},{"type":15,"tag":360,"props":11694,"children":11695},{"style":373},[11696],{"type":21,"value":705},{"type":15,"tag":360,"props":11698,"children":11699},{"style":708},[11700],{"type":21,"value":711},{"type":15,"tag":360,"props":11702,"children":11703},{"style":373},[11704],{"type":21,"value":408},{"type":15,"tag":360,"props":11706,"children":11707},{"class":362,"line":5413},[11708],{"type":15,"tag":360,"props":11709,"children":11710},{"style":373},[11711],{"type":21,"value":11712},"            }\n",{"type":15,"tag":360,"props":11714,"children":11715},{"class":362,"line":5421},[11716,11721,11725],{"type":15,"tag":360,"props":11717,"children":11718},{"style":373},[11719],{"type":21,"value":11720},"        } ",{"type":15,"tag":360,"props":11722,"children":11723},{"style":367},[11724],{"type":21,"value":512},{"type":15,"tag":360,"props":11726,"children":11727},{"style":373},[11728],{"type":21,"value":422},{"type":15,"tag":360,"props":11730,"children":11731},{"class":362,"line":5430},[11732,11737,11741],{"type":15,"tag":360,"props":11733,"children":11734},{"style":373},[11735],{"type":21,"value":11736},"            lookup.",{"type":15,"tag":360,"props":11738,"children":11739},{"style":389},[11740],{"type":21,"value":530},{"type":15,"tag":360,"props":11742,"children":11743},{"style":373},[11744],{"type":21,"value":479},{"type":15,"tag":360,"props":11746,"children":11747},{"class":362,"line":5439},[11748],{"type":15,"tag":360,"props":11749,"children":11750},{"style":373},[11751],{"type":21,"value":11752},"        }\n",{"type":15,"tag":360,"props":11754,"children":11755},{"class":362,"line":5447},[11756],{"type":15,"tag":360,"props":11757,"children":11758},{"style":373},[11759],{"type":21,"value":3820},{"type":15,"tag":360,"props":11761,"children":11762},{"class":362,"line":5455},[11763,11767,11771],{"type":15,"tag":360,"props":11764,"children":11765},{"style":373},[11766],{"type":21,"value":507},{"type":15,"tag":360,"props":11768,"children":11769},{"style":367},[11770],{"type":21,"value":512},{"type":15,"tag":360,"props":11772,"children":11773},{"style":373},[11774],{"type":21,"value":422},{"type":15,"tag":360,"props":11776,"children":11777},{"class":362,"line":5467},[11778,11783,11787],{"type":15,"tag":360,"props":11779,"children":11780},{"style":373},[11781],{"type":21,"value":11782},"    retry.",{"type":15,"tag":360,"props":11784,"children":11785},{"style":389},[11786],{"type":21,"value":766},{"type":15,"tag":360,"props":11788,"children":11789},{"style":373},[11790],{"type":21,"value":479},{"type":15,"tag":360,"props":11792,"children":11793},{"class":362,"line":5488},[11794],{"type":15,"tag":360,"props":11795,"children":11796},{"style":373},[11797],{"type":21,"value":543},{"type":15,"tag":805,"props":11799,"children":11800},{},[],{"type":15,"tag":325,"props":11802,"children":11804},{"id":11803},"use-case-7-loop-paginating-an-external-api",[11805],{"type":21,"value":11806},"Use Case 7: Loop — Paginating an External API",{"type":15,"tag":24,"props":11808,"children":11809},{},[11810,11814],{"type":15,"tag":30,"props":11811,"children":11812},{},[11813],{"type":21,"value":5021},{"type":21,"value":11815}," Sync orders from a partner's API. We don't know how many pages there are; the partner will tell us when there's no more data.",{"type":15,"tag":24,"props":11817,"children":11818},{},[11819],{"type":21,"value":11820},"This is the canonical case for a loop — sequential work where each step decides whether to keep going.",{"type":15,"tag":350,"props":11822,"children":11824},{"className":352,"code":11823,"language":354,"meta":7,"style":7},"// Action: kicking off the loop\ncontext.createLoop({\n    workItemType:  \"syncOrdersFromPartner\",\n    initialState:  { offset: 0, batchSize: 200 },\n    onComplete:    \"partnerSyncDone\",\n    onError:       \"partnerSyncFailed\",\n    maxIterations: 5000,\n    deadlineMs:    Date.now() + 4 * 60 * 60 * 1000,   // 4 hours\n    context:       { partnerName: \"Acme Co\" }\n});\n",[11825],{"type":15,"tag":254,"props":11826,"children":11827},{"__ignoreMap":7},[11828,11836,11851,11868,11895,11912,11928,11945,12002,12019],{"type":15,"tag":360,"props":11829,"children":11830},{"class":362,"line":363},[11831],{"type":15,"tag":360,"props":11832,"children":11833},{"style":486},[11834],{"type":21,"value":11835},"// Action: kicking off the loop\n",{"type":15,"tag":360,"props":11837,"children":11838},{"class":362,"line":411},[11839,11843,11847],{"type":15,"tag":360,"props":11840,"children":11841},{"style":373},[11842],{"type":21,"value":1234},{"type":15,"tag":360,"props":11844,"children":11845},{"style":389},[11846],{"type":21,"value":289},{"type":15,"tag":360,"props":11848,"children":11849},{"style":373},[11850],{"type":21,"value":905},{"type":15,"tag":360,"props":11852,"children":11853},{"class":362,"line":425},[11854,11859,11864],{"type":15,"tag":360,"props":11855,"children":11856},{"style":373},[11857],{"type":21,"value":11858},"    workItemType:  ",{"type":15,"tag":360,"props":11860,"children":11861},{"style":400},[11862],{"type":21,"value":11863},"\"syncOrdersFromPartner\"",{"type":15,"tag":360,"props":11865,"children":11866},{"style":373},[11867],{"type":21,"value":923},{"type":15,"tag":360,"props":11869,"children":11870},{"class":362,"line":449},[11871,11876,11880,11885,11890],{"type":15,"tag":360,"props":11872,"children":11873},{"style":373},[11874],{"type":21,"value":11875},"    initialState:  { offset: ",{"type":15,"tag":360,"props":11877,"children":11878},{"style":708},[11879],{"type":21,"value":4352},{"type":15,"tag":360,"props":11881,"children":11882},{"style":373},[11883],{"type":21,"value":11884},", batchSize: ",{"type":15,"tag":360,"props":11886,"children":11887},{"style":708},[11888],{"type":21,"value":11889},"200",{"type":15,"tag":360,"props":11891,"children":11892},{"style":373},[11893],{"type":21,"value":11894}," },\n",{"type":15,"tag":360,"props":11896,"children":11897},{"class":362,"line":482},[11898,11903,11908],{"type":15,"tag":360,"props":11899,"children":11900},{"style":373},[11901],{"type":21,"value":11902},"    onComplete:    ",{"type":15,"tag":360,"props":11904,"children":11905},{"style":400},[11906],{"type":21,"value":11907},"\"partnerSyncDone\"",{"type":15,"tag":360,"props":11909,"children":11910},{"style":373},[11911],{"type":21,"value":923},{"type":15,"tag":360,"props":11913,"children":11914},{"class":362,"line":492},[11915,11919,11924],{"type":15,"tag":360,"props":11916,"children":11917},{"style":373},[11918],{"type":21,"value":3115},{"type":15,"tag":360,"props":11920,"children":11921},{"style":400},[11922],{"type":21,"value":11923},"\"partnerSyncFailed\"",{"type":15,"tag":360,"props":11925,"children":11926},{"style":373},[11927],{"type":21,"value":923},{"type":15,"tag":360,"props":11929,"children":11930},{"class":362,"line":501},[11931,11936,11941],{"type":15,"tag":360,"props":11932,"children":11933},{"style":373},[11934],{"type":21,"value":11935},"    maxIterations: ",{"type":15,"tag":360,"props":11937,"children":11938},{"style":708},[11939],{"type":21,"value":11940},"5000",{"type":15,"tag":360,"props":11942,"children":11943},{"style":373},[11944],{"type":21,"value":923},{"type":15,"tag":360,"props":11946,"children":11947},{"class":362,"line":519},[11948,11953,11957,11961,11965,11969,11973,11977,11981,11985,11989,11993,11997],{"type":15,"tag":360,"props":11949,"children":11950},{"style":373},[11951],{"type":21,"value":11952},"    deadlineMs:    Date.",{"type":15,"tag":360,"props":11954,"children":11955},{"style":389},[11956],{"type":21,"value":2899},{"type":15,"tag":360,"props":11958,"children":11959},{"style":373},[11960],{"type":21,"value":2904},{"type":15,"tag":360,"props":11962,"children":11963},{"style":367},[11964],{"type":21,"value":2909},{"type":15,"tag":360,"props":11966,"children":11967},{"style":708},[11968],{"type":21,"value":5382},{"type":15,"tag":360,"props":11970,"children":11971},{"style":367},[11972],{"type":21,"value":2919},{"type":15,"tag":360,"props":11974,"children":11975},{"style":708},[11976],{"type":21,"value":2924},{"type":15,"tag":360,"props":11978,"children":11979},{"style":367},[11980],{"type":21,"value":2919},{"type":15,"tag":360,"props":11982,"children":11983},{"style":708},[11984],{"type":21,"value":2924},{"type":15,"tag":360,"props":11986,"children":11987},{"style":367},[11988],{"type":21,"value":2919},{"type":15,"tag":360,"props":11990,"children":11991},{"style":708},[11992],{"type":21,"value":2933},{"type":15,"tag":360,"props":11994,"children":11995},{"style":373},[11996],{"type":21,"value":7924},{"type":15,"tag":360,"props":11998,"children":11999},{"style":486},[12000],{"type":21,"value":12001},"// 4 hours\n",{"type":15,"tag":360,"props":12003,"children":12004},{"class":362,"line":537},[12005,12010,12015],{"type":15,"tag":360,"props":12006,"children":12007},{"style":373},[12008],{"type":21,"value":12009},"    context:       { partnerName: ",{"type":15,"tag":360,"props":12011,"children":12012},{"style":400},[12013],{"type":21,"value":12014},"\"Acme Co\"",{"type":15,"tag":360,"props":12016,"children":12017},{"style":373},[12018],{"type":21,"value":4366},{"type":15,"tag":360,"props":12020,"children":12021},{"class":362,"line":773},[12022],{"type":15,"tag":360,"props":12023,"children":12024},{"style":373},[12025],{"type":21,"value":944},{"type":15,"tag":24,"props":12027,"children":12028},{},[12029,12031,12036,12038,12044,12046,12052],{"type":21,"value":12030},"Unlike ",{"type":15,"tag":254,"props":12032,"children":12034},{"className":12033},[],[12035],{"type":21,"value":259},{"type":21,"value":12037},", the work itself is a registered Java component (a ",{"type":15,"tag":254,"props":12039,"children":12041},{"className":12040},[],[12042],{"type":21,"value":12043},"LoopWorker",{"type":21,"value":12045},") — not a JavaScript action. This is because loop workers need to be carefully written for idempotency, which is easier to enforce in compiled Java code. The ",{"type":15,"tag":254,"props":12047,"children":12049},{"className":12048},[],[12050],{"type":21,"value":12051},"workItemType",{"type":21,"value":12053}," is just a string that names a worker that's already been registered with the platform.",{"type":15,"tag":24,"props":12055,"children":12056},{},[12057],{"type":21,"value":12058},"If you're a tenant developer, ask a platform engineer to register the worker for you.",{"type":15,"tag":24,"props":12060,"children":12061},{},[12062],{"type":21,"value":12063},"The loop's finalizer receives:",{"type":15,"tag":208,"props":12065,"children":12066},{},[12067,12081],{"type":15,"tag":212,"props":12068,"children":12069},{},[12070],{"type":15,"tag":216,"props":12071,"children":12072},{},[12073,12077],{"type":15,"tag":220,"props":12074,"children":12075},{},[12076],{"type":21,"value":1586},{"type":15,"tag":220,"props":12078,"children":12079},{},[12080],{"type":21,"value":1591},{"type":15,"tag":236,"props":12082,"children":12083},{},[12084,12112,12128,12145,12162],{"type":15,"tag":216,"props":12085,"children":12086},{},[12087,12107],{"type":15,"tag":243,"props":12088,"children":12089},{},[12090,12095,12096,12101,12102],{"type":15,"tag":254,"props":12091,"children":12093},{"className":12092},[],[12094],{"type":21,"value":1606},{"type":21,"value":1348},{"type":15,"tag":254,"props":12097,"children":12099},{"className":12098},[],[12100],{"type":21,"value":1623},{"type":21,"value":1348},{"type":15,"tag":254,"props":12103,"children":12105},{"className":12104},[],[12106],{"type":21,"value":1751},{"type":15,"tag":243,"props":12108,"children":12109},{},[12110],{"type":21,"value":12111},"Same as batches",{"type":15,"tag":216,"props":12113,"children":12114},{},[12115,12123],{"type":15,"tag":243,"props":12116,"children":12117},{},[12118],{"type":15,"tag":254,"props":12119,"children":12121},{"className":12120},[],[12122],{"type":21,"value":12051},{"type":15,"tag":243,"props":12124,"children":12125},{},[12126],{"type":21,"value":12127},"The worker name",{"type":15,"tag":216,"props":12129,"children":12130},{},[12131,12140],{"type":15,"tag":243,"props":12132,"children":12133},{},[12134],{"type":15,"tag":254,"props":12135,"children":12137},{"className":12136},[],[12138],{"type":21,"value":12139},"iteration",{"type":15,"tag":243,"props":12141,"children":12142},{},[12143],{"type":21,"value":12144},"How many iterations actually ran",{"type":15,"tag":216,"props":12146,"children":12147},{},[12148,12157],{"type":15,"tag":243,"props":12149,"children":12150},{},[12151],{"type":15,"tag":254,"props":12152,"children":12154},{"className":12153},[],[12155],{"type":21,"value":12156},"output",{"type":15,"tag":243,"props":12158,"children":12159},{},[12160],{"type":21,"value":12161},"Optional per-completion output the worker passes back",{"type":15,"tag":216,"props":12163,"children":12164},{},[12165,12174],{"type":15,"tag":243,"props":12166,"children":12167},{},[12168],{"type":15,"tag":254,"props":12169,"children":12171},{"className":12170},[],[12172],{"type":21,"value":12173},"stateDatasetId",{"type":15,"tag":243,"props":12175,"children":12176},{},[12177],{"type":21,"value":12178},"Where the final state record lives",{"type":15,"tag":350,"props":12180,"children":12182},{"className":352,"code":12181,"language":354,"meta":7,"style":7},"// Action: \"partnerSyncDone\"\ncontext.log(\"Synced {} pages from {} over {}s\",\n    context.getInput(\"iteration\"),\n    context.getParameter(\"partnerName\"),\n    Math.round(context.getInput(\"durationMs\") / 1000));\n",[12183],{"type":15,"tag":254,"props":12184,"children":12185},{"__ignoreMap":7},[12186,12194,12218,12242,12266],{"type":15,"tag":360,"props":12187,"children":12188},{"class":362,"line":363},[12189],{"type":15,"tag":360,"props":12190,"children":12191},{"style":486},[12192],{"type":21,"value":12193},"// Action: \"partnerSyncDone\"\n",{"type":15,"tag":360,"props":12195,"children":12196},{"class":362,"line":411},[12197,12201,12205,12209,12214],{"type":15,"tag":360,"props":12198,"children":12199},{"style":373},[12200],{"type":21,"value":1234},{"type":15,"tag":360,"props":12202,"children":12203},{"style":389},[12204],{"type":21,"value":1418},{"type":15,"tag":360,"props":12206,"children":12207},{"style":373},[12208],{"type":21,"value":397},{"type":15,"tag":360,"props":12210,"children":12211},{"style":400},[12212],{"type":21,"value":12213},"\"Synced {} pages from {} over {}s\"",{"type":15,"tag":360,"props":12215,"children":12216},{"style":373},[12217],{"type":21,"value":923},{"type":15,"tag":360,"props":12219,"children":12220},{"class":362,"line":425},[12221,12225,12229,12233,12238],{"type":15,"tag":360,"props":12222,"children":12223},{"style":373},[12224],{"type":21,"value":1439},{"type":15,"tag":360,"props":12226,"children":12227},{"style":389},[12228],{"type":21,"value":1444},{"type":15,"tag":360,"props":12230,"children":12231},{"style":373},[12232],{"type":21,"value":397},{"type":15,"tag":360,"props":12234,"children":12235},{"style":400},[12236],{"type":21,"value":12237},"\"iteration\"",{"type":15,"tag":360,"props":12239,"children":12240},{"style":373},[12241],{"type":21,"value":1270},{"type":15,"tag":360,"props":12243,"children":12244},{"class":362,"line":449},[12245,12249,12253,12257,12262],{"type":15,"tag":360,"props":12246,"children":12247},{"style":373},[12248],{"type":21,"value":1439},{"type":15,"tag":360,"props":12250,"children":12251},{"style":389},[12252],{"type":21,"value":2067},{"type":15,"tag":360,"props":12254,"children":12255},{"style":373},[12256],{"type":21,"value":397},{"type":15,"tag":360,"props":12258,"children":12259},{"style":400},[12260],{"type":21,"value":12261},"\"partnerName\"",{"type":15,"tag":360,"props":12263,"children":12264},{"style":373},[12265],{"type":21,"value":1270},{"type":15,"tag":360,"props":12267,"children":12268},{"class":362,"line":482},[12269,12273,12277,12281,12285,12289,12293,12297,12301,12305],{"type":15,"tag":360,"props":12270,"children":12271},{"style":373},[12272],{"type":21,"value":8229},{"type":15,"tag":360,"props":12274,"children":12275},{"style":389},[12276],{"type":21,"value":8234},{"type":15,"tag":360,"props":12278,"children":12279},{"style":373},[12280],{"type":21,"value":8239},{"type":15,"tag":360,"props":12282,"children":12283},{"style":389},[12284],{"type":21,"value":1444},{"type":15,"tag":360,"props":12286,"children":12287},{"style":373},[12288],{"type":21,"value":397},{"type":15,"tag":360,"props":12290,"children":12291},{"style":400},[12292],{"type":21,"value":8252},{"type":15,"tag":360,"props":12294,"children":12295},{"style":373},[12296],{"type":21,"value":3594},{"type":15,"tag":360,"props":12298,"children":12299},{"style":367},[12300],{"type":21,"value":8261},{"type":15,"tag":360,"props":12302,"children":12303},{"style":708},[12304],{"type":21,"value":2933},{"type":15,"tag":360,"props":12306,"children":12307},{"style":373},[12308],{"type":21,"value":1506},{"type":15,"tag":2164,"props":12310,"children":12311},{},[12312],{"type":15,"tag":24,"props":12313,"children":12314},{},[12315,12320],{"type":15,"tag":30,"props":12316,"children":12317},{},[12318],{"type":21,"value":12319},"Note:",{"type":21,"value":12321}," Loops are a less common pattern. Most \"big jobs\" in application development are batches, not loops. The loop primitive is here when you genuinely need it — drain a queue, paginate an API, walk a long sequence — but try a batch first.",{"type":15,"tag":805,"props":12323,"children":12324},{},[],{"type":15,"tag":126,"props":12326,"children":12328},{"id":12327},"what-the-platform-handles-automatically",[12329],{"type":21,"value":12330},"What the Platform Handles Automatically",{"type":15,"tag":24,"props":12332,"children":12333},{},[12334],{"type":21,"value":12335},"Here's a partial list of things you don't need to worry about:",{"type":15,"tag":38,"props":12337,"children":12338},{},[12339,12349,12359,12383,12393],{"type":15,"tag":42,"props":12340,"children":12341},{},[12342,12347],{"type":15,"tag":30,"props":12343,"children":12344},{},[12345],{"type":21,"value":12346},"Worker crashes mid-child.",{"type":21,"value":12348}," The message comes back to the queue; another worker picks it up. The action runs again — so make children idempotent.",{"type":15,"tag":42,"props":12350,"children":12351},{},[12352,12357],{"type":15,"tag":30,"props":12353,"children":12354},{},[12355],{"type":21,"value":12356},"Server restarts mid-batch.",{"type":21,"value":12358}," All batch state lives in MongoDB. When the server comes back up, sweeps pick up where things left off.",{"type":15,"tag":42,"props":12360,"children":12361},{},[12362,12367,12369,12374,12376,12381],{"type":15,"tag":30,"props":12363,"children":12364},{},[12365],{"type":21,"value":12366},"Lost messages.",{"type":21,"value":12368}," The deadline sweeper is the safety net. A batch that's run longer than its deadline is forcibly transitioned to ",{"type":15,"tag":254,"props":12370,"children":12372},{"className":12371},[],[12373],{"type":21,"value":1655},{"type":21,"value":12375}," and its ",{"type":15,"tag":254,"props":12377,"children":12379},{"className":12378},[],[12380],{"type":21,"value":1538},{"type":21,"value":12382}," runs.",{"type":15,"tag":42,"props":12384,"children":12385},{},[12386,12391],{"type":15,"tag":30,"props":12387,"children":12388},{},[12389],{"type":21,"value":12390},"Duplicate child reports.",{"type":21,"value":12392}," The platform deduplicates internally, so a child running twice (e.g. due to message redelivery) only counts once toward the batch's totals.",{"type":15,"tag":42,"props":12394,"children":12395},{},[12396,12401],{"type":15,"tag":30,"props":12397,"children":12398},{},[12399],{"type":21,"value":12400},"Finalizer crashes.",{"type":21,"value":12402}," The finalizer is just another action. If it fails, it's retried like any other action job. If it fails repeatedly, an operator can replay it with one click.",{"type":15,"tag":805,"props":12404,"children":12405},{},[],{"type":15,"tag":126,"props":12407,"children":12409},{"id":12408},"things-you-should-think-about",[12410],{"type":21,"value":12411},"Things You Should Think About",{"type":15,"tag":208,"props":12413,"children":12414},{},[12415,12431],{"type":15,"tag":212,"props":12416,"children":12417},{},[12418],{"type":15,"tag":216,"props":12419,"children":12420},{},[12421,12426],{"type":15,"tag":220,"props":12422,"children":12423},{},[12424],{"type":21,"value":12425},"Concern",{"type":15,"tag":220,"props":12427,"children":12428},{},[12429],{"type":21,"value":12430},"What to Do",{"type":15,"tag":236,"props":12432,"children":12433},{},[12434,12464,12480,12496,12518,12548],{"type":15,"tag":216,"props":12435,"children":12436},{},[12437,12445],{"type":15,"tag":243,"props":12438,"children":12439},{},[12440],{"type":15,"tag":30,"props":12441,"children":12442},{},[12443],{"type":21,"value":12444},"Always close query results.",{"type":15,"tag":243,"props":12446,"children":12447},{},[12448,12449,12454,12456,12462],{"type":21,"value":2614},{"type":15,"tag":254,"props":12450,"children":12452},{"className":12451},[],[12453],{"type":21,"value":4224},{"type":21,"value":12455}," consistently. Without ",{"type":15,"tag":254,"props":12457,"children":12459},{"className":12458},[],[12460],{"type":21,"value":12461},"result.close()",{"type":21,"value":12463}," you leak transactions and exhaust the connection pool.",{"type":15,"tag":216,"props":12465,"children":12466},{},[12467,12475],{"type":15,"tag":243,"props":12468,"children":12469},{},[12470],{"type":15,"tag":30,"props":12471,"children":12472},{},[12473],{"type":21,"value":12474},"Make child actions idempotent.",{"type":15,"tag":243,"props":12476,"children":12477},{},[12478],{"type":21,"value":12479},"The platform delivers messages \"at least once,\" not \"exactly once.\" If a child sends an email or charges a card, write your code so a re-run doesn't double-charge (e.g. set a flag on the record before doing the side effect, and check it on entry).",{"type":15,"tag":216,"props":12481,"children":12482},{},[12483,12491],{"type":15,"tag":243,"props":12484,"children":12485},{},[12486],{"type":15,"tag":30,"props":12487,"children":12488},{},[12489],{"type":21,"value":12490},"Pick a reasonable deadline.",{"type":15,"tag":243,"props":12492,"children":12493},{},[12494],{"type":21,"value":12495},"Default 24h is fine for most batches but can be too long for jobs that should obviously be done in minutes. A short deadline trips alarms sooner.",{"type":15,"tag":216,"props":12497,"children":12498},{},[12499,12513],{"type":15,"tag":243,"props":12500,"children":12501},{},[12502],{"type":15,"tag":30,"props":12503,"children":12504},{},[12505,12506,12511],{"type":21,"value":2614},{"type":15,"tag":254,"props":12507,"children":12509},{"className":12508},[],[12510],{"type":21,"value":2265},{"type":21,"value":12512}," deliberately.",{"type":15,"tag":243,"props":12514,"children":12515},{},[12516],{"type":21,"value":12517},"\"Send 100,000 marketing emails\" can survive 0.1% bouncing; \"process 100,000 customer payments\" cannot.",{"type":15,"tag":216,"props":12519,"children":12520},{},[12521,12543],{"type":15,"tag":243,"props":12522,"children":12523},{},[12524],{"type":15,"tag":30,"props":12525,"children":12526},{},[12527,12529,12534,12536,12541],{"type":21,"value":12528},"Prefer ",{"type":15,"tag":254,"props":12530,"children":12532},{"className":12531},[],[12533],{"type":21,"value":3410},{"type":21,"value":12535}," over ",{"type":15,"tag":254,"props":12537,"children":12539},{"className":12538},[],[12540],{"type":21,"value":3850},{"type":21,"value":12542}," for very large batches.",{"type":15,"tag":243,"props":12544,"children":12545},{},[12546],{"type":21,"value":12547},"Persisting every result for a million children is wasteful if you only ever look at the failures.",{"type":15,"tag":216,"props":12549,"children":12550},{},[12551,12559],{"type":15,"tag":243,"props":12552,"children":12553},{},[12554],{"type":15,"tag":30,"props":12555,"children":12556},{},[12557],{"type":21,"value":12558},"Reducers must be pure.",{"type":15,"tag":243,"props":12560,"children":12561},{},[12562],{"type":21,"value":12563},"No database writes, no API calls — just compute the new accumulator from the inputs.",{"type":15,"tag":805,"props":12565,"children":12566},{},[],{"type":15,"tag":126,"props":12568,"children":12570},{"id":12569},"api-reference",[12571],{"type":21,"value":12572},"API Reference",{"type":15,"tag":325,"props":12574,"children":12576},{"id":12575},"contextcreatebatchoptions",[12577],{"type":15,"tag":254,"props":12578,"children":12580},{"className":12579},[],[12581],{"type":21,"value":12582},"context.createBatch(options)",{"type":15,"tag":24,"props":12584,"children":12585},{},[12586,12588,12594],{"type":21,"value":12587},"Returns a ",{"type":15,"tag":254,"props":12589,"children":12591},{"className":12590},[],[12592],{"type":21,"value":12593},"BatchExecution",{"type":21,"value":12595}," handle.",{"type":15,"tag":350,"props":12597,"children":12599},{"className":352,"code":12598,"language":354,"meta":7,"style":7},"context.createBatch({\n    // --- Lifecycle hooks ---\n    onSuccess:         \"actionName\",   // when state == COMPLETED\n    onError:           \"actionName\",   // FAILED, TIMED_OUT, CANCELLED\n    onPartial:         \"actionName\",   // PARTIAL (falls back to onSuccess)\n\n    // --- Result persistence ---\n    results:           \"COUNT\",        // or PERSIST | FAILURES_ONLY | REDUCE\n    resultsTtlHours:   24,             // 1..168\n    reducer:           \"reducer\",      // REDUCE only\n    reducerInitial:    { },            // REDUCE only\n    reducerFailure:    \"SKIP\",         // SKIP | ABORT, default SKIP\n\n    // --- Safety nets ---\n    failureThreshold:  0.10,           // null = no threshold\n    failureMinSamples: 10,\n    deadlineMs:        Date.now() + 3600000,   // default: createdAt + 24h\n\n    // --- Concurrency ---\n    maxConcurrent:     50,             // null = unlimited\n\n    // --- Caller state ---\n    context:           { }             // forwarded to the finalizer\n});\n",[12600],{"type":15,"tag":254,"props":12601,"children":12602},{"__ignoreMap":7},[12603,12618,12626,12647,12667,12688,12695,12703,12725,12748,12770,12782,12805,12812,12820,12841,12856,12889,12896,12904,12924,12931,12939,12952],{"type":15,"tag":360,"props":12604,"children":12605},{"class":362,"line":363},[12606,12610,12614],{"type":15,"tag":360,"props":12607,"children":12608},{"style":373},[12609],{"type":21,"value":1234},{"type":15,"tag":360,"props":12611,"children":12612},{"style":389},[12613],{"type":21,"value":259},{"type":15,"tag":360,"props":12615,"children":12616},{"style":373},[12617],{"type":21,"value":905},{"type":15,"tag":360,"props":12619,"children":12620},{"class":362,"line":411},[12621],{"type":15,"tag":360,"props":12622,"children":12623},{"style":486},[12624],{"type":21,"value":12625},"    // --- Lifecycle hooks ---\n",{"type":15,"tag":360,"props":12627,"children":12628},{"class":362,"line":425},[12629,12633,12638,12642],{"type":15,"tag":360,"props":12630,"children":12631},{"style":373},[12632],{"type":21,"value":2663},{"type":15,"tag":360,"props":12634,"children":12635},{"style":400},[12636],{"type":21,"value":12637},"\"actionName\"",{"type":15,"tag":360,"props":12639,"children":12640},{"style":373},[12641],{"type":21,"value":7924},{"type":15,"tag":360,"props":12643,"children":12644},{"style":486},[12645],{"type":21,"value":12646},"// when state == COMPLETED\n",{"type":15,"tag":360,"props":12648,"children":12649},{"class":362,"line":449},[12650,12654,12658,12662],{"type":15,"tag":360,"props":12651,"children":12652},{"style":373},[12653],{"type":21,"value":2680},{"type":15,"tag":360,"props":12655,"children":12656},{"style":400},[12657],{"type":21,"value":12637},{"type":15,"tag":360,"props":12659,"children":12660},{"style":373},[12661],{"type":21,"value":7924},{"type":15,"tag":360,"props":12663,"children":12664},{"style":486},[12665],{"type":21,"value":12666},"// FAILED, TIMED_OUT, CANCELLED\n",{"type":15,"tag":360,"props":12668,"children":12669},{"class":362,"line":482},[12670,12675,12679,12683],{"type":15,"tag":360,"props":12671,"children":12672},{"style":373},[12673],{"type":21,"value":12674},"    onPartial:         ",{"type":15,"tag":360,"props":12676,"children":12677},{"style":400},[12678],{"type":21,"value":12637},{"type":15,"tag":360,"props":12680,"children":12681},{"style":373},[12682],{"type":21,"value":7924},{"type":15,"tag":360,"props":12684,"children":12685},{"style":486},[12686],{"type":21,"value":12687},"// PARTIAL (falls back to onSuccess)\n",{"type":15,"tag":360,"props":12689,"children":12690},{"class":362,"line":492},[12691],{"type":15,"tag":360,"props":12692,"children":12693},{"emptyLinePlaceholder":839},[12694],{"type":21,"value":842},{"type":15,"tag":360,"props":12696,"children":12697},{"class":362,"line":501},[12698],{"type":15,"tag":360,"props":12699,"children":12700},{"style":486},[12701],{"type":21,"value":12702},"    // --- Result persistence ---\n",{"type":15,"tag":360,"props":12704,"children":12705},{"class":362,"line":519},[12706,12710,12715,12720],{"type":15,"tag":360,"props":12707,"children":12708},{"style":373},[12709],{"type":21,"value":5279},{"type":15,"tag":360,"props":12711,"children":12712},{"style":400},[12713],{"type":21,"value":12714},"\"COUNT\"",{"type":15,"tag":360,"props":12716,"children":12717},{"style":373},[12718],{"type":21,"value":12719},",        ",{"type":15,"tag":360,"props":12721,"children":12722},{"style":486},[12723],{"type":21,"value":12724},"// or PERSIST | FAILURES_ONLY | REDUCE\n",{"type":15,"tag":360,"props":12726,"children":12727},{"class":362,"line":537},[12728,12733,12738,12743],{"type":15,"tag":360,"props":12729,"children":12730},{"style":373},[12731],{"type":21,"value":12732},"    resultsTtlHours:   ",{"type":15,"tag":360,"props":12734,"children":12735},{"style":708},[12736],{"type":21,"value":12737},"24",{"type":15,"tag":360,"props":12739,"children":12740},{"style":373},[12741],{"type":21,"value":12742},",             ",{"type":15,"tag":360,"props":12744,"children":12745},{"style":486},[12746],{"type":21,"value":12747},"// 1..168\n",{"type":15,"tag":360,"props":12749,"children":12750},{"class":362,"line":773},[12751,12756,12761,12765],{"type":15,"tag":360,"props":12752,"children":12753},{"style":373},[12754],{"type":21,"value":12755},"    reducer:           ",{"type":15,"tag":360,"props":12757,"children":12758},{"style":400},[12759],{"type":21,"value":12760},"\"reducer\"",{"type":15,"tag":360,"props":12762,"children":12763},{"style":373},[12764],{"type":21,"value":2707},{"type":15,"tag":360,"props":12766,"children":12767},{"style":486},[12768],{"type":21,"value":12769},"// REDUCE only\n",{"type":15,"tag":360,"props":12771,"children":12772},{"class":362,"line":1016},[12773,12778],{"type":15,"tag":360,"props":12774,"children":12775},{"style":373},[12776],{"type":21,"value":12777},"    reducerInitial:    { },            ",{"type":15,"tag":360,"props":12779,"children":12780},{"style":486},[12781],{"type":21,"value":12769},{"type":15,"tag":360,"props":12783,"children":12784},{"class":362,"line":1024},[12785,12790,12795,12800],{"type":15,"tag":360,"props":12786,"children":12787},{"style":373},[12788],{"type":21,"value":12789},"    reducerFailure:    ",{"type":15,"tag":360,"props":12791,"children":12792},{"style":400},[12793],{"type":21,"value":12794},"\"SKIP\"",{"type":15,"tag":360,"props":12796,"children":12797},{"style":373},[12798],{"type":21,"value":12799},",         ",{"type":15,"tag":360,"props":12801,"children":12802},{"style":486},[12803],{"type":21,"value":12804},"// SKIP | ABORT, default SKIP\n",{"type":15,"tag":360,"props":12806,"children":12807},{"class":362,"line":1040},[12808],{"type":15,"tag":360,"props":12809,"children":12810},{"emptyLinePlaceholder":839},[12811],{"type":21,"value":842},{"type":15,"tag":360,"props":12813,"children":12814},{"class":362,"line":1056},[12815],{"type":15,"tag":360,"props":12816,"children":12817},{"style":486},[12818],{"type":21,"value":12819},"    // --- Safety nets ---\n",{"type":15,"tag":360,"props":12821,"children":12822},{"class":362,"line":1072},[12823,12827,12831,12836],{"type":15,"tag":360,"props":12824,"children":12825},{"style":373},[12826],{"type":21,"value":2697},{"type":15,"tag":360,"props":12828,"children":12829},{"style":708},[12830],{"type":21,"value":2702},{"type":15,"tag":360,"props":12832,"children":12833},{"style":373},[12834],{"type":21,"value":12835},",           ",{"type":15,"tag":360,"props":12837,"children":12838},{"style":486},[12839],{"type":21,"value":12840},"// null = no threshold\n",{"type":15,"tag":360,"props":12842,"children":12843},{"class":362,"line":5296},[12844,12848,12852],{"type":15,"tag":360,"props":12845,"children":12846},{"style":373},[12847],{"type":21,"value":2720},{"type":15,"tag":360,"props":12849,"children":12850},{"style":708},[12851],{"type":21,"value":3137},{"type":15,"tag":360,"props":12853,"children":12854},{"style":373},[12855],{"type":21,"value":923},{"type":15,"tag":360,"props":12857,"children":12858},{"class":362,"line":5319},[12859,12863,12867,12871,12875,12880,12884],{"type":15,"tag":360,"props":12860,"children":12861},{"style":373},[12862],{"type":21,"value":5365},{"type":15,"tag":360,"props":12864,"children":12865},{"style":389},[12866],{"type":21,"value":2899},{"type":15,"tag":360,"props":12868,"children":12869},{"style":373},[12870],{"type":21,"value":2904},{"type":15,"tag":360,"props":12872,"children":12873},{"style":367},[12874],{"type":21,"value":2909},{"type":15,"tag":360,"props":12876,"children":12877},{"style":708},[12878],{"type":21,"value":12879}," 3600000",{"type":15,"tag":360,"props":12881,"children":12882},{"style":373},[12883],{"type":21,"value":7924},{"type":15,"tag":360,"props":12885,"children":12886},{"style":486},[12887],{"type":21,"value":12888},"// default: createdAt + 24h\n",{"type":15,"tag":360,"props":12890,"children":12891},{"class":362,"line":5336},[12892],{"type":15,"tag":360,"props":12893,"children":12894},{"emptyLinePlaceholder":839},[12895],{"type":21,"value":842},{"type":15,"tag":360,"props":12897,"children":12898},{"class":362,"line":5359},[12899],{"type":15,"tag":360,"props":12900,"children":12901},{"style":486},[12902],{"type":21,"value":12903},"    // --- Concurrency ---\n",{"type":15,"tag":360,"props":12905,"children":12906},{"class":362,"line":5413},[12907,12911,12915,12919],{"type":15,"tag":360,"props":12908,"children":12909},{"style":373},[12910],{"type":21,"value":5342},{"type":15,"tag":360,"props":12912,"children":12913},{"style":708},[12914],{"type":21,"value":2725},{"type":15,"tag":360,"props":12916,"children":12917},{"style":373},[12918],{"type":21,"value":12742},{"type":15,"tag":360,"props":12920,"children":12921},{"style":486},[12922],{"type":21,"value":12923},"// null = unlimited\n",{"type":15,"tag":360,"props":12925,"children":12926},{"class":362,"line":5421},[12927],{"type":15,"tag":360,"props":12928,"children":12929},{"emptyLinePlaceholder":839},[12930],{"type":21,"value":842},{"type":15,"tag":360,"props":12932,"children":12933},{"class":362,"line":5430},[12934],{"type":15,"tag":360,"props":12935,"children":12936},{"style":486},[12937],{"type":21,"value":12938},"    // --- Caller state ---\n",{"type":15,"tag":360,"props":12940,"children":12941},{"class":362,"line":5439},[12942,12947],{"type":15,"tag":360,"props":12943,"children":12944},{"style":373},[12945],{"type":21,"value":12946},"    context:           { }             ",{"type":15,"tag":360,"props":12948,"children":12949},{"style":486},[12950],{"type":21,"value":12951},"// forwarded to the finalizer\n",{"type":15,"tag":360,"props":12953,"children":12954},{"class":362,"line":5447},[12955],{"type":15,"tag":360,"props":12956,"children":12957},{"style":373},[12958],{"type":21,"value":944},{"type":15,"tag":325,"props":12960,"children":12962},{"id":12961},"batchexecution-methods",[12963,12968],{"type":15,"tag":254,"props":12964,"children":12966},{"className":12965},[],[12967],{"type":21,"value":12593},{"type":21,"value":12969}," Methods",{"type":15,"tag":208,"props":12971,"children":12972},{},[12973,12988],{"type":15,"tag":212,"props":12974,"children":12975},{},[12976],{"type":15,"tag":216,"props":12977,"children":12978},{},[12979,12984],{"type":15,"tag":220,"props":12980,"children":12981},{},[12982],{"type":21,"value":12983},"Method",{"type":15,"tag":220,"props":12985,"children":12986},{},[12987],{"type":21,"value":1591},{"type":15,"tag":236,"props":12989,"children":12990},{},[12991,13015,13032,13048,13077,13093],{"type":15,"tag":216,"props":12992,"children":12993},{},[12994,13003],{"type":15,"tag":243,"props":12995,"children":12996},{},[12997],{"type":15,"tag":254,"props":12998,"children":13000},{"className":12999},[],[13001],{"type":21,"value":13002},"add(actionRef, record, params)",{"type":15,"tag":243,"props":13004,"children":13005},{},[13006,13008,13013],{"type":21,"value":13007},"Schedule one child invocation. Blocks if ",{"type":15,"tag":254,"props":13009,"children":13011},{"className":13010},[],[13012],{"type":21,"value":2272},{"type":21,"value":13014}," is set and the cap is reached.",{"type":15,"tag":216,"props":13016,"children":13017},{},[13018,13027],{"type":15,"tag":243,"props":13019,"children":13020},{},[13021],{"type":15,"tag":254,"props":13022,"children":13024},{"className":13023},[],[13025],{"type":21,"value":13026},"addAll(actionRef, records, params)",{"type":15,"tag":243,"props":13028,"children":13029},{},[13030],{"type":21,"value":13031},"Convenience: same action against many records.",{"type":15,"tag":216,"props":13033,"children":13034},{},[13035,13043],{"type":15,"tag":243,"props":13036,"children":13037},{},[13038],{"type":15,"tag":254,"props":13039,"children":13041},{"className":13040},[],[13042],{"type":21,"value":1155},{"type":15,"tag":243,"props":13044,"children":13045},{},[13046],{"type":21,"value":13047},"Mark the batch fully populated. Idempotent. Required before completion can fire.",{"type":15,"tag":216,"props":13049,"children":13050},{},[13051,13060],{"type":15,"tag":243,"props":13052,"children":13053},{},[13054],{"type":15,"tag":254,"props":13055,"children":13057},{"className":13056},[],[13058],{"type":21,"value":13059},"cancel()",{"type":15,"tag":243,"props":13061,"children":13062},{},[13063,13065,13070,13071,13076],{"type":21,"value":13064},"Force the batch to ",{"type":15,"tag":254,"props":13066,"children":13068},{"className":13067},[],[13069],{"type":21,"value":1662},{"type":21,"value":4968},{"type":15,"tag":254,"props":13072,"children":13074},{"className":13073},[],[13075],{"type":21,"value":1538},{"type":21,"value":1664},{"type":15,"tag":216,"props":13078,"children":13079},{},[13080,13088],{"type":15,"tag":243,"props":13081,"children":13082},{},[13083],{"type":15,"tag":254,"props":13084,"children":13086},{"className":13085},[],[13087],{"type":21,"value":4991},{"type":15,"tag":243,"props":13089,"children":13090},{},[13091],{"type":21,"value":13092},"Read-only progress view. Reads from the database.",{"type":15,"tag":216,"props":13094,"children":13095},{},[13096,13105],{"type":15,"tag":243,"props":13097,"children":13098},{},[13099],{"type":15,"tag":254,"props":13100,"children":13102},{"className":13101},[],[13103],{"type":21,"value":13104},"getId()",{"type":15,"tag":243,"props":13106,"children":13107},{},[13108],{"type":21,"value":13109},"The batch's id; useful for logging or admin tooling.",{"type":15,"tag":325,"props":13111,"children":13113},{"id":13112},"contextcreateloopoptions",[13114],{"type":15,"tag":254,"props":13115,"children":13117},{"className":13116},[],[13118],{"type":21,"value":13119},"context.createLoop(options)",{"type":15,"tag":24,"props":13121,"children":13122},{},[13123,13124,13130],{"type":21,"value":12587},{"type":15,"tag":254,"props":13125,"children":13127},{"className":13126},[],[13128],{"type":21,"value":13129},"LoopExecution",{"type":21,"value":12595},{"type":15,"tag":350,"props":13132,"children":13134},{"className":352,"code":13133,"language":354,"meta":7,"style":7},"context.createLoop({\n    workItemType:   \"registeredWorkerName\",   // required\n    initialState:   { },\n    onComplete:     \"actionName\",\n    onError:        \"actionName\",\n    maxIterations:  1000,                     // null = no cap\n    deadlineMs:     Date.now() + 3600000,\n    context:        { }\n});\n",[13135],{"type":15,"tag":254,"props":13136,"children":13137},{"__ignoreMap":7},[13138,13153,13175,13183,13199,13215,13238,13266,13274],{"type":15,"tag":360,"props":13139,"children":13140},{"class":362,"line":363},[13141,13145,13149],{"type":15,"tag":360,"props":13142,"children":13143},{"style":373},[13144],{"type":21,"value":1234},{"type":15,"tag":360,"props":13146,"children":13147},{"style":389},[13148],{"type":21,"value":289},{"type":15,"tag":360,"props":13150,"children":13151},{"style":373},[13152],{"type":21,"value":905},{"type":15,"tag":360,"props":13154,"children":13155},{"class":362,"line":411},[13156,13161,13166,13170],{"type":15,"tag":360,"props":13157,"children":13158},{"style":373},[13159],{"type":21,"value":13160},"    workItemType:   ",{"type":15,"tag":360,"props":13162,"children":13163},{"style":400},[13164],{"type":21,"value":13165},"\"registeredWorkerName\"",{"type":15,"tag":360,"props":13167,"children":13168},{"style":373},[13169],{"type":21,"value":7924},{"type":15,"tag":360,"props":13171,"children":13172},{"style":486},[13173],{"type":21,"value":13174},"// required\n",{"type":15,"tag":360,"props":13176,"children":13177},{"class":362,"line":425},[13178],{"type":15,"tag":360,"props":13179,"children":13180},{"style":373},[13181],{"type":21,"value":13182},"    initialState:   { },\n",{"type":15,"tag":360,"props":13184,"children":13185},{"class":362,"line":449},[13186,13191,13195],{"type":15,"tag":360,"props":13187,"children":13188},{"style":373},[13189],{"type":21,"value":13190},"    onComplete:     ",{"type":15,"tag":360,"props":13192,"children":13193},{"style":400},[13194],{"type":21,"value":12637},{"type":15,"tag":360,"props":13196,"children":13197},{"style":373},[13198],{"type":21,"value":923},{"type":15,"tag":360,"props":13200,"children":13201},{"class":362,"line":482},[13202,13207,13211],{"type":15,"tag":360,"props":13203,"children":13204},{"style":373},[13205],{"type":21,"value":13206},"    onError:        ",{"type":15,"tag":360,"props":13208,"children":13209},{"style":400},[13210],{"type":21,"value":12637},{"type":15,"tag":360,"props":13212,"children":13213},{"style":373},[13214],{"type":21,"value":923},{"type":15,"tag":360,"props":13216,"children":13217},{"class":362,"line":492},[13218,13223,13228,13233],{"type":15,"tag":360,"props":13219,"children":13220},{"style":373},[13221],{"type":21,"value":13222},"    maxIterations:  ",{"type":15,"tag":360,"props":13224,"children":13225},{"style":708},[13226],{"type":21,"value":13227},"1000",{"type":15,"tag":360,"props":13229,"children":13230},{"style":373},[13231],{"type":21,"value":13232},",                     ",{"type":15,"tag":360,"props":13234,"children":13235},{"style":486},[13236],{"type":21,"value":13237},"// null = no cap\n",{"type":15,"tag":360,"props":13239,"children":13240},{"class":362,"line":501},[13241,13246,13250,13254,13258,13262],{"type":15,"tag":360,"props":13242,"children":13243},{"style":373},[13244],{"type":21,"value":13245},"    deadlineMs:     Date.",{"type":15,"tag":360,"props":13247,"children":13248},{"style":389},[13249],{"type":21,"value":2899},{"type":15,"tag":360,"props":13251,"children":13252},{"style":373},[13253],{"type":21,"value":2904},{"type":15,"tag":360,"props":13255,"children":13256},{"style":367},[13257],{"type":21,"value":2909},{"type":15,"tag":360,"props":13259,"children":13260},{"style":708},[13261],{"type":21,"value":12879},{"type":15,"tag":360,"props":13263,"children":13264},{"style":373},[13265],{"type":21,"value":923},{"type":15,"tag":360,"props":13267,"children":13268},{"class":362,"line":519},[13269],{"type":15,"tag":360,"props":13270,"children":13271},{"style":373},[13272],{"type":21,"value":13273},"    context:        { }\n",{"type":15,"tag":360,"props":13275,"children":13276},{"class":362,"line":537},[13277],{"type":15,"tag":360,"props":13278,"children":13279},{"style":373},[13280],{"type":21,"value":944},{"type":15,"tag":325,"props":13282,"children":13284},{"id":13283},"finalizer-input-fields",[13285],{"type":21,"value":13286},"Finalizer Input Fields",{"type":15,"tag":24,"props":13288,"children":13289},{},[13290,13292,13297,13299,13304],{"type":21,"value":13291},"The finalizer reads its input via ",{"type":15,"tag":254,"props":13293,"children":13295},{"className":13294},[],[13296],{"type":21,"value":1803},{"type":21,"value":13298}," (or the whole map via ",{"type":15,"tag":254,"props":13300,"children":13302},{"className":13301},[],[13303],{"type":21,"value":1567},{"type":21,"value":13305},"). Available fields:",{"type":15,"tag":208,"props":13307,"children":13308},{},[13309,13328],{"type":15,"tag":212,"props":13310,"children":13311},{},[13312],{"type":15,"tag":216,"props":13313,"children":13314},{},[13315,13319,13324],{"type":15,"tag":220,"props":13316,"children":13317},{},[13318],{"type":21,"value":1586},{"type":15,"tag":220,"props":13320,"children":13321},{},[13322],{"type":21,"value":13323},"Applies To",{"type":15,"tag":220,"props":13325,"children":13326},{},[13327],{"type":21,"value":1591},{"type":15,"tag":236,"props":13329,"children":13330},{},[13331,13352,13372,13392,13413,13433,13453,13474,13495,13523,13544,13564,13585,13605,13626],{"type":15,"tag":216,"props":13332,"children":13333},{},[13334,13342,13347],{"type":15,"tag":243,"props":13335,"children":13336},{},[13337],{"type":15,"tag":254,"props":13338,"children":13340},{"className":13339},[],[13341],{"type":21,"value":1606},{"type":15,"tag":243,"props":13343,"children":13344},{},[13345],{"type":21,"value":13346},"both",{"type":15,"tag":243,"props":13348,"children":13349},{},[13350],{"type":21,"value":13351},"The batch / loop's id",{"type":15,"tag":216,"props":13353,"children":13354},{},[13355,13363,13367],{"type":15,"tag":243,"props":13356,"children":13357},{},[13358],{"type":15,"tag":254,"props":13359,"children":13361},{"className":13360},[],[13362],{"type":21,"value":1623},{"type":15,"tag":243,"props":13364,"children":13365},{},[13366],{"type":21,"value":13346},{"type":15,"tag":243,"props":13368,"children":13369},{},[13370],{"type":21,"value":13371},"Terminal state",{"type":15,"tag":216,"props":13373,"children":13374},{},[13375,13383,13387],{"type":15,"tag":243,"props":13376,"children":13377},{},[13378],{"type":15,"tag":254,"props":13379,"children":13381},{"className":13380},[],[13382],{"type":21,"value":1751},{"type":15,"tag":243,"props":13384,"children":13385},{},[13386],{"type":21,"value":13346},{"type":15,"tag":243,"props":13388,"children":13389},{},[13390],{"type":21,"value":13391},"Human-readable reason string",{"type":15,"tag":216,"props":13393,"children":13394},{},[13395,13403,13408],{"type":15,"tag":243,"props":13396,"children":13397},{},[13398],{"type":15,"tag":254,"props":13399,"children":13401},{"className":13400},[],[13402],{"type":21,"value":1676},{"type":15,"tag":243,"props":13404,"children":13405},{},[13406],{"type":21,"value":13407},"batch",{"type":15,"tag":243,"props":13409,"children":13410},{},[13411],{"type":21,"value":13412},"Total children added",{"type":15,"tag":216,"props":13414,"children":13415},{},[13416,13424,13428],{"type":15,"tag":243,"props":13417,"children":13418},{},[13419],{"type":15,"tag":254,"props":13420,"children":13422},{"className":13421},[],[13423],{"type":21,"value":1693},{"type":15,"tag":243,"props":13425,"children":13426},{},[13427],{"type":21,"value":13407},{"type":15,"tag":243,"props":13429,"children":13430},{},[13431],{"type":21,"value":13432},"Children that succeeded",{"type":15,"tag":216,"props":13434,"children":13435},{},[13436,13444,13448],{"type":15,"tag":243,"props":13437,"children":13438},{},[13439],{"type":15,"tag":254,"props":13440,"children":13442},{"className":13441},[],[13443],{"type":21,"value":1710},{"type":15,"tag":243,"props":13445,"children":13446},{},[13447],{"type":21,"value":13407},{"type":15,"tag":243,"props":13449,"children":13450},{},[13451],{"type":21,"value":13452},"Children that failed (after retries)",{"type":15,"tag":216,"props":13454,"children":13455},{},[13456,13464,13469],{"type":15,"tag":243,"props":13457,"children":13458},{},[13459],{"type":15,"tag":254,"props":13460,"children":13462},{"className":13461},[],[13463],{"type":21,"value":12139},{"type":15,"tag":243,"props":13465,"children":13466},{},[13467],{"type":21,"value":13468},"loop",{"type":15,"tag":243,"props":13470,"children":13471},{},[13472],{"type":21,"value":13473},"How many iterations ran",{"type":15,"tag":216,"props":13475,"children":13476},{},[13477,13486,13490],{"type":15,"tag":243,"props":13478,"children":13479},{},[13480],{"type":15,"tag":254,"props":13481,"children":13483},{"className":13482},[],[13484],{"type":21,"value":13485},"createdAt",{"type":15,"tag":243,"props":13487,"children":13488},{},[13489],{"type":21,"value":13346},{"type":15,"tag":243,"props":13491,"children":13492},{},[13493],{"type":21,"value":13494},"Epoch ms when created",{"type":15,"tag":216,"props":13496,"children":13497},{},[13498,13507,13511],{"type":15,"tag":243,"props":13499,"children":13500},{},[13501],{"type":15,"tag":254,"props":13502,"children":13504},{"className":13503},[],[13505],{"type":21,"value":13506},"sealedAt",{"type":15,"tag":243,"props":13508,"children":13509},{},[13510],{"type":21,"value":13407},{"type":15,"tag":243,"props":13512,"children":13513},{},[13514,13516,13521],{"type":21,"value":13515},"When ",{"type":15,"tag":254,"props":13517,"children":13519},{"className":13518},[],[13520],{"type":21,"value":1155},{"type":21,"value":13522}," was called",{"type":15,"tag":216,"props":13524,"children":13525},{},[13526,13535,13539],{"type":15,"tag":243,"props":13527,"children":13528},{},[13529],{"type":15,"tag":254,"props":13530,"children":13532},{"className":13531},[],[13533],{"type":21,"value":13534},"completedAt",{"type":15,"tag":243,"props":13536,"children":13537},{},[13538],{"type":21,"value":13346},{"type":15,"tag":243,"props":13540,"children":13541},{},[13542],{"type":21,"value":13543},"When terminal state was reached",{"type":15,"tag":216,"props":13545,"children":13546},{},[13547,13555,13559],{"type":15,"tag":243,"props":13548,"children":13549},{},[13550],{"type":15,"tag":254,"props":13551,"children":13553},{"className":13552},[],[13554],{"type":21,"value":1727},{"type":15,"tag":243,"props":13556,"children":13557},{},[13558],{"type":21,"value":13346},{"type":15,"tag":243,"props":13560,"children":13561},{},[13562],{"type":21,"value":13563},"`completedAt - (sealedAt",{"type":15,"tag":216,"props":13565,"children":13566},{},[13567,13575,13580],{"type":15,"tag":243,"props":13568,"children":13569},{},[13570],{"type":15,"tag":254,"props":13571,"children":13573},{"className":13572},[],[13574],{"type":21,"value":1787},{"type":15,"tag":243,"props":13576,"children":13577},{},[13578],{"type":21,"value":13579},"batch (when results != COUNT)",{"type":15,"tag":243,"props":13581,"children":13582},{},[13583],{"type":21,"value":13584},"Scratchpad dataset id",{"type":15,"tag":216,"props":13586,"children":13587},{},[13588,13596,13600],{"type":15,"tag":243,"props":13589,"children":13590},{},[13591],{"type":15,"tag":254,"props":13592,"children":13594},{"className":13593},[],[13595],{"type":21,"value":12173},{"type":15,"tag":243,"props":13597,"children":13598},{},[13599],{"type":21,"value":13468},{"type":15,"tag":243,"props":13601,"children":13602},{},[13603],{"type":21,"value":13604},"Scratchpad dataset id of last state",{"type":15,"tag":216,"props":13606,"children":13607},{},[13608,13616,13621],{"type":15,"tag":243,"props":13609,"children":13610},{},[13611],{"type":15,"tag":254,"props":13612,"children":13614},{"className":13613},[],[13615],{"type":21,"value":12156},{"type":15,"tag":243,"props":13617,"children":13618},{},[13619],{"type":21,"value":13620},"loop (on STOPPED)",{"type":15,"tag":243,"props":13622,"children":13623},{},[13624],{"type":21,"value":13625},"Optional output from worker",{"type":15,"tag":216,"props":13627,"children":13628},{},[13629,13638,13643],{"type":15,"tag":243,"props":13630,"children":13631},{},[13632],{"type":15,"tag":254,"props":13633,"children":13635},{"className":13634},[],[13636],{"type":21,"value":13637},"reducerState",{"type":15,"tag":243,"props":13639,"children":13640},{},[13641],{"type":21,"value":13642},"batch (when results == REDUCE)",{"type":15,"tag":243,"props":13644,"children":13645},{},[13646],{"type":21,"value":13647},"The final accumulator",{"type":15,"tag":24,"props":13649,"children":13650},{},[13651,13653,13658,13660,13665],{"type":21,"value":13652},"Whatever you passed as ",{"type":15,"tag":254,"props":13654,"children":13656},{"className":13655},[],[13657],{"type":21,"value":1842},{"type":21,"value":13659}," when creating the batch / loop arrives as parameters, fetched with ",{"type":15,"tag":254,"props":13661,"children":13663},{"className":13662},[],[13664],{"type":21,"value":1850},{"type":21,"value":1664},{"type":15,"tag":805,"props":13667,"children":13668},{},[],{"type":15,"tag":126,"props":13670,"children":13672},{"id":13671},"common-patterns",[13673],{"type":21,"value":13674},"Common Patterns",{"type":15,"tag":325,"props":13676,"children":13678},{"id":13677},"one-finalizer-for-every-outcome",[13679],{"type":21,"value":13680},"One Finalizer for Every Outcome",{"type":15,"tag":24,"props":13682,"children":13683},{},[13684,13686,13691],{"type":21,"value":13685},"If your post-processing logic is largely shared, point all three hooks at the same action and switch on ",{"type":15,"tag":254,"props":13687,"children":13689},{"className":13688},[],[13690],{"type":21,"value":1623},{"type":21,"value":36},{"type":15,"tag":350,"props":13693,"children":13695},{"className":352,"code":13694,"language":354,"meta":7,"style":7},"let batch = context.createBatch({\n    onSuccess: \"handleBatchOutcome\",\n    onPartial: \"handleBatchOutcome\",\n    onError:   \"handleBatchOutcome\",\n    context:   { campaignId: campaign.get(\"id\") }\n});\n",[13696],{"type":15,"tag":254,"props":13697,"children":13698},{"__ignoreMap":7},[13699,13726,13742,13757,13772,13796],{"type":15,"tag":360,"props":13700,"children":13701},{"class":362,"line":363},[13702,13706,13710,13714,13718,13722],{"type":15,"tag":360,"props":13703,"children":13704},{"style":367},[13705],{"type":21,"value":370},{"type":15,"tag":360,"props":13707,"children":13708},{"style":373},[13709],{"type":21,"value":611},{"type":15,"tag":360,"props":13711,"children":13712},{"style":367},[13713],{"type":21,"value":381},{"type":15,"tag":360,"props":13715,"children":13716},{"style":373},[13717],{"type":21,"value":386},{"type":15,"tag":360,"props":13719,"children":13720},{"style":389},[13721],{"type":21,"value":259},{"type":15,"tag":360,"props":13723,"children":13724},{"style":373},[13725],{"type":21,"value":905},{"type":15,"tag":360,"props":13727,"children":13728},{"class":362,"line":411},[13729,13733,13738],{"type":15,"tag":360,"props":13730,"children":13731},{"style":373},[13732],{"type":21,"value":913},{"type":15,"tag":360,"props":13734,"children":13735},{"style":400},[13736],{"type":21,"value":13737},"\"handleBatchOutcome\"",{"type":15,"tag":360,"props":13739,"children":13740},{"style":373},[13741],{"type":21,"value":923},{"type":15,"tag":360,"props":13743,"children":13744},{"class":362,"line":425},[13745,13749,13753],{"type":15,"tag":360,"props":13746,"children":13747},{"style":373},[13748],{"type":21,"value":5247},{"type":15,"tag":360,"props":13750,"children":13751},{"style":400},[13752],{"type":21,"value":13737},{"type":15,"tag":360,"props":13754,"children":13755},{"style":373},[13756],{"type":21,"value":923},{"type":15,"tag":360,"props":13758,"children":13759},{"class":362,"line":449},[13760,13764,13768],{"type":15,"tag":360,"props":13761,"children":13762},{"style":373},[13763],{"type":21,"value":931},{"type":15,"tag":360,"props":13765,"children":13766},{"style":400},[13767],{"type":21,"value":13737},{"type":15,"tag":360,"props":13769,"children":13770},{"style":373},[13771],{"type":21,"value":923},{"type":15,"tag":360,"props":13773,"children":13774},{"class":362,"line":482},[13775,13780,13784,13788,13792],{"type":15,"tag":360,"props":13776,"children":13777},{"style":373},[13778],{"type":21,"value":13779},"    context:   { campaignId: campaign.",{"type":15,"tag":360,"props":13781,"children":13782},{"style":389},[13783],{"type":21,"value":1256},{"type":15,"tag":360,"props":13785,"children":13786},{"style":373},[13787],{"type":21,"value":397},{"type":15,"tag":360,"props":13789,"children":13790},{"style":400},[13791],{"type":21,"value":1967},{"type":15,"tag":360,"props":13793,"children":13794},{"style":373},[13795],{"type":21,"value":7407},{"type":15,"tag":360,"props":13797,"children":13798},{"class":362,"line":492},[13799],{"type":15,"tag":360,"props":13800,"children":13801},{"style":373},[13802],{"type":21,"value":944},{"type":15,"tag":350,"props":13804,"children":13806},{"className":352,"code":13805,"language":354,"meta":7,"style":7},"// Action: \"handleBatchOutcome\"\nlet state      = context.getInput(\"state\");\nlet succeeded  = context.getInput(\"succeededJobs\");\nlet failed     = context.getInput(\"failedJobs\");\nlet total      = context.getInput(\"totalJobs\");\nlet campaignId = context.getParameter(\"campaignId\");\n\nswitch (state) {\n    case \"COMPLETED\":\n        context.log(\"Campaign {} completed cleanly: {} sent\",\n            campaignId, succeeded);\n        break;\n    case \"PARTIAL\":\n        context.log(\"Campaign {} mostly succeeded: {}/{} sent, {} failed\",\n            campaignId, succeeded, total, failed);\n        break;\n    case \"FAILED\":\n    case \"TIMED_OUT\":\n    case \"CANCELLED\":\n        context.sendMail({\n            to:      \"ops@example.com\",\n            subject: \"Campaign \" + campaignId + \" ended in \" + state,\n            body:    failed + \"/\" + total + \" failed\"\n        });\n        break;\n}\n",[13807],{"type":15,"tag":254,"props":13808,"children":13809},{"__ignoreMap":7},[13810,13818,13854,13890,13926,13962,13997,14004,14017,14035,14059,14067,14079,14095,14119,14127,14138,14154,14170,14186,14201,14217,14255,14290,14297,14308],{"type":15,"tag":360,"props":13811,"children":13812},{"class":362,"line":363},[13813],{"type":15,"tag":360,"props":13814,"children":13815},{"style":486},[13816],{"type":21,"value":13817},"// Action: \"handleBatchOutcome\"\n",{"type":15,"tag":360,"props":13819,"children":13820},{"class":362,"line":411},[13821,13825,13830,13834,13838,13842,13846,13850],{"type":15,"tag":360,"props":13822,"children":13823},{"style":367},[13824],{"type":21,"value":370},{"type":15,"tag":360,"props":13826,"children":13827},{"style":373},[13828],{"type":21,"value":13829}," state      ",{"type":15,"tag":360,"props":13831,"children":13832},{"style":367},[13833],{"type":21,"value":381},{"type":15,"tag":360,"props":13835,"children":13836},{"style":373},[13837],{"type":21,"value":386},{"type":15,"tag":360,"props":13839,"children":13840},{"style":389},[13841],{"type":21,"value":1444},{"type":15,"tag":360,"props":13843,"children":13844},{"style":373},[13845],{"type":21,"value":397},{"type":15,"tag":360,"props":13847,"children":13848},{"style":400},[13849],{"type":21,"value":8857},{"type":15,"tag":360,"props":13851,"children":13852},{"style":373},[13853],{"type":21,"value":408},{"type":15,"tag":360,"props":13855,"children":13856},{"class":362,"line":425},[13857,13861,13866,13870,13874,13878,13882,13886],{"type":15,"tag":360,"props":13858,"children":13859},{"style":367},[13860],{"type":21,"value":370},{"type":15,"tag":360,"props":13862,"children":13863},{"style":373},[13864],{"type":21,"value":13865}," succeeded  ",{"type":15,"tag":360,"props":13867,"children":13868},{"style":367},[13869],{"type":21,"value":381},{"type":15,"tag":360,"props":13871,"children":13872},{"style":373},[13873],{"type":21,"value":386},{"type":15,"tag":360,"props":13875,"children":13876},{"style":389},[13877],{"type":21,"value":1444},{"type":15,"tag":360,"props":13879,"children":13880},{"style":373},[13881],{"type":21,"value":397},{"type":15,"tag":360,"props":13883,"children":13884},{"style":400},[13885],{"type":21,"value":1453},{"type":15,"tag":360,"props":13887,"children":13888},{"style":373},[13889],{"type":21,"value":408},{"type":15,"tag":360,"props":13891,"children":13892},{"class":362,"line":449},[13893,13897,13902,13906,13910,13914,13918,13922],{"type":15,"tag":360,"props":13894,"children":13895},{"style":367},[13896],{"type":21,"value":370},{"type":15,"tag":360,"props":13898,"children":13899},{"style":373},[13900],{"type":21,"value":13901}," failed     ",{"type":15,"tag":360,"props":13903,"children":13904},{"style":367},[13905],{"type":21,"value":381},{"type":15,"tag":360,"props":13907,"children":13908},{"style":373},[13909],{"type":21,"value":386},{"type":15,"tag":360,"props":13911,"children":13912},{"style":389},[13913],{"type":21,"value":1444},{"type":15,"tag":360,"props":13915,"children":13916},{"style":373},[13917],{"type":21,"value":397},{"type":15,"tag":360,"props":13919,"children":13920},{"style":400},[13921],{"type":21,"value":1477},{"type":15,"tag":360,"props":13923,"children":13924},{"style":373},[13925],{"type":21,"value":408},{"type":15,"tag":360,"props":13927,"children":13928},{"class":362,"line":482},[13929,13933,13938,13942,13946,13950,13954,13958],{"type":15,"tag":360,"props":13930,"children":13931},{"style":367},[13932],{"type":21,"value":370},{"type":15,"tag":360,"props":13934,"children":13935},{"style":373},[13936],{"type":21,"value":13937}," total      ",{"type":15,"tag":360,"props":13939,"children":13940},{"style":367},[13941],{"type":21,"value":381},{"type":15,"tag":360,"props":13943,"children":13944},{"style":373},[13945],{"type":21,"value":386},{"type":15,"tag":360,"props":13947,"children":13948},{"style":389},[13949],{"type":21,"value":1444},{"type":15,"tag":360,"props":13951,"children":13952},{"style":373},[13953],{"type":21,"value":397},{"type":15,"tag":360,"props":13955,"children":13956},{"style":400},[13957],{"type":21,"value":1501},{"type":15,"tag":360,"props":13959,"children":13960},{"style":373},[13961],{"type":21,"value":408},{"type":15,"tag":360,"props":13963,"children":13964},{"class":362,"line":492},[13965,13969,13973,13977,13981,13985,13989,13993],{"type":15,"tag":360,"props":13966,"children":13967},{"style":367},[13968],{"type":21,"value":370},{"type":15,"tag":360,"props":13970,"children":13971},{"style":373},[13972],{"type":21,"value":5057},{"type":15,"tag":360,"props":13974,"children":13975},{"style":367},[13976],{"type":21,"value":381},{"type":15,"tag":360,"props":13978,"children":13979},{"style":373},[13980],{"type":21,"value":386},{"type":15,"tag":360,"props":13982,"children":13983},{"style":389},[13984],{"type":21,"value":2067},{"type":15,"tag":360,"props":13986,"children":13987},{"style":373},[13988],{"type":21,"value":397},{"type":15,"tag":360,"props":13990,"children":13991},{"style":400},[13992],{"type":21,"value":2119},{"type":15,"tag":360,"props":13994,"children":13995},{"style":373},[13996],{"type":21,"value":408},{"type":15,"tag":360,"props":13998,"children":13999},{"class":362,"line":501},[14000],{"type":15,"tag":360,"props":14001,"children":14002},{"emptyLinePlaceholder":839},[14003],{"type":21,"value":842},{"type":15,"tag":360,"props":14005,"children":14006},{"class":362,"line":519},[14007,14012],{"type":15,"tag":360,"props":14008,"children":14009},{"style":367},[14010],{"type":21,"value":14011},"switch",{"type":15,"tag":360,"props":14013,"children":14014},{"style":373},[14015],{"type":21,"value":14016}," (state) {\n",{"type":15,"tag":360,"props":14018,"children":14019},{"class":362,"line":537},[14020,14025,14030],{"type":15,"tag":360,"props":14021,"children":14022},{"style":367},[14023],{"type":21,"value":14024},"    case",{"type":15,"tag":360,"props":14026,"children":14027},{"style":400},[14028],{"type":21,"value":14029}," \"COMPLETED\"",{"type":15,"tag":360,"props":14031,"children":14032},{"style":373},[14033],{"type":21,"value":14034},":\n",{"type":15,"tag":360,"props":14036,"children":14037},{"class":362,"line":773},[14038,14042,14046,14050,14055],{"type":15,"tag":360,"props":14039,"children":14040},{"style":373},[14041],{"type":21,"value":3752},{"type":15,"tag":360,"props":14043,"children":14044},{"style":389},[14045],{"type":21,"value":1418},{"type":15,"tag":360,"props":14047,"children":14048},{"style":373},[14049],{"type":21,"value":397},{"type":15,"tag":360,"props":14051,"children":14052},{"style":400},[14053],{"type":21,"value":14054},"\"Campaign {} completed cleanly: {} sent\"",{"type":15,"tag":360,"props":14056,"children":14057},{"style":373},[14058],{"type":21,"value":923},{"type":15,"tag":360,"props":14060,"children":14061},{"class":362,"line":1016},[14062],{"type":15,"tag":360,"props":14063,"children":14064},{"style":373},[14065],{"type":21,"value":14066},"            campaignId, succeeded);\n",{"type":15,"tag":360,"props":14068,"children":14069},{"class":362,"line":1024},[14070,14075],{"type":15,"tag":360,"props":14071,"children":14072},{"style":367},[14073],{"type":21,"value":14074},"        break",{"type":15,"tag":360,"props":14076,"children":14077},{"style":373},[14078],{"type":21,"value":9667},{"type":15,"tag":360,"props":14080,"children":14081},{"class":362,"line":1040},[14082,14086,14091],{"type":15,"tag":360,"props":14083,"children":14084},{"style":367},[14085],{"type":21,"value":14024},{"type":15,"tag":360,"props":14087,"children":14088},{"style":400},[14089],{"type":21,"value":14090}," \"PARTIAL\"",{"type":15,"tag":360,"props":14092,"children":14093},{"style":373},[14094],{"type":21,"value":14034},{"type":15,"tag":360,"props":14096,"children":14097},{"class":362,"line":1056},[14098,14102,14106,14110,14115],{"type":15,"tag":360,"props":14099,"children":14100},{"style":373},[14101],{"type":21,"value":3752},{"type":15,"tag":360,"props":14103,"children":14104},{"style":389},[14105],{"type":21,"value":1418},{"type":15,"tag":360,"props":14107,"children":14108},{"style":373},[14109],{"type":21,"value":397},{"type":15,"tag":360,"props":14111,"children":14112},{"style":400},[14113],{"type":21,"value":14114},"\"Campaign {} mostly succeeded: {}/{} sent, {} failed\"",{"type":15,"tag":360,"props":14116,"children":14117},{"style":373},[14118],{"type":21,"value":923},{"type":15,"tag":360,"props":14120,"children":14121},{"class":362,"line":1072},[14122],{"type":15,"tag":360,"props":14123,"children":14124},{"style":373},[14125],{"type":21,"value":14126},"            campaignId, succeeded, total, failed);\n",{"type":15,"tag":360,"props":14128,"children":14129},{"class":362,"line":5296},[14130,14134],{"type":15,"tag":360,"props":14131,"children":14132},{"style":367},[14133],{"type":21,"value":14074},{"type":15,"tag":360,"props":14135,"children":14136},{"style":373},[14137],{"type":21,"value":9667},{"type":15,"tag":360,"props":14139,"children":14140},{"class":362,"line":5319},[14141,14145,14150],{"type":15,"tag":360,"props":14142,"children":14143},{"style":367},[14144],{"type":21,"value":14024},{"type":15,"tag":360,"props":14146,"children":14147},{"style":400},[14148],{"type":21,"value":14149}," \"FAILED\"",{"type":15,"tag":360,"props":14151,"children":14152},{"style":373},[14153],{"type":21,"value":14034},{"type":15,"tag":360,"props":14155,"children":14156},{"class":362,"line":5336},[14157,14161,14166],{"type":15,"tag":360,"props":14158,"children":14159},{"style":367},[14160],{"type":21,"value":14024},{"type":15,"tag":360,"props":14162,"children":14163},{"style":400},[14164],{"type":21,"value":14165}," \"TIMED_OUT\"",{"type":15,"tag":360,"props":14167,"children":14168},{"style":373},[14169],{"type":21,"value":14034},{"type":15,"tag":360,"props":14171,"children":14172},{"class":362,"line":5359},[14173,14177,14182],{"type":15,"tag":360,"props":14174,"children":14175},{"style":367},[14176],{"type":21,"value":14024},{"type":15,"tag":360,"props":14178,"children":14179},{"style":400},[14180],{"type":21,"value":14181}," \"CANCELLED\"",{"type":15,"tag":360,"props":14183,"children":14184},{"style":373},[14185],{"type":21,"value":14034},{"type":15,"tag":360,"props":14187,"children":14188},{"class":362,"line":5413},[14189,14193,14197],{"type":15,"tag":360,"props":14190,"children":14191},{"style":373},[14192],{"type":21,"value":3752},{"type":15,"tag":360,"props":14194,"children":14195},{"style":389},[14196],{"type":21,"value":1239},{"type":15,"tag":360,"props":14198,"children":14199},{"style":373},[14200],{"type":21,"value":905},{"type":15,"tag":360,"props":14202,"children":14203},{"class":362,"line":5421},[14204,14209,14213],{"type":15,"tag":360,"props":14205,"children":14206},{"style":373},[14207],{"type":21,"value":14208},"            to:      ",{"type":15,"tag":360,"props":14210,"children":14211},{"style":400},[14212],{"type":21,"value":8418},{"type":15,"tag":360,"props":14214,"children":14215},{"style":373},[14216],{"type":21,"value":923},{"type":15,"tag":360,"props":14218,"children":14219},{"class":362,"line":5430},[14220,14225,14229,14233,14237,14241,14246,14250],{"type":15,"tag":360,"props":14221,"children":14222},{"style":373},[14223],{"type":21,"value":14224},"            subject: ",{"type":15,"tag":360,"props":14226,"children":14227},{"style":400},[14228],{"type":21,"value":6489},{"type":15,"tag":360,"props":14230,"children":14231},{"style":367},[14232],{"type":21,"value":6494},{"type":15,"tag":360,"props":14234,"children":14235},{"style":373},[14236],{"type":21,"value":5057},{"type":15,"tag":360,"props":14238,"children":14239},{"style":367},[14240],{"type":21,"value":2909},{"type":15,"tag":360,"props":14242,"children":14243},{"style":400},[14244],{"type":21,"value":14245}," \" ended in \"",{"type":15,"tag":360,"props":14247,"children":14248},{"style":367},[14249],{"type":21,"value":6494},{"type":15,"tag":360,"props":14251,"children":14252},{"style":373},[14253],{"type":21,"value":14254}," state,\n",{"type":15,"tag":360,"props":14256,"children":14257},{"class":362,"line":5439},[14258,14263,14267,14272,14276,14281,14285],{"type":15,"tag":360,"props":14259,"children":14260},{"style":373},[14261],{"type":21,"value":14262},"            body:    failed ",{"type":15,"tag":360,"props":14264,"children":14265},{"style":367},[14266],{"type":21,"value":2909},{"type":15,"tag":360,"props":14268,"children":14269},{"style":400},[14270],{"type":21,"value":14271}," \"/\"",{"type":15,"tag":360,"props":14273,"children":14274},{"style":367},[14275],{"type":21,"value":6494},{"type":15,"tag":360,"props":14277,"children":14278},{"style":373},[14279],{"type":21,"value":14280}," total ",{"type":15,"tag":360,"props":14282,"children":14283},{"style":367},[14284],{"type":21,"value":2909},{"type":15,"tag":360,"props":14286,"children":14287},{"style":400},[14288],{"type":21,"value":14289}," \" failed\"\n",{"type":15,"tag":360,"props":14291,"children":14292},{"class":362,"line":5447},[14293],{"type":15,"tag":360,"props":14294,"children":14295},{"style":373},[14296],{"type":21,"value":5538},{"type":15,"tag":360,"props":14298,"children":14299},{"class":362,"line":5455},[14300,14304],{"type":15,"tag":360,"props":14301,"children":14302},{"style":367},[14303],{"type":21,"value":14074},{"type":15,"tag":360,"props":14305,"children":14306},{"style":373},[14307],{"type":21,"value":9667},{"type":15,"tag":360,"props":14309,"children":14310},{"class":362,"line":5467},[14311],{"type":15,"tag":360,"props":14312,"children":14313},{"style":373},[14314],{"type":21,"value":543},{"type":15,"tag":325,"props":14316,"children":14318},{"id":14317},"returning-a-batch-id-for-a-job-status-ui",[14319],{"type":21,"value":14320},"Returning a Batch ID for a \"Job Status\" UI",{"type":15,"tag":24,"props":14322,"children":14323},{},[14324],{"type":21,"value":14325},"When a UI button kicks off a batch, returning the batch id lets you build an admin view that shows running jobs and their progress:",{"type":15,"tag":350,"props":14327,"children":14329},{"className":352,"code":14328,"language":354,"meta":7,"style":7},"// At the end of \"sendCampaign\":\ncontext.return({\n    message: \"Campaign queued for \"\n             + batch.snapshot().get(\"totalJobs\") + \" recipients\",\n    batchId: batch.getId()\n});\n",[14330],{"type":15,"tag":254,"props":14331,"children":14332},{"__ignoreMap":7},[14333,14341,14356,14367,14414,14429],{"type":15,"tag":360,"props":14334,"children":14335},{"class":362,"line":363},[14336],{"type":15,"tag":360,"props":14337,"children":14338},{"style":486},[14339],{"type":21,"value":14340},"// At the end of \"sendCampaign\":\n",{"type":15,"tag":360,"props":14342,"children":14343},{"class":362,"line":411},[14344,14348,14352],{"type":15,"tag":360,"props":14345,"children":14346},{"style":373},[14347],{"type":21,"value":1234},{"type":15,"tag":360,"props":14349,"children":14350},{"style":389},[14351],{"type":21,"value":4485},{"type":15,"tag":360,"props":14353,"children":14354},{"style":373},[14355],{"type":21,"value":905},{"type":15,"tag":360,"props":14357,"children":14358},{"class":362,"line":425},[14359,14363],{"type":15,"tag":360,"props":14360,"children":14361},{"style":373},[14362],{"type":21,"value":5636},{"type":15,"tag":360,"props":14364,"children":14365},{"style":400},[14366],{"type":21,"value":5641},{"type":15,"tag":360,"props":14368,"children":14369},{"class":362,"line":449},[14370,14374,14378,14382,14386,14390,14394,14398,14402,14406,14410],{"type":15,"tag":360,"props":14371,"children":14372},{"style":367},[14373],{"type":21,"value":5650},{"type":15,"tag":360,"props":14375,"children":14376},{"style":373},[14377],{"type":21,"value":4796},{"type":15,"tag":360,"props":14379,"children":14380},{"style":389},[14381],{"type":21,"value":4801},{"type":15,"tag":360,"props":14383,"children":14384},{"style":373},[14385],{"type":21,"value":5074},{"type":15,"tag":360,"props":14387,"children":14388},{"style":389},[14389],{"type":21,"value":1256},{"type":15,"tag":360,"props":14391,"children":14392},{"style":373},[14393],{"type":21,"value":397},{"type":15,"tag":360,"props":14395,"children":14396},{"style":400},[14397],{"type":21,"value":1501},{"type":15,"tag":360,"props":14399,"children":14400},{"style":373},[14401],{"type":21,"value":3594},{"type":15,"tag":360,"props":14403,"children":14404},{"style":367},[14405],{"type":21,"value":2909},{"type":15,"tag":360,"props":14407,"children":14408},{"style":400},[14409],{"type":21,"value":5687},{"type":15,"tag":360,"props":14411,"children":14412},{"style":373},[14413],{"type":21,"value":923},{"type":15,"tag":360,"props":14415,"children":14416},{"class":362,"line":482},[14417,14421,14425],{"type":15,"tag":360,"props":14418,"children":14419},{"style":373},[14420],{"type":21,"value":5700},{"type":15,"tag":360,"props":14422,"children":14423},{"style":389},[14424],{"type":21,"value":5705},{"type":15,"tag":360,"props":14426,"children":14427},{"style":373},[14428],{"type":21,"value":5710},{"type":15,"tag":360,"props":14430,"children":14431},{"class":362,"line":492},[14432],{"type":15,"tag":360,"props":14433,"children":14434},{"style":373},[14435],{"type":21,"value":944},{"type":15,"tag":24,"props":14437,"children":14438},{},[14439,14441,14447,14449,14455],{"type":21,"value":14440},"The UI can store ",{"type":15,"tag":254,"props":14442,"children":14444},{"className":14443},[],[14445],{"type":21,"value":14446},"batchId",{"type":21,"value":14448}," and poll a server action that calls ",{"type":15,"tag":254,"props":14450,"children":14452},{"className":14451},[],[14453],{"type":21,"value":14454},"batch.snapshot()",{"type":21,"value":14456}," to render a live progress bar.",{"type":15,"tag":325,"props":14458,"children":14460},{"id":14459},"periodic-cleanup-with-a-loop",[14461],{"type":21,"value":14462},"Periodic Cleanup with a Loop",{"type":15,"tag":24,"props":14464,"children":14465},{},[14466],{"type":21,"value":14467},"Loops are a natural fit for \"keep doing X until there's no more X\":",{"type":15,"tag":350,"props":14469,"children":14471},{"className":352,"code":14470,"language":354,"meta":7,"style":7},"context.createLoop({\n    workItemType: \"pruneOldThumbnails\",\n    initialState: { cursor: null },\n    onComplete:   \"cleanupDone\",\n    deadlineMs:   Date.now() + 6 * 60 * 60 * 1000\n});\n",[14472],{"type":15,"tag":254,"props":14473,"children":14474},{"__ignoreMap":7},[14475,14490,14507,14523,14540,14590],{"type":15,"tag":360,"props":14476,"children":14477},{"class":362,"line":363},[14478,14482,14486],{"type":15,"tag":360,"props":14479,"children":14480},{"style":373},[14481],{"type":21,"value":1234},{"type":15,"tag":360,"props":14483,"children":14484},{"style":389},[14485],{"type":21,"value":289},{"type":15,"tag":360,"props":14487,"children":14488},{"style":373},[14489],{"type":21,"value":905},{"type":15,"tag":360,"props":14491,"children":14492},{"class":362,"line":411},[14493,14498,14503],{"type":15,"tag":360,"props":14494,"children":14495},{"style":373},[14496],{"type":21,"value":14497},"    workItemType: ",{"type":15,"tag":360,"props":14499,"children":14500},{"style":400},[14501],{"type":21,"value":14502},"\"pruneOldThumbnails\"",{"type":15,"tag":360,"props":14504,"children":14505},{"style":373},[14506],{"type":21,"value":923},{"type":15,"tag":360,"props":14508,"children":14509},{"class":362,"line":425},[14510,14515,14519],{"type":15,"tag":360,"props":14511,"children":14512},{"style":373},[14513],{"type":21,"value":14514},"    initialState: { cursor: ",{"type":15,"tag":360,"props":14516,"children":14517},{"style":708},[14518],{"type":21,"value":711},{"type":15,"tag":360,"props":14520,"children":14521},{"style":373},[14522],{"type":21,"value":11894},{"type":15,"tag":360,"props":14524,"children":14525},{"class":362,"line":449},[14526,14531,14536],{"type":15,"tag":360,"props":14527,"children":14528},{"style":373},[14529],{"type":21,"value":14530},"    onComplete:   ",{"type":15,"tag":360,"props":14532,"children":14533},{"style":400},[14534],{"type":21,"value":14535},"\"cleanupDone\"",{"type":15,"tag":360,"props":14537,"children":14538},{"style":373},[14539],{"type":21,"value":923},{"type":15,"tag":360,"props":14541,"children":14542},{"class":362,"line":482},[14543,14548,14552,14556,14560,14565,14569,14573,14577,14581,14585],{"type":15,"tag":360,"props":14544,"children":14545},{"style":373},[14546],{"type":21,"value":14547},"    deadlineMs:   Date.",{"type":15,"tag":360,"props":14549,"children":14550},{"style":389},[14551],{"type":21,"value":2899},{"type":15,"tag":360,"props":14553,"children":14554},{"style":373},[14555],{"type":21,"value":2904},{"type":15,"tag":360,"props":14557,"children":14558},{"style":367},[14559],{"type":21,"value":2909},{"type":15,"tag":360,"props":14561,"children":14562},{"style":708},[14563],{"type":21,"value":14564}," 6",{"type":15,"tag":360,"props":14566,"children":14567},{"style":367},[14568],{"type":21,"value":2919},{"type":15,"tag":360,"props":14570,"children":14571},{"style":708},[14572],{"type":21,"value":2924},{"type":15,"tag":360,"props":14574,"children":14575},{"style":367},[14576],{"type":21,"value":2919},{"type":15,"tag":360,"props":14578,"children":14579},{"style":708},[14580],{"type":21,"value":2924},{"type":15,"tag":360,"props":14582,"children":14583},{"style":367},[14584],{"type":21,"value":2919},{"type":15,"tag":360,"props":14586,"children":14587},{"style":708},[14588],{"type":21,"value":14589}," 1000\n",{"type":15,"tag":360,"props":14591,"children":14592},{"class":362,"line":492},[14593],{"type":15,"tag":360,"props":14594,"children":14595},{"style":373},[14596],{"type":21,"value":944},{"type":15,"tag":24,"props":14598,"children":14599},{},[14600,14602,14608,14610,14616],{"type":21,"value":14601},"The Java-side ",{"type":15,"tag":254,"props":14603,"children":14605},{"className":14604},[],[14606],{"type":21,"value":14607},"pruneOldThumbnails",{"type":21,"value":14609}," worker deletes thumbnails older than 90 days in pages of 1000, and reports ",{"type":15,"tag":254,"props":14611,"children":14613},{"className":14612},[],[14614],{"type":21,"value":14615},"STOP",{"type":21,"value":14617}," when the page is empty.",{"type":15,"tag":805,"props":14619,"children":14620},{},[],{"type":15,"tag":126,"props":14622,"children":14624},{"id":14623},"what-admins-see",[14625],{"type":21,"value":14626},"What Admins See",{"type":15,"tag":24,"props":14628,"children":14629},{},[14630,14632,14638],{"type":21,"value":14631},"Operators have visibility into running and recent batches via JMX (",{"type":15,"tag":254,"props":14633,"children":14635},{"className":14634},[],[14636],{"type":21,"value":14637},"jconsole",{"type":21,"value":14639}," or any Java monitoring tool):",{"type":15,"tag":38,"props":14641,"children":14642},{},[14643,14648,14659],{"type":15,"tag":42,"props":14644,"children":14645},{},[14646],{"type":21,"value":14647},"Counters showing how many batches are starting, completing, failing, timing out across the JVM's lifetime — useful for trending.",{"type":15,"tag":42,"props":14649,"children":14650},{},[14651,14653,14658],{"type":21,"value":14652},"Latency: average and max time from ",{"type":15,"tag":254,"props":14654,"children":14656},{"className":14655},[],[14657],{"type":21,"value":1155},{"type":21,"value":1739},{"type":15,"tag":42,"props":14660,"children":14661},{},[14662],{"type":21,"value":14663},"Live operations they can invoke: force-terminate a runaway batch, replay a finalizer that didn't run cleanly.",{"type":15,"tag":24,"props":14665,"children":14666},{},[14667],{"type":21,"value":14668},"You don't usually need to think about this — it's there for the rare day when something genuinely goes wrong and an operator needs to investigate. But it's worth knowing the operations are available; if you're debugging a stuck batch with the ops team, they have tools.",{"type":15,"tag":805,"props":14670,"children":14671},{},[],{"type":15,"tag":126,"props":14673,"children":14675},{"id":14674},"three-habits-that-pay-off",[14676],{"type":21,"value":14677},"Three Habits That Pay Off",{"type":15,"tag":24,"props":14679,"children":14680},{},[14681],{"type":21,"value":14682},"The system rewards three habits:",{"type":15,"tag":1084,"props":14684,"children":14685},{},[14686,14696,14713],{"type":15,"tag":42,"props":14687,"children":14688},{},[14689,14694],{"type":15,"tag":30,"props":14690,"children":14691},{},[14692],{"type":21,"value":14693},"Trust the platform's safety nets.",{"type":21,"value":14695}," Don't write your own retry loops; don't write your own deadline tracking; don't write your own deduplication. The platform does these correctly. Your code should focus on the business logic of one child invocation.",{"type":15,"tag":42,"props":14697,"children":14698},{},[14699,14704,14706,14711],{"type":15,"tag":30,"props":14700,"children":14701},{},[14702],{"type":21,"value":14703},"Be deliberate about result modes.",{"type":21,"value":14705}," ",{"type":15,"tag":254,"props":14707,"children":14709},{"className":14708},[],[14710],{"type":21,"value":3354},{"type":21,"value":14712}," is free and almost always enough. Move up the cost ladder only when the finalizer genuinely needs the data.",{"type":15,"tag":42,"props":14714,"children":14715},{},[14716,14721],{"type":15,"tag":30,"props":14717,"children":14718},{},[14719],{"type":21,"value":14720},"Write small, idempotent child actions.",{"type":21,"value":14722}," A child action that's safe to run twice is a child action you'll never have to debug at 3am.",{"type":15,"tag":24,"props":14724,"children":14725},{},[14726],{"type":21,"value":14727},"If you find yourself fighting the system — writing complicated state-tracking code, ad-hoc retry loops, manual progress queues — there's almost certainly a simpler way using the primitives in this guide. Reach out before you build something custom.",{"type":15,"tag":805,"props":14729,"children":14730},{},[],{"type":15,"tag":126,"props":14732,"children":14734},{"id":14733},"next-steps",[14735],{"type":21,"value":14736},"Next Steps",{"type":15,"tag":38,"props":14738,"children":14739},{},[14740,14751,14762],{"type":15,"tag":42,"props":14741,"children":14742},{},[14743,14749],{"type":15,"tag":10136,"props":14744,"children":14746},{"href":14745},"/guides/rules-and-actions",[14747],{"type":21,"value":14748},"Rules and Actions",{"type":21,"value":14750}," — Learn the basics of action scripts and triggers.",{"type":15,"tag":42,"props":14752,"children":14753},{},[14754,14760],{"type":15,"tag":10136,"props":14755,"children":14757},{"href":14756},"/guides/performance",[14758],{"type":21,"value":14759},"Performance",{"type":21,"value":14761}," — Optimise your applications for speed and efficiency.",{"type":15,"tag":42,"props":14763,"children":14764},{},[14765,14771],{"type":15,"tag":10136,"props":14766,"children":14768},{"href":14767},"/guides/api-integration",[14769],{"type":21,"value":14770},"API Integration",{"type":21,"value":14772}," — Combine batches with external service calls.",{"type":15,"tag":14774,"props":14775,"children":14776},"style",{},[14777],{"type":21,"value":14778},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":411,"depth":411,"links":14780},[14781,14782,14783,14786,14787,14795,14796,14797,14798,14799,14801,14812,14813,14822,14823,14824,14831,14836,14837,14838],{"id":128,"depth":411,"text":131},{"id":198,"depth":411,"text":201},{"id":315,"depth":411,"text":318,"children":14784},[14785],{"id":327,"depth":425,"text":330},{"id":810,"depth":411,"text":813},{"id":1517,"depth":411,"text":1520,"children":14788},[14789,14791,14793],{"id":1558,"depth":425,"text":14790},"Channel 1: Platform-Supplied Input — context.getInput()",{"id":1815,"depth":425,"text":14792},"Channel 2: Caller-Supplied Parameters — context.getParameter()",{"id":2243,"depth":425,"text":14794},"What Is Not in the Finalizer's Input",{"id":2308,"depth":411,"text":2311},{"id":2387,"depth":411,"text":2390},{"id":2587,"depth":411,"text":2590},{"id":2783,"depth":411,"text":2786},{"id":2970,"depth":411,"text":14800},"Concurrency Control: maxConcurrent",{"id":3324,"depth":411,"text":3327,"children":14802},[14803,14805,14807,14809,14811],{"id":3347,"depth":425,"text":14804},"COUNT (default)",{"id":3403,"depth":425,"text":14806},"FAILURES_ONLY — Best for Debugging",{"id":3843,"depth":425,"text":14808},"PERSIST — Store Every Result",{"id":4229,"depth":425,"text":14810},"REDUCE — Aggregate as You Go",{"id":4633,"depth":425,"text":4636},{"id":4753,"depth":411,"text":4756},{"id":4999,"depth":411,"text":5002,"children":14814},[14815,14816,14817,14818,14819,14820,14821],{"id":5010,"depth":425,"text":5013},{"id":6641,"depth":425,"text":6644},{"id":7659,"depth":425,"text":7662},{"id":9166,"depth":425,"text":9169},{"id":10651,"depth":425,"text":10654},{"id":11316,"depth":425,"text":11319},{"id":11803,"depth":425,"text":11806},{"id":12327,"depth":411,"text":12330},{"id":12408,"depth":411,"text":12411},{"id":12569,"depth":411,"text":12572,"children":14825},[14826,14827,14829,14830],{"id":12575,"depth":425,"text":12582},{"id":12961,"depth":425,"text":14828},"BatchExecution Methods",{"id":13112,"depth":425,"text":13119},{"id":13283,"depth":425,"text":13286},{"id":13671,"depth":411,"text":13674,"children":14832},[14833,14834,14835],{"id":13677,"depth":425,"text":13680},{"id":14317,"depth":425,"text":14320},{"id":14459,"depth":425,"text":14462},{"id":14623,"depth":411,"text":14626},{"id":14674,"depth":411,"text":14677},{"id":14733,"depth":411,"text":14736},"markdown","content:guides:distributed-execution.md","content","guides/distributed-execution.md","guides/distributed-execution","md",1777469543933]