Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled scripts stop being scheduled #1509

Open
kpfromer opened this issue Aug 18, 2024 · 4 comments
Open

Scheduled scripts stop being scheduled #1509

kpfromer opened this issue Aug 18, 2024 · 4 comments

Comments

@kpfromer
Copy link

Hey, thank you so much for making this project. It's wonderful to have an API to script so easily.

However, I've run into some issues with scheduled scripts. My scheduled scripts stop being scheduled after a while. I notice when I pull up the command palette, they don't show the next scheduled time. The way I fix this is by restarting ScriptKit.

But this is super annoying to deal with, and ideally ScriptKit can figure out that it should reschedule these scripts.

Below is an example scheduled script that stops working after scriptkit has been launched for a few hours.

// Name: Kenv Sync
// Description: Syncs main kenv directory with github on a schedule (every 10 minutes)
// Schedule: 0 */10 * * * *

import "@johnlindquist/kit";
import { invariantAndExit } from "../lib/script-invariant";

await hide();

const mainKenvDir = kenvPath();

const deviceName = await env("DEVICE_NAME");

const commitMessage = `${formatDate(new Date(), "yyyy-MM-dd kk:mm:ss")} ${deviceName}`;

const cliOptions = {
  cwd: mainKenvDir,
  shell: "/bin/zsh",
  all: true,
  reject: false,
};

const gitStatusResult = await execa("git status --porcelain", cliOptions);
invariantAndExit(gitStatusResult.exitCode === 0, "Git status failed");

// We need to check if there are any changes to commit and if there are, we need to commit them
if (gitStatusResult.stdout.trim() !== "") {
  const commitResult = await execa(
    `git add -A && git commit -m '${commitMessage}'`,
    cliOptions,
  );
  invariantAndExit(commitResult.exitCode === 0, "Git commit failed");
}

const pullResult = await execa("git pull --rebase", cliOptions);
invariantAndExit(pullResult.exitCode === 0, "Git pull failed");

const gitUnpushedResult = await execa("git log origin/main..HEAD", cliOptions);
invariantAndExit(gitUnpushedResult.exitCode === 0, "Git unpushed check failed");

// If there are no changes to commit, we can exit the script
if (gitUnpushedResult.stdout.trim() === "") {
  exit(0);
}

const pushResult = await execa("git push", cliOptions);
invariantAndExit(pushResult.exitCode === 0, "Git push failed");

notify("Synced kenv");
@johnlindquist
Copy link
Owner

Thanks for the kind words!

Do you see anything in the ~/.kit/logs/kit.log that would indicate that something failed/etc? I'm not exactly sure what to tell you to look for. I'll investigate from my end too.

@kpfromer
Copy link
Author

Looking through my log file, I don't see anything out of the ordinary, but I'll keep an eye on it when it occurs.

I'll also try doing a clean restart of everything. Hopefully that will fix it permanently.

@kpfromer
Copy link
Author

Hmm, maybe it's because I'm not calling await hide() for longer running scheduled scripts and then script kit kills the script?

[2024-08-18 14:59:01.127] [warn]  ☠️ ERROR PROMPT SHOULD SHOW ☠️
[2024-08-18 14:59:01.127] [warn]  Error: Timeout after 1 seconds waiting for HIDE_APP response
              
The app failed to send a HIDE_APP response to the script process within the expected timeframe. Halting script.

Please share this error to our GitHub Discussions with your scenario: https://github.com/johnlindquist/kit/discussions/categories/errors

    at Timeout._onTimeout (file:///Users/kpfromer/.kit/target/app.js:1605:25)
    at listOnTimeout (node:internal/timers:569:17)
    at process.processTimers (node:internal/timers:512:7)
[2024-08-18 15:12:01.124] [warn]  Error: Timeout after 1 seconds waiting for HIDE_APP response
              
The app failed to send a HIDE_APP response to the script process within the expected timeframe. Halting script.

Please share this error to our GitHub Discussions with your scenario: https://github.com/johnlindquist/kit/discussions/categories/errors

[2024-08-18 15:12:01.127] [warn]  ☠️ ERROR PROMPT SHOULD SHOW ☠️
[2024-08-18 15:12:01.127] [warn]  Error: Timeout after 1 seconds waiting for HIDE_APP response

@wesdunn
Copy link

wesdunn commented Sep 18, 2024

Note: N00b Kit user here...

Maybe try setting the KIT_HIDE_DELAY env var to something sufficient for the script to complete? This is just based off glancing at the code here: https://github.com/johnlindquist/kit/blob/main/src/api/kit.ts#L862

I could be mistaken, and it's likely that I am, so... grain of salt and all.

Other thought, given behavior reported, is there is some internal timer that maybe has some bad math behind it and creates some kind of skew as the length of the Kit process increases?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants