# How to extend and implement TimerProvider?

**URL:** <https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357>\
**Category:** Getting advice\
**Created:** [November 15, 2023, 9:59am UTC](https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357 "2023-11-15T09:59:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gautammarla](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@gautammarla](https://forum.keycloak.org/u/gautammarla)\
**Post date:** [November 15, 2023, 9:59am UTC](https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357/1 "2023-11-15T09:59:32Z")

</div>

Hi community,

I have been trying to run a task (let’s say get the users) scheduled daily inside keycloak. I have gone through the TimerProvider interface and implemented it into my custom class (let’s say GetUserProvider).  
This custom implementation has to start with keycloak startup. Any ideas on how to go on about this.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [November 15, 2023, 3:58pm UTC](https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357/2 "2023-11-15T15:58:36Z")

</div>

You can just set it up in the `postInit` method of any other Provider. Here’s an example: [https://github.com/xgp/keycloak-experiments/blob/main/single-node/src/main/java/com/github/xgp/keycloak/backup/h2/H2BackupProviderFactory.java#L44-L56](https://github.com/xgp/keycloak-experiments/blob/main/single-node/src/main/java/com/github/xgp/keycloak/backup/h2/H2BackupProviderFactory.java#L44-L56)

---

<div class="post-metadata">

**Author:** ![gautammarla](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@gautammarla](https://forum.keycloak.org/u/gautammarla)\
**Post date:** [November 16, 2023, 5:24am UTC](https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357/3 "2023-11-16T05:24:24Z")

</div>

Thanks @xgp , will check that today. If you don’t mind, I have few more questions. Do I have to use another provider? Can it not be used as a implementation on its own?  
For ex: Like in the example, the DatabaseBackupProviderFactory is called on startup, which then calls TimerProvider. Can I call TimerProvider in a similar way and not through another provider?

Edit: Yes, your solution is working fine, thanks. I am able to get the users based on a specific period. Now, I just want to know whether it will work standalone or not.

---

<div class="post-metadata">

**Author:** ![xgp](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/xgp/32/2589_2.png) [@xgp](https://forum.keycloak.org/u/xgp)\
**Post date:** [November 16, 2023, 10:29am UTC](https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357/4 "2023-11-16T10:29:27Z")

</div>

I don’t know another way to do it other than to load the `TimerProvider` from a session and schedule your tasks.

---

<div class="post-metadata">

**Author:** ![gautammarla](https://avatars.discourse-cdn.com/v4/letter/g/50afbb/32.png) [@gautammarla](https://forum.keycloak.org/u/gautammarla)\
**Post date:** [November 16, 2023, 10:52am UTC](https://forum.keycloak.org/t/how-to-extend-and-implement-timerprovider/23357/5 "2023-11-16T10:52:03Z")

</div>

Oh! Ok. No worries. Thanks for the help though. 🙂
