Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Your schema should store:
  • last run time epoch milliseconds
  • frequency to run at, in seconds
  • other stuff like ids, foreign references, job names, etc.

On startup, partition all your jobs by frequency (60 might mean something run every 60s; 3600 would be hourly; etc) and then sort by last run time, oldest to newest. Map each set to figure out each job's next run time.

Look at the 0th item in each set to see which has the next run time. Sleep between now and then.

When you wake up, execute your top job. Update its last run time. Add it back to the queue of jobs. Re-partition/sort/map the entire queue; calculate your next run time; rinse and repeat.

There's plenty of opportunity here to improve this, by adding state tracking; offloading the sorting/mapping to your database; periodically refreshing the list of available jobs; etc. but for a naive implementation, this works.


In reply to Re: Scheduling type daemon by Anonymous Monk
in thread Scheduling type daemon by Laurielounge

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-26 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found