-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: delete token traits via worker (#1333)
delete token traits via worker
- Loading branch information
Showing
4 changed files
with
53 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import Queue from 'bull' | ||
import connection from '../connection' | ||
import { JobData } from '../jobs/delete-traits' | ||
|
||
export default async (job: Queue.Job<JobData>, done: Queue.DoneCallback) => { | ||
if (!connection.isInitialized) { | ||
await connection.initialize().catch((err) => { | ||
throw err | ||
}) | ||
} | ||
|
||
const em = connection.manager | ||
|
||
await em.query( | ||
` | ||
DELETE FROM trait_token WHERE token_id = $1 | ||
`, | ||
[job.data.id] | ||
) | ||
|
||
await em.query( | ||
` | ||
DELETE FROM token_rarity WHERE token_id = $1 | ||
`, | ||
[job.data.id] | ||
) | ||
|
||
done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Queue from 'bull' | ||
import { redisConfig } from './common' | ||
|
||
export type JobData = { id: string } | ||
|
||
export const deleteTraitsQueue = new Queue<JobData>('deleteTraits', { | ||
defaultJobOptions: { removeOnComplete: true }, | ||
redis: redisConfig, | ||
settings: { | ||
maxStalledCount: 1, | ||
}, | ||
}) | ||
|
||
export const deleteTokenTraits = async (id: string) => { | ||
deleteTraitsQueue.add({ id }).catch(() => { | ||
// eslint-disable-next-line no-console | ||
console.log('Closing connection as Redis is not available') | ||
deleteTraitsQueue.close(true) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters