How to schedule events on specific days/times

Discussion in 'Ruby' started by z0mbix, Aug 28, 2012.

  1. z0mbix

    z0mbix Guest

    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"
    ]
    }
    ]
    }
     
    z0mbix, Aug 28, 2012
    #1
    1. Advertisements

  2. Kernel#sleep, Thread#run.

    mfg, simon .... l
     
    Simon Krahnke, Sep 8, 2012
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.