Git Product home page Git Product logo

Comments (4)

grayaii avatar grayaii commented on August 10, 2024

I second this. I can't seem to find a way to do something like this:
0 16 5 * *
β€œAt 16:00 on the 5th of every month.”
Or something similar.
Thanks

from schedule.

dbader avatar dbader commented on August 10, 2024

I can definitely understand the interest in a feature like this. What I'm worried about is that schedule isn't a good fit for this kind of scheduling problem.

For example, let's say we want to schedule a job function to run on August 27, 2016 in some kind of web app that uses schedule. What's going to happen if someone deploys a new version of the app around the instant the job's supposed to run? How are we going to keep track of whether the job ran or not when the app was restarted? How are we going to make sure the job is only going to run once, even if the app is restarted on the day the job's supposed to run?

If we wanted to solve these problems we'd have to talk about a persistence mechanism. And I believe that we'd basically end up on a path to re-invent cron 😐

In its current form schedule is a job scheduler well-suited for periodic tasks, preferably ones with relatively small intervals between executions.

from schedule.

grayaii avatar grayaii commented on August 10, 2024

Thanks for the quick reply!!!

I thought that schedule only kicks jobs if it "crosses" the scheduled time, and therefore doesn't need any persistent data.
So in the above example, if a job is scheduled to run on Aug 27 at midnight, then, if schedule is stopped at 11:59 and started at 12:01, it wouldn't start the job because it never "crossed" the time the job was supposed to run.

And likewise, if schedule was restarted continuously on Aug 27, then it wouldn't kick it off either, since it wasn't running "across" the time.

In other words, it only kicks off jobs if schedule was running a bit before and a bit after the time of scheduled job.

I'm not the author, so I wouldn't know :) I'm only guessing.

I'm working on a Proof of Concept where I'm converting all our cron jobs to use schedule, and here it is, in all its glory. This code will indeed be restarted every time I do a deploy, so I'm hoping that the tasks that run at "specific days" or "month" intervals don't get executed ever time I restart schedule:

(of course, I replaced "job" with a thread call, and i have global dictionary which ensures jobs that take 5 minutes to run but are on a 1 minute cron do not run in parallel)

If specific day, or month intervals is not a good match for schedule, let me know I'll look for an alternative, but I love the simplicity of this package!

  # Load up the crons. Use http://crontab.guru/ to convert existing crons:
  schedule.every(1).minutes.do(job)
  schedule.every(1).minutes.do(job)
  schedule.every(1).minutes.do(job)
  schedule.every().day.at("11:00").do(job)
  schedule.every(1).minutes.do(job)
  schedule.every().hour.at(":59").do(job)


  for i in range(6):
      schedule.every().friday.at("{}:7".format(i * 4)).do(job)
      schedule.every().saturday.at("{}:7".format(i * 4)).do(job)
      schedule.every().sunday.at("{}:7".format(i * 4)).do(job)

  schedule.every(3).hour.at(":7").do(job)
  schedule.every(15).minutes.do(job)
  schedule.every().day.at("15:00").do(job)

  # I'll create a ticket on my backlog, since I can't figure out how to do this with 'schedule':
  #schedule.every().month.at("16:00").do(job)
  #0 16 5 * * 

  for i in range(24):
      schedule.every().monday.at("{}:17".format(i)).do(job)
      schedule.every().tuesday.at("{}:17".format(i)).do(job)
      schedule.every().wednesday.at("{}:17".format(i)).do(job)

  schedule.every().day.at("13:33").do(job)
  schedule.every(4).hour.at(":40").do(job)
  schedule.every(5).minutes.do(job)
  schedule.every(15).minutes.do(job)
  schedule.every().hour.at(":33")(job)
  schedule.every().hour.at(":40").do(job)
  schedule.every().day.at("00:00").do(job)
  schedule.every().day.at("9:05").do(job)
  schedule.every().day.at("7:08").do(job)
  schedule.every().day.at("9:13").do(job)
  schedule.every().day.at("9:00").do(job)
  schedule.every().hour.at("0:47").do(job)
  schedule.every(2).hour.at(":20").do(job)
  schedule.every().day.at("7:25").do(job)
  schedule.every().saturday.at("8:35").do(job)
  schedule.every().day.at("4:00").do(job)
  schedule.every().day.at("5:00").do(job)
  schedule.every().day.at("9:00").do(job)
  schedule.every(15).minutes.do(job)
  schedule.every().day.at("13:15").do(job)

  # This one is set to run at odd times on the hour:
  schedule.every().hour.at(":16").do(job)
  schedule.every().hour.at(":46").do(job)

  schedule.every().day.at("8:30").do(job)
  schedule.every().day.at("14:00").do(job)
  schedule.every(15).minutes.do(job)
  schedule.every().day.at("6:30").do(job)
  schedule.every().hour.at(":11").do(job)
  schedule.every().day.at("12:00").do(job)
  schedule.every().day.at("12:05").do(job)
  schedule.every().sunday.at("3:00").do(job)
  schedule.every().friday.at("5:00").do(job)
  schedule.every().day.at("6:30").do(job)
  schedule.every().day.at("6:00").do(job)

from schedule.

SijmenHuizenga avatar SijmenHuizenga commented on August 10, 2024

it only kicks off jobs if schedule was running a bit before and a bit after the time of scheduled job

This is 100% correct.

If an 1-minute job execution doesn't happen, it's probably no big deal because the job will run 1 minute after the program starts again. But if a job is set to run each month, and the job is skipped, the job only runs again the next month. The impact of a missed monthly job is often much bigger. So I agree with @dbader that schedule is better suited for short periodic tasks. In this mindset, I don't think scheduling a job on a specific date suits this library.

from schedule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.