Giter VIP home page Giter VIP logo

Comments (13)

aparmar avatar aparmar commented on June 15, 2024 7

If you dont want to give the full date, you could try something like this:

every 1.month, :at => "start of the month at 9am"
This will produce the intended "0 9 1 * *". It will also keep your code a little cleaner :)

Hope that helps.

-AP

from whenever.

javan avatar javan commented on June 15, 2024 2

Ah, I see the problem (other than me not having good docs in this area). When you use :at with 1.month, the day, hour, and minute get parsed from the time. So when you just use a time like 9am, it assumes the day you mean is today.

One way to correct this is give it a full date. I admit that this looks ugly, but it should work: every 1.month, :at => "January 1st 9am"

It will ignore the "January", but it's necessary for a successful parse (Whenever uses the Chronic gem for parsing dates and times).

Hope that helps.

the

from whenever.

javan avatar javan commented on June 15, 2024

are you showing all of the cron output there? your first example has a 9 in the hour place and 18 in the day.

# .---------------- minute (0 - 59) 
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
# |  |  |  |  |
# *  *  *  *  *  command to be executed

from whenever.

tsommer avatar tsommer commented on June 15, 2024

no, the complete output was:

0 9 18 * * command

from whenever.

javan avatar javan commented on June 15, 2024

can you paste your schedule.rb file? something seems off.

from whenever.

tsommer avatar tsommer commented on June 15, 2024
every 1.month, :at => "9 AM" do
  command "..."
end

from whenever.

tsommer avatar tsommer commented on June 15, 2024

Thanks Javan.

As you said, thats not good looking but it works!

from whenever.

aparmar avatar aparmar commented on June 15, 2024

tsommer...the above solution I posted should work. I'm not sure if you looked at it.

from whenever.

javan avatar javan commented on June 15, 2024

"start of the month at 9am" -- that rules! thanks.

from whenever.

eeng avatar eeng commented on June 15, 2024

I need to express this cron job "0 0 27-31 * *". Is it posible with the current syntax?

Maybe would be better to provide another method in the DSL to pass in cron jobs in the normal cron syntax, something like:

cron "0 0 27-31 * *" do
   # ...
end

from whenever.

javan avatar javan commented on June 15, 2024

I agree that a raw syntax option would be nice (patches welcome!). In the meantime you can do this with a dash of Ruby.

every 1.month, :at => (27..31).to_a.map { |d| "12am January #{d}" } do
  command "..."
end

from whenever.

eeng avatar eeng commented on June 15, 2024

Javan thanks for the fast response.
Currently I'm using the following patch. Maybe the regexp could need some improvements but it works for me now.

class Whenever::Output::Cron
  CRON_EXP = /[^\s]+\s[^\s+]\s[^\s]+\s[^\s]+\s[^\s]+/
  
  def time_in_cron_syntax
    case @time
      when CRON_EXP then @time
      when Symbol then parse_symbol
      when String then parse_as_string
      else parse_time
    end
  end
end

Then I can do:

every '0 0 27-31 * *' do
  ...
end

from whenever.

jinyi0313 avatar jinyi0313 commented on June 15, 2024

how i create every 2 month, end of day(31th), 11 59pm do cron?
every 2.month, at 59 11 L * 0

from whenever.

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.