git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Josh Heinrichs <joshiheinrichs@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 1/1] maintenance: fix launchctl calendar intervals
Date: Mon, 21 Apr 2025 10:42:06 -0700	[thread overview]
Message-ID: <xmqq1ptl76oh.fsf@gitster.g> (raw)
In-Reply-To: <20250421054633.231069-2-joshiheinrichs@gmail.com> (Josh Heinrichs's message of "Sun, 20 Apr 2025 23:46:33 -0600")

Josh Heinrichs <joshiheinrichs@gmail.com> writes:

> When using the launchctl scheduler, the weekly job runs daily, and the
> daily job runs on the first six days of each month. This appears to be
> due to specifying "Day" in the calendar intervals, which according to
> launchd.plist(5) is for specifying days of the month rather than days of
> the week. The behaviour of running a job on the 0th day is undocumented,
> but in my testing appears to be the same as not specifying "Day" in the
> calendar interval, in which case the job will run daily.
>
> Use "Weekday" in the calendar intervals, which is the correct way to
> schedule jobs to run on specific days of the week.
>
> Signed-off-by: Josh Heinrichs <joshiheinrichs@gmail.com>
> ---

With a bit wider context, the patch looks like so.  As I do not use
macOS or launchctl myself, my guess may be way off but please bear
with me.

>  builtin/gc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git i/builtin/gc.c w/builtin/gc.c
> index 99431fd467..cc13baa3bd 100644
> --- i/builtin/gc.c
> +++ w/builtin/gc.c
> @@ -2072,24 +2072,24 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
>  		for (i = 1; i <= 23; i++)
>  			strbuf_addf(&plist, repeat, i, minute);
>  		break;
>  
>  	case SCHEDULE_DAILY:
>  		repeat = "<dict>\n"
> -			 "<key>Day</key><integer>%d</integer>\n"
> +			 "<key>Weekday</key><integer>%d</integer>\n"
>  			 "<key>Hour</key><integer>0</integer>\n"
>  			 "<key>Minute</key><integer>%d</integer>\n"
>  			 "</dict>\n";
>  		for (i = 1; i <= 6; i++)
>  			strbuf_addf(&plist, repeat, i, minute);
>  		break;

So we used to say that "we want the task to run on days 1 thru 6 (6
days in total) of a month at certain minute of the day past
midnight", which clearly not how people think of "daily" task.

Updated one specifies the task to run on day 1 (Monday) thru 6
(Saturday) of a week.  The manual page seems to say that day 0 and
day 7 of a week are both Sundays.

  https://www.manpagez.com/man/5/launchd.plist/ look for
  StartCalendarInterval to read about Day and Weekday.

Curious that day 7/0 are ignored.  Other schedulers are somewhat
inconsistent but generally agree, so I won't worry about changing it
in this patch.  schtasks_schedule_task() excludes Sundays, and
crontab_update_schedule() says that it wants to run daily scheduled
tasks on day 1-6.  systemd_timer_write_timer_file() however seems to
say that it wants to run things on Tue..Sun (excluding Mondays),
which may want to be corrected, I dunno.


>  	case SCHEDULE_WEEKLY:
>  		strbuf_addf(&plist,
>  			    "<dict>\n"
> -			    "<key>Day</key><integer>0</integer>\n"
> +			    "<key>Weekday</key><integer>0</integer>\n"
>  			    "<key>Hour</key><integer>0</integer>\n"
>  			    "<key>Minute</key><integer>%d</integer>\n"
>  			    "</dict>\n",
>  			    minute);
>  		break;

This one used to say "run on 0th day of the month", but now it says
"run on 0th day of the week", which is on Sundays.  Makes sense.

Will queue.  Thanks.

  reply	other threads:[~2025-04-21 17:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-21  5:46 [PATCH 0/1] maintenance: fix launchctl calendar intervals Josh Heinrichs
2025-04-21  5:46 ` [PATCH 1/1] " Josh Heinrichs
2025-04-21 17:42   ` Junio C Hamano [this message]
2025-04-23 19:25     ` Derrick Stolee
2025-04-23 20:31       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq1ptl76oh.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=joshiheinrichs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).