1
4 Comments

[DEV_HELP] I’m building a feature that involves scheduled tasks.

Hi Everyone!

I’m building a feature that involves scheduled tasks. I'd love to hear your ideas and opinions on how to better implement it.

1. Scenario:

  • 1.1. Users can create a task for a specific date (i.e. scheduled date).
  • 1.2. The task will be flagged open only when that scheduled date comes. Until then, it will be marked closed.
  • 1.3. Once the scheduled date is over, this task will be flagged closed again.

2. Prerequisites:

I’m using the following technologies:

  • React
  • Firebase Realtime Database
  • Firebase Cloud Functions
  • Google Cloud Scheduler
  • Google Cloud Pub/Sub

3. Initial Plan:

  • 3.1. I will create a separate database for the Task Queue. Any new tasks scheduled by users will also be stored here. Task and User data are stored on different databases respectively.

  • 3.2. I will create a function that is scheduled to run everyday at 00:00:00. On the event that this function fires, it will do 2 things:

  • 3.2.1. It will check today’s date and retrieve the collection from the Task Queue database with that same date. The function will then go over each task and mark it open for that day.

  • 3.2.2. It will also retrieve yesterday’s task queue, go over those tasks and mark them closed.

4. Questions:

  • 4.1. How should I structure the task queue DB more efficiently (in Firebase RDB)?
  • 4.2. Ideally, how should I setup the scheduler function (i.e. should I run it once a day)?
  • 4.3. How should I handle Users from different timezones?

I know there's a much more effective and efficient way of setting this up so I'm looking forward to everyone's feedback. Any links/resources for further reading will be awesome. Thank you in advance!

on February 9, 2020
  1. 1

    4.1 - I wouldn't overthink things here. I'm not familiar with Firebase RDB, but I'd simply save each task and then index the DB on dates. You'd probably have to hit millions of records to start running into performance issues, and at that point you can always run cleanup scripts to archive old data.

    4.2 - It depends on the use case. If the tasks are only by day then running it once per day might be fine. If I can get more granular (this day between 1-2) you'll need to run it more often.

    4.3 - Save the users time zone and convert any times to UTC before saving to the DB. You can then properly format it for the user when you return it to them.

    1. 1

      Gotcha. Thanks for the feedback! Totally agree on not overthinking things. It's much more important to just get it out there asap.

  2. 1

    4.3. You can convert user-input timezones into UTC timezone before storing it in your DB
    Ref: https://stackoverflow.com/questions/42842134/handling-multiple-timezones-in-application

    1. 1

      Noted. Thank you for the insight!