Skip to content

Commit

Permalink
feat: Pinner for processed artworks
Browse files Browse the repository at this point in the history
  • Loading branch information
billybonks committed May 28, 2022
1 parent f5fbb67 commit 82cc0b3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/processors/default/ipfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Axios, AxiosResponse, AxiosError } from 'axios';
import _ from 'lodash';

import { Table } from '../../db/db';
import { unpinnedTrackContent } from '../../triggers/ipfs';
import { unpinnedTrackContent, unpinnedProcessedArtworks } from '../../triggers/ipfs';
import { Clients, Processor } from '../../types/processor';
import { ProcessedTrack } from '../../types/track';
import { RollOutput, rollPromises } from '../../utils/rollingPromises';
Expand Down Expand Up @@ -86,3 +86,11 @@ export const ipfsArtworkPinner: Processor = ({
processorFunction: processorFunction,
initialCursor: undefined
});


export const ipfsProcessedArtworksPinner: Processor = ({
name,
trigger: unpinnedProcessedArtworks(10), // 10 is the max on many pinning apis
processorFunction: processorFunction,
initialCursor: undefined
});
22 changes: 22 additions & 0 deletions src/triggers/ipfs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Table } from '../db/db';
import { Clients } from '../types/processor';
import { ProcessedTrack } from '../types/track';
import { Artworks } from '../types/track';
import { Trigger } from '../types/trigger';

export const unpinnedTrackContent: (cidField: string, limit?: number) => Trigger<undefined> =
Expand All @@ -22,3 +23,24 @@ export const unpinnedTrackContent: (cidField: string, limit?: number) => Trigger
});
return cids;
};

export const unpinnedProcessedArtworks = function (limit?: number): Trigger<undefined> {
return async function (clients: Clients) {
const query = `select t.* from "${Table.processedArtworks}" as t
LEFT OUTER JOIN "${Table.ipfsPins}" as p
ON t.cid = p.id
WHERE (t.cid IS NOT NULL)
AND (p.id is NULL)
LIMIT ${limit}`
const artworks = (await clients.db.rawSQL(
query
)).rows.slice(0, parseInt(process.env.QUERY_TRIGGER_BATCH_SIZE!));
const cids = artworks.map((artwork: Artworks) => {
if (!artwork.cid) {
throw new Error('Unexpected null ipfs cid')
}
return artwork.cid;
});
return cids;
};
}

0 comments on commit 82cc0b3

Please sign in to comment.