Can i run a background task timing based on relative data or database variable?

Options
Just in case there is a better way to do this all together I'll spell out what I'm trying to do and then ask my specific question. 

I have a table of users, each has an allotment of 3 posts per day, saved as post_count in the user table, when they post it gets incremented down, when it is zero, they can't post again until tomorrow. 

I want, at each user's local time at midnight, to reset the count to 3. Is this possible? if so, how?

Otherwise, how might I accomplish this?

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Hey  definitely possible. I imagine there's at least a few different approaches here. 

    One idea - first, you'd need to store each user's timezone. You can Query All Records from user (using the stream return type) and For Each Loop through those records. Then have a Conditional... WHERE now (format_timestamp using the user's timezone, so var: item.timezone) == 12am (or however you format the timestamp)... THEN reset the count on the user...

    You might want to make the Conditional WHERE statement be more inclusive of a few minutes from midnight to just past it, in order to give the background task full time to run. 

    The task would probably run every 30 minutes (I think) to cover the wide-range of timezones.