Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a dynamically scheduled task?

I am trying to create an app that simulates opening a tab at a bar. I am running into one issue that I can't seem to figure out - it goes as follows:

  1. When someone opens a bar tab, dynamically create a scheduled task that executes code to close the tab after 24 hours.

  2. If the tab gets closed before the 24 hours, cancel the scheduled task.

  1. If the tab doesn't get closed after 24 hours, execute the code described in step 1 to initiate a payment on the card used to open the tab.

I was initially looking into Firebase Functions, and was thinking about using a setTimeout() callable function, but after doing some research I found that Firebase Function's cannot be invoked for longer than 9 minutes.

NOTE: I would like this to be dynamic. Meaning, having it account for a variable amount of users. There could be 100 or 1000 users on the platform, each of them needs the ability to have a unique scheduled task for them (sometimes multiple per user).

like image 616
devon66h Avatar asked Dec 19 '20 23:12

devon66h


People also ask

What is dynamic task scheduling?

In order to increase the effi- ciency of the system, a dynamic task scheduling algorithm is proposed, which balances the load among the nodes of the cluster. The technique is dynamic, nonpreemptive, adaptive, and it uses a mixed centralised and decentralised policies.

How do you dynamically schedule a spring batch job?

Spring Batch Scheduling: Spring Batch Jobs Scheduling You can configure Spring Batch Jobs in two different ways: Using the @EnableScheduling annotation. Creating a method annotated with @Scheduled and providing recurrence details with the job. Then add the job execution logic inside this method.

How do I create a scheduled task script?

Type the following command to create a daily task to run an app at 11:00am and press Enter:Syntax SCHTASKS /CREATE /SC DAILY /TN "FOLDERPATH\TASKNAME" /TR "C:\SOURCE\FOLDER\APP-OR-SCRIPT" /ST HH:MM Example SCHTASKS /CREATE /SC DAILY /TN "MyTasks\Notepad task" /TR "C:\Windows\System32\notepad.exe" /ST 11:00 Quick tip: ...


1 Answers

Please see the comments for the full solution.

There are multiple approaches to circumvent the 10 minutes rule (which is prevalent in the serverless code) but here's something that can help you. I suggest separating the task into three:

  1. A cloud function that close the tab when called.
  2. A schedule function that calls it (https://firebase.google.com/docs/functions/schedule-functions)
  3. A way to start and stop the schedule function.

I am not sure how firebase function work, but I worked with azure functions before and those can be controlled with command line (CLI) or with a sdk for your language of choice. To cancel using the command line, try something like this:

firebase functions:delete scheduledFunction

from How to cancel a scheduled firebase function?.

Now what's left is how to figure out how to start the function, and if it's possible to pass in a parameter to schedule it.

Good luck!

like image 62
yichiz Avatar answered Sep 20 '22 13:09

yichiz