Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined pin job #672

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/classes/modules_did_did_processor.DIDProcessor.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
| `didService` | [`DIDService`](modules_did_did_service.DIDService.md) |
| `logger` | [`Logger`](modules_logger_logger_service.Logger.md) |
| `configService` | `ConfigService`<`Record`<`string`, `unknown`\>, ``false``\> |
| `pinQueue` | `Queue`<`any`\> |
| `pinQueue` | `Queue`<[`PinClaimData`](../modules/modules_ipfs_ipfs_types.md#pinclaimdata)\> |

## Methods

Expand Down
2 changes: 1 addition & 1 deletion docs/api/classes/modules_ipfs_ipfs_service.IPFSService.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
| :------ | :------ |
| `didStoreCluster` | `DidStore` |
| `didStoreInfura` | `DidStore` |
| `pinsQueue` | `Queue`<`string`\> |
| `pinsQueue` | `Queue`<[`PinClaimData`](../modules/modules_ipfs_ipfs_types.md#pinclaimdata)\> |
| `logger` | [`Logger`](modules_logger_logger_service.Logger.md) |

## Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ It was implemented for EW migration from Infura to EW hosted IPFS

| Name | Type |
| :------ | :------ |
| `job` | `Job`<`any`\> |
| `job` | `Job`<[`PinClaimData`](../modules/modules_ipfs_ipfs_types.md#pinclaimdata)\> |

#### Returns

Expand Down
14 changes: 14 additions & 0 deletions docs/api/modules/modules_ipfs_ipfs_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [IpfsClusterConfig](modules_ipfs_ipfs_types.md#ipfsclusterconfig)
- [IpfsInfuraConfig](modules_ipfs_ipfs_types.md#ipfsinfuraconfig)
- [PinClaimData](modules_ipfs_ipfs_types.md#pinclaimdata)

### Variables

Expand Down Expand Up @@ -38,6 +39,19 @@ ___
| `protocol?` | `string` |
| `url?` | `string` |

___

### PinClaimData

Ƭ **PinClaimData**: `Object`

#### Type declaration

| Name | Type |
| :------ | :------ |
| `cid` | `string` |
| `claim?` | `string` |

## Variables

### IPFSClusterConfigToken
Expand Down
8 changes: 6 additions & 2 deletions src/modules/did/did.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
} from '@nestjs/bull';
import { ConfigService } from '@nestjs/config';
import { Job, Queue } from 'bull';
import { PIN_CLAIM_JOB_NAME, PIN_CLAIM_QUEUE_NAME } from '../ipfs/ipfs.types';
import {
PinClaimData,
PIN_CLAIM_JOB_NAME,
PIN_CLAIM_QUEUE_NAME,
} from '../ipfs/ipfs.types';
import { Logger } from '../logger/logger.service';
import { DIDDocumentEntity } from './did.entity';
import { DIDService } from './did.service';
Expand All @@ -27,7 +31,7 @@ export class DIDProcessor {
private readonly logger: Logger,
private readonly configService: ConfigService,
@InjectQueue(PIN_CLAIM_QUEUE_NAME)
private pinQueue: Queue
private pinQueue: Queue<PinClaimData>
) {
this.logger.setContext(DIDProcessor.name);
}
Expand Down
13 changes: 7 additions & 6 deletions src/modules/ipfs/ipfs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CID } from 'multiformats/cid';
import { InjectQueue } from '@nestjs/bull';
import { Queue } from 'bull';
import { PIN_CLAIM_QUEUE_NAME, PIN_CLAIM_JOB_NAME } from './ipfs.types';
import {
PIN_CLAIM_QUEUE_NAME,
PIN_CLAIM_JOB_NAME,
PinClaimData,
} from './ipfs.types';
import { Logger } from '../logger/logger.service';
import { inspect } from 'util';

Expand All @@ -14,7 +18,7 @@ export class IPFSService {
private didStoreCluster: DidStoreCluster,
private didStoreInfura: DidStoreGateway,
@InjectQueue(PIN_CLAIM_QUEUE_NAME)
private readonly pinsQueue: Queue<string>,
private readonly pinsQueue: Queue<PinClaimData>,
private readonly logger: Logger
) {
this.logger.setContext(IPFSService.name);
Expand Down Expand Up @@ -64,10 +68,7 @@ export class IPFSService {
}

try {
await this.pinsQueue.add(
PIN_CLAIM_JOB_NAME,
JSON.stringify({ cid, claim })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you recall why stringify was used initially? From what I can from the NestJs Bull queue docs it seems fine to use a non-stringified object, but it's not clear to me why we didn't use the object directly in the first place 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't really remember reason

);
await this.pinsQueue.add(PIN_CLAIM_JOB_NAME, { cid, claim });
} catch (e) {
this.logger.debug(`Error to add pin job for cid ${cid}: ${e}`);
const jobsCounts = await this.pinsQueue.getJobCounts();
Expand Down
5 changes: 5 additions & 0 deletions src/modules/ipfs/ipfs.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ export const IPFSClusterConfigToken = Symbol.for('IPFSClusterConfigToken');

export const PIN_CLAIM_JOB_NAME = 'pinning';
export const PIN_CLAIM_QUEUE_NAME = 'pinClaimQueue';

export type PinClaimData = {
cid: string;
claim?: string;
};
13 changes: 8 additions & 5 deletions src/modules/ipfs/pin.processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { Job } from 'bull';
import { DidStore as DidStoreInfura } from 'didStoreInfura';
import { DidStore as DidStoreCluster } from 'didStoreCluster';
import { Logger } from '../logger/logger.service';
import { PIN_CLAIM_JOB_NAME, PIN_CLAIM_QUEUE_NAME } from './ipfs.types';
import {
PinClaimData,
PIN_CLAIM_JOB_NAME,
PIN_CLAIM_QUEUE_NAME,
} from './ipfs.types';

@Processor(PIN_CLAIM_QUEUE_NAME)
export class PinProcessor {
Expand Down Expand Up @@ -49,10 +53,9 @@ export class PinProcessor {
* It was implemented for EW migration from Infura to EW hosted IPFS
*/
@Process(PIN_CLAIM_JOB_NAME)
async pin(job: Job) {
const data = JSON.parse(job.data);
const cid = data.cid;
let claim = data.claim;
async pin(job: Job<PinClaimData>) {
const cid = job.data.cid;
let claim = job.data.claim;
try {
await this.didStoreCluster.get(cid);
} catch (_) {
Expand Down
Loading