task3check.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { forEachAsync, getAxiosClient } from '../../utils'
  2. import { DBClient } from '../../singletons'
  3. import { InitiaClient } from '../../InitiaClient'
  4. async function startCheck(concurrency) {
  5. const accountsRaw = await DBClient.instance.randomTask2.findMany({
  6. where: {
  7. finish: 1,
  8. },
  9. take: 40000,
  10. })
  11. await forEachAsync(accountsRaw, concurrency, async (account, index) => {
  12. console.log(
  13. `${index}/${accountsRaw.length}: processing ${account.address},account id: ${account.id}`,
  14. )
  15. try {
  16. const axios = getAxiosClient(true)
  17. const res = await axios.get(
  18. `https://xp-api.initiation-1.initia.xyz/xp/weekly/${account.address}/3`,
  19. )
  20. console.log(res.data)
  21. const finishedTasks = res.data.finishedTasks
  22. if (finishedTasks.length === 6) {
  23. await DBClient.instance.randomTask2.update({
  24. where: { id: account.id },
  25. data: { finish: 2 },
  26. })
  27. }
  28. } catch (e) {
  29. console.log(e.message)
  30. return
  31. }
  32. })
  33. }
  34. startCheck(50)