-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a144f6a
commit 913c80b
Showing
4 changed files
with
36 additions
and
6 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
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
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 { userRepo } from './db' | ||
import { createSdkService } from './sdk' | ||
|
||
export async function startUsersPoller() { | ||
const sdk = (await createSdkService()).getSdk() | ||
|
||
// Periodic task to fetch user data and update names | ||
setInterval(async () => { | ||
try { | ||
const users = userRepo.all() | ||
|
||
for (const user of users) { | ||
const { data: userResponse } = await sdk.users.getUser({ id: user.id }) | ||
if (!userResponse) { | ||
throw new Error(`Error fetching user ${user.id} from sdk`) | ||
} | ||
if (userResponse.name !== user.name) { | ||
userRepo.upsert({ | ||
...user, | ||
name: userResponse.name | ||
}) | ||
console.log(`Updated user ${user.id}'s name`) | ||
} | ||
} | ||
} catch (error) { | ||
console.error('Failed to update user names:', error) | ||
} | ||
}, 300000) // Runs every 5 min | ||
} |