How to schedule events on specific days/times

Z

z0mbix

Hi, I am currently writing a proof of concept music player in Ruby and havegot so far, but I need a bit of advice for how to proceed. The music player plays music from a simple json playlist file in a loop. This is simple and already implemented, but what I need to do is play different playlists oneach day of the week, and only during the specified times, so I need some way to schedule events to switch playlists at the specified days/times. I've not had to do anything like this before and not sure what the best approach is. Should there be a separate thread that wakes up every minute to check if a switch is required, or is there a better way to do this?

Here's a sample json schedule file:

{
"playlist-name": "Day Part Schedule",
"description": "This schedule file only plays files during the specified duration",
"monday": [
{
"playlist": "monday.json",
"times": [
"0900-1700",
"1800-1900"
]
}
],
"tuesday": [
{
"playlist": "tuesday.json"
}
],
"wednesday": [
{
"playlist": "wednesday.json",
"times": [
"0900-1730"
]
}
],
"thursday": [
{
"playlist": "thursday.json",
"times": [
"0900-1730"
]
}
],
"friday": [
{
"playlist": "friday.json",
"times": [
"0900-1730"
]
}
],
"saturday": [
{
"playlist": "saturday.json",
"times": [
"0900-1900"
]
}
],
"sunday": [
{
"playlist": "sunday.json",
"times": [
"1000-1630"
]
}
]
}
 
S

Simon Krahnke

* Robert Klemme said:
There might be solutions for scheduling around. Did you look in RAA or
Gem repository? If you want to do it yourself, you can make that more
intelligent than polling. Basically you need to calculate the next even
(i.e. music on) and sleep until that point in time is reached. Then
start playing. If you want to be able to modify the schedule online
(i.e. while the application is running) things get a bit more
complicated because you may have to wake up earlier than intended.

Kernel#sleep, Thread#run.

mfg, simon .... l
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top