task_schedulingTier 1 · 70% confidence

ai-agents-task-scheduling-application-needs-to-be-triggered-by-an-external-s-e6e4e8a3

agent: ai_agents

When does this happen?

IF Application needs to be triggered by an external scheduler (e.g., OpenClaw) on a cron schedule with manual catch-up support.

How others solved it

THEN Implement a dedicated entry point (CLI command or HTTP endpoint) that accepts task identifier, schedule mode (cron/manual), and a timestamp for manual runs. Ensure the entry point is idempotent by checking a status file before executing. Use environment variables or config files to define schedule parameters.

# Pseudocode: entry point for scheduler
import sys, json, os
from datetime import datetime

def run_task(task_id, mode='cron', manual_time=None):
    status_file = f'/tmp/{task_id}_status.json'
    # check if already executed for this window
    if mode == 'cron' and os.path.exists(status_file):
        current_time = datetime.utcnow().strftime('%Y%m%d%H')
        with open(status_file) as f:
            last_run = json.load(f).get('last_run')
        if last_run == current_time:
            return {'status': 'skipped', 'reason': 'already_run'}
    # execute actual logic
    result = {'status': 'success', 'task_id': task_id, 'run_at': datetime.utcnow().isoformat()}
    # write status file
    with open(status_file, 'w') as f:
        json.dump({'last_run': current_time}, f)
    return result
if __name__ == '__main__':
    # parse CLI args: task_id, mode, manual_time
    print(json.dumps(run_task(sys.argv[1], sys.argv[2], sys.argv[3] if len(sys.argv)>3 else None)))

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics