How to schedule events on specific days/times

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

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

  2. * Robert Klemme <> (2012-08-29) schrieb:

    >On 28.08.2012 22:48, wrote:
    >> This is simple and already implemented, but what I need to do is play
    >> different playlists on each 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?

    >
    >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
     
    Simon Krahnke, Sep 8, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Stockwell
    Replies:
    2
    Views:
    703
    Anna Martelli Ravenscroft
    Sep 20, 2004
  2. Gerrit
    Replies:
    0
    Views:
    386
    Gerrit
    Sep 20, 2004
  3. Terry Reedy
    Replies:
    0
    Views:
    430
    Terry Reedy
    Sep 20, 2004
  4. Replies:
    5
    Views:
    468
    Bo Yang
    Nov 2, 2006
  5. kirke

    list of days between two days

    kirke, Oct 19, 2006, in forum: Javascript
    Replies:
    7
    Views:
    138
    Julian Turner
    Oct 20, 2006
Loading...

Share This Page