diff --git a/cheddahbot/scheduler.py b/cheddahbot/scheduler.py index bd21f24..c3fed70 100644 --- a/cheddahbot/scheduler.py +++ b/cheddahbot/scheduler.py @@ -521,7 +521,7 @@ class Scheduler: # ── AutoCora Result Polling ── def _autocora_loop(self): - """Poll for AutoCora results on a regular interval.""" + """Auto-submit jobs for today's tasks, then poll for results.""" interval = self.config.autocora.poll_interval_minutes * 60 # Wait before first poll @@ -529,6 +529,7 @@ class Scheduler: while not self._stop_event.is_set(): try: + self._auto_submit_cora_jobs() self._poll_autocora_results() self.db.kv_set( "system:loop:autocora:last_run", datetime.now(UTC).isoformat() @@ -537,6 +538,22 @@ class Scheduler: log.error("AutoCora poll error: %s", e) self._interruptible_wait(interval, self._force_autocora) + def _auto_submit_cora_jobs(self): + """Auto-submit AutoCora jobs for tasks due today.""" + from .tools.autocora import submit_autocora_jobs + + if not self.config.clickup.api_token: + return + + today = datetime.now(UTC).strftime("%Y-%m-%d") + ctx = { + "config": self.config, + "db": self.db, + "agent": self.agent, + } + result = submit_autocora_jobs(target_date=today, ctx=ctx) + log.info("AutoCora auto-submit (%s): %s", today, result) + def _poll_autocora_results(self): """Check for completed AutoCora results and update ClickUp tasks.""" from .tools.autocora import _parse_result @@ -757,7 +774,7 @@ class Scheduler: args = { "xlsx_path": str(xlsx_path), - "project_name": matched_task.name, + "project_name": matched_task.custom_fields.get("Keyword", "") or matched_task.name, "money_site_url": money_site_url, "custom_anchors": matched_task.custom_fields.get("CustomAnchors", "") or "", "cli_flags": matched_task.custom_fields.get("CLIFlags", "") or "", diff --git a/cheddahbot/tools/autocora.py b/cheddahbot/tools/autocora.py index 9044a06..4f68cf7 100644 --- a/cheddahbot/tools/autocora.py +++ b/cheddahbot/tools/autocora.py @@ -135,8 +135,7 @@ def _group_by_keyword(tasks, all_tasks): url = task.custom_fields.get("IMSURL", "") or "" url = str(url).strip() if not url: - alerts.append(f"Task '{task.name}' (id={task.id}) missing IMSURL field") - continue + url = "https://seotoollab.com/blank.html" kw_lower = keyword.lower() if kw_lower not in groups: @@ -251,6 +250,10 @@ def submit_autocora_jobs(target_date: str = "", ctx: dict | None = None) -> str: } db.kv_set(kv_key, json.dumps(kv_state)) + # Move ClickUp tasks to "automation underway" + for tid in group["task_ids"]: + client.update_task_status(tid, "automation underway") + submitted.append(group["keyword"]) log.info("Submitted AutoCora job: %s → %s", group["keyword"], job_id)