Skip to content

Commit dba3dd1

Browse files
author
Alex Stelea
committed
fix: use same ref of incentivesVesterConfig
1 parent 3e8691c commit dba3dd1

6 files changed

Lines changed: 44 additions & 34 deletions

File tree

apps/workers/src/helpers/handleExit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { Cause, Exit } from 'effect';
1+
import { workerRuntime } from 'api/incentives/snapshot/v2/runtime';
2+
import { Cause, Effect, Exit } from 'effect';
23

34
export const handleExit = (exit: Exit.Exit<any, any>) => {
45
Exit.match(exit, {
56
onSuccess: (value) => value,
67
onFailure: (cause) => {
8+
workerRuntime.runSync(Effect.logError(cause));
79
if (Cause.isFailType(cause)) {
810
const enhancedError = new Error(cause.error._tag);
911
enhancedError.stack = Cause.pretty(cause);
@@ -14,7 +16,6 @@ export const handleExit = (exit: Exit.Exit<any, any>) => {
1416
const enhancedError = new Error(cause._tag ?? 'unhandled error');
1517
enhancedError.cause = cause._tag;
1618
enhancedError.stack = Cause.pretty(cause);
17-
console.error(cause);
1819
throw enhancedError;
1920
},
2021
});

apps/workers/src/queues/season-reward-claim/queue.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SeasonRewardWorkerInput } from 'api/incentives/season-reward/seasonRewardWorker';
2+
import { workerRuntime } from 'api/incentives/snapshot/v2/runtime';
23
import { Effect } from 'effect';
34
import { redisClient } from '../../redis';
45
import { createQueue } from '../createQueue';
@@ -13,16 +14,14 @@ export const seasonRewardClaimQueue = createQueue<
1314
redisClient,
1415
worker: seasonRewardClaimWorker,
1516
onError: async (job, error) => {
16-
Effect.runSync(
17-
Effect.gen(function* () {
18-
yield* Effect.logError({
19-
jobId: job?.id,
20-
jobName: job?.name,
21-
input: job?.data,
22-
error: error.message,
23-
stack: error.stack,
24-
failedReason: error.cause,
25-
});
17+
workerRuntime.runSync(
18+
Effect.logError({
19+
jobId: job?.id,
20+
jobName: job?.name,
21+
input: job?.data,
22+
error: error.message,
23+
stack: error.stack,
24+
failedReason: error.cause,
2625
}),
2726
);
2827
},

packages/api/src/incentives/season-reward/incentives-vester/incentivesVester.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ export class IncentivesVester extends Effect.Service<IncentivesVester>()(
337337
},
338338
) {
339339
static MainnetLive = IncentivesVester.Default.pipe(
340-
Layer.provide(
340+
Layer.provideMerge(
341341
Layer.mergeAll(
342342
Signer.VaultLive,
343343
Layer.effect(

packages/api/src/incentives/season-reward/seasonRewardWorker.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DisableTestClock } from '../../test-helpers/disableTestClock';
88
import { truncateTables } from '../../test-helpers/truncateTables';
99
import { AccountAddress, Amount } from '../account-balance/v2/schemas';
1010
import { DbService } from '../db/dbClient';
11+
import { SeasonService } from '../season/season';
1112
import { Signer } from '../transaction-intent/signer/signer';
1213
import { IncentivesVesterConfig } from './incentives-vester/config';
1314
import { IncentivesVester } from './incentives-vester/incentivesVester';
@@ -69,20 +70,26 @@ const testSetup = Effect.gen(function* () {
6970
return result;
7071
}).pipe(Effect.tapError(Effect.logError), Effect.provide(DbService.Default));
7172

73+
const IncentivesVesterTestLive = IncentivesVester.Default.pipe(
74+
Layer.provideMerge(
75+
Layer.mergeAll(
76+
Signer.VaultLive,
77+
Layer.effect(
78+
IncentivesVesterConfig,
79+
IncentivesVesterConfig.StokenetConfig,
80+
),
81+
),
82+
),
83+
);
84+
7285
layer(
7386
SeasonRewardWorker.DefaultWithoutDependencies.pipe(
7487
Layer.provide(
7588
Layer.mergeAll(
7689
SeasonRewardClaim.Default,
77-
IncentivesVester.Default.pipe(
78-
Layer.provide(
79-
Layer.effect(
80-
IncentivesVesterConfig,
81-
IncentivesVesterConfig.StokenetConfig,
82-
),
83-
),
84-
),
90+
IncentivesVesterTestLive,
8591
RedisLockTest,
92+
SeasonService.Default,
8693
),
8794
),
8895
),

packages/api/src/incentives/season-reward/seasonRewardWorker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Data, Duration, Effect, Layer, Option, Ref, Schema } from 'effect';
1+
import { Data, Duration, Effect, Option, Ref, Schema } from 'effect';
22
import {
33
AccountAddress,
44
Amount,
@@ -43,10 +43,6 @@ export class SeasonRewardWorker extends Effect.Service<SeasonRewardWorker>()(
4343
SeasonRewardClaim.Default,
4444
RedisLock.Default,
4545
SeasonService.Default,
46-
Layer.effect(
47-
IncentivesVesterConfig,
48-
IncentivesVesterConfig.MainnetConfig,
49-
),
5046
],
5147
effect: Effect.gen(function* () {
5248
const incentivesVester = yield* IncentivesVester;

packages/api/src/incentives/transaction-intent/signer/vault.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import {
2-
FetchHttpClient,
3-
FileSystem,
4-
HttpBody,
5-
HttpClient,
6-
} from '@effect/platform';
7-
import { NodeFileSystem } from '@effect/platform-node';
1+
import { FileSystem, HttpBody, HttpClient } from '@effect/platform';
2+
import { NodeFileSystem, NodeHttpClient } from '@effect/platform-node';
83
import {
94
Array as A,
105
Config,
116
Effect,
7+
Layer,
128
Option,
139
ParseResult,
1410
pipe,
@@ -114,8 +110,16 @@ const getVaultToken = (fs: FileSystem.FileSystem) =>
114110
return yield* Config.string('VAULT_TOKEN');
115111
});
116112

113+
const NodeHttpClientLive = NodeHttpClient.layerWithoutAgent.pipe(
114+
Layer.provide(
115+
NodeHttpClient.makeAgentLayer({
116+
rejectUnauthorized: false, // Allow self-signed certificates for internal cluster traffic
117+
}),
118+
),
119+
);
120+
117121
export class Vault extends Effect.Service<Vault>()('Vault', {
118-
dependencies: [FetchHttpClient.layer, NodeFileSystem.layer],
122+
dependencies: [NodeHttpClientLive, NodeFileSystem.layer],
119123
effect: Effect.gen(function* () {
120124
const keyName = yield* Config.string('VAULT_KEY_NAME').pipe(
121125
Config.withDefault('xrd-distribution'),
@@ -139,7 +143,9 @@ export class Vault extends Effect.Service<Vault>()('Vault', {
139143
},
140144
})
141145
.pipe(
146+
Effect.tapError(Effect.logError),
142147
Effect.flatMap((response) => response.json),
148+
Effect.tap((response) => Effect.log(response)),
143149
Effect.flatMap(Schema.decodeUnknown(PublicKeyResponseSchema)),
144150
);
145151
}).pipe(Effect.orDie);
@@ -164,6 +170,7 @@ export class Vault extends Effect.Service<Vault>()('Vault', {
164170
})
165171
.pipe(
166172
Effect.flatMap((response) => response.json),
173+
Effect.tap((response) => Effect.log(response)),
167174
Effect.flatMap(Schema.decodeUnknown(SignResponseSchema)),
168175
);
169176

0 commit comments

Comments
 (0)