Mirror of https://github.com/roostorg/coop github.com/roostorg/coop
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Kysely] Migrate backtests and retroaction out of sequelize (#290)

* [Kysely] Migrate backtests and retroaction out of sequelize

* disable again

authored by

Juan Mrad and committed by
GitHub
44e9ae40 18d06ca7

+21 -109
+21 -109
server/graphql/datasources/RuleApi.ts
··· 7 7 import { uid } from 'uid'; 8 8 9 9 import { inject, type Dependencies } from '../../iocContainer/index.js'; 10 + import { type Backtest } from '../../models/rules/BacktestModel.js'; 10 11 import { type User } from '../../models/UserModel.js'; 11 12 import { type ActionCountsInput } from '../../services/actionStatisticsService/index.js'; 12 13 import { type AggregationClause } from '../../services/aggregationsService/index.js'; ··· 49 50 type GQLConditionInput, 50 51 type GQLConditionInputFieldInput, 51 52 type GQLConditionSetInput, 53 + type GQLCreateBacktestInput, 52 54 type GQLCreateContentRuleInput, 53 55 type GQLCreateUserRuleInput, 54 56 type GQLRunRetroactionInput, ··· 644 646 } 645 647 } 646 648 647 - async createBacktest(_input: unknown, _user: User) { 648 - throw new Error('Not Implemented'); 649 - 650 - // const id = uid(); 651 - // const rule = await this.models.Rule.findByPk(input.ruleId, { 652 - // rejectOnEmpty: true, 653 - // }); 654 - // const ruleContentTypes = await rule.getContentTypes(); 655 - 656 - // if (!ruleContentTypes.length) { 657 - // throw new Error( 658 - // "Rule is not attached to any content types, so we're " + 659 - // 'unable to select content to use for the backtest.', 660 - // ); 661 - // } 662 - 663 - // const backest = this.models.Backtest.build({ 664 - // id, 665 - // ruleId: input.ruleId, 666 - // sampleDesiredSize: input.sampleDesiredSize, 667 - // sampleStartAt: new Date(input.sampleStartAt), 668 - // sampleEndAt: new Date(input.sampleEndAt), 669 - // creatorId: user.id, 670 - // }); 671 - 672 - // await backest.save(); 673 - 674 - // // Start sampling and enqueueing the sampled items, but do this without 675 - // // awaiting so that we can return to the frontend immediately. 676 - // // 677 - // // Our query ignores legacy submissions that didn't store their content type 678 - // // schema at the time of submission, as we can't interpret those reliably 679 - // // when backtesting. This also has the effect of excluding all rows which 680 - // // didn't log their submission id or item type id (which is what we want, 681 - // // since those fields are required, and we started logging them before 682 - // // logging `schema`). The use of FixSingleTableSelectRowType gets the types 683 - // // to be aware of all our WHERE clause filters and their implications for 684 - // // the other columns. 685 - // // prettier-ignore 686 - // this.getItemSubmissionsFromWarehouse({ 687 - // orgId: user.orgId, 688 - // randomSample: true, 689 - // numRows: input.sampleDesiredSize, 690 - // startAt: new Date(input.sampleStartAt), 691 - // endAt: new Date(input.sampleEndAt), 692 - // itemTypeIds: ruleContentTypes.map(ct => ct.id), 693 - // }).then(async (submissions) => { 694 - // const ruleSetExecutionJobs = submissions.map((it) => ({ 695 - // orgId: user.orgId, 696 - // ruleIds: [input.ruleId], 697 - // itemSubmission: it, 698 - // environment: RuleEnvironment.BACKTEST, 699 - // correlationId: toCorrelationId({ type: 'backtest', id }), 700 - // })); 701 - 702 - // const { failures } = await this.ruleScheduler.enqueueRuleSetExecutions( 703 - // ruleSetExecutionJobs, 704 - // ); 705 - 706 - // const sampleActualSize = submissions.length - failures.length; 707 - // await backest.update({ sampleActualSize, samplingComplete: true }); 708 - // }) 709 - // .catch((e) => { 710 - // const span = this.tracer.getActiveSpan(); 711 - // span?.recordException(e); 712 - // }); 713 - 714 - // return backest; 649 + /** 650 + * TODO(BACKTEST_RETROACTION): Re-enable the Kysely + warehouse + RuleEngine flow when product UI 651 + * exposes backtests again and we can routinely validate against real CONTENT_API_REQUESTS data and 652 + * RULE_EXECUTIONS logging in dev/staging. Restore `RuleEngine` + `getItemTypeEventuallyConsistent` 653 + * on this class, `kyselyInsertBacktestRow` / `kyselyUpdateBacktestSamplingOutcome` in 654 + * `ruleKyselyPersistence.ts`, and the deleted private helpers (`getContentItemTypeIdsForRule`, 655 + * `runSampledRuleExecutions`, `queryWarehouseSubmissionsForRule`). 656 + */ 657 + async createBacktest(_input: GQLCreateBacktestInput, _user: User): Promise<Backtest> { 658 + throw new Error( 659 + 'createBacktest is temporarily disabled (TODO BACKTEST_RETROACTION: no UI / env to validate).', 660 + ); 715 661 } 716 662 717 663 async getBacktestResults( ··· 814 760 * of content on which it will run. That prevents us from accidentally 815 761 * turning this on and overloading our node servers, and is sufficient 816 762 * for the Slack demo. 763 + * 764 + * TODO(BACKTEST_RETROACTION): Same as `createBacktest` — re-enable when UI and env 765 + * support validation. 817 766 */ 818 - async runRetroaction(_input: GQLRunRetroactionInput, _user: User) { 819 - throw new Error('Not Implemented'); 820 - 821 - // const rule = await this.models.Rule.findByPk(input.ruleId, { 822 - // rejectOnEmpty: true, 823 - // }); 824 - // const ruleContentTypes = await rule.getContentTypes(); 825 - 826 - // if (!ruleContentTypes.length) { 827 - // throw new Error( 828 - // "Rule is not attached to any content types, so we're " + 829 - // 'unable to select content to use for the backtest.', 830 - // ); 831 - // } 832 - 833 - // const id = uid(); 834 - // const submissions = await this.getItemSubmissionsFromWarehouse({ 835 - // orgId: user.orgId, 836 - // itemTypeIds: ruleContentTypes.map((ct) => ct.id), 837 - // randomSample: false, 838 - // numRows: 100, // TODO: Remove the limit, and instead batch this query 839 - // startAt: new Date(input.startAt), 840 - // endAt: new Date(input.endAt), 841 - // }); 842 - 843 - // try { 844 - // const { failures } = await this.ruleScheduler.enqueueRuleSetExecutions( 845 - // submissions.map((it) => ({ 846 - // orgId: user.orgId, 847 - // ruleIds: [input.ruleId], 848 - // itemSubmission: it, 849 - // environment: RuleEnvironment.RETROACTION, 850 - // correlationId: toCorrelationId({ type: 'retroaction', id }), 851 - // })), 852 - // ); 853 - 854 - // return { _: !failures.length }; 855 - // } catch (e) { 856 - // this.tracer.getActiveSpan()?.recordException(e as Exception); 857 - // return { _: false }; 858 - // } 767 + async runRetroaction(_input: GQLRunRetroactionInput, _user: User): Promise<{ _: boolean }> { 768 + throw new Error( 769 + 'runRetroaction is temporarily disabled (TODO BACKTEST_RETROACTION: no UI / env to validate).', 770 + ); 859 771 } 860 772 861 773 /**