Skip to content

Commit 9c650a7

Browse files
committed
Replace container polling with a simple 10s sleep before publish
1 parent 947a4b7 commit 9c650a7

1 file changed

Lines changed: 3 additions & 19 deletions

File tree

social_posters/instagram.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def publish(self, post: Post) -> PostResult:
5959

6060
try:
6161
container_id = self._create_media_container(post)
62-
self._wait_for_container(container_id)
62+
time.sleep(10)
63+
6364
media_id = self._publish_media(container_id)
6465
return PostResult(
6566
success=True,
@@ -91,24 +92,7 @@ def _create_media_container(self, post: Post) -> str:
9192
response.raise_for_status()
9293
return response.json()["id"]
9394

94-
def _wait_for_container(self, container_id: str, max_attempts: int = 10, interval: int = 5):
95-
"""Poll the container status until it's FINISHED or an error occurs."""
96-
for attempt in range(max_attempts):
97-
response = requests.get(
98-
f"{GRAPH_API_BASE}/{container_id}",
99-
params={"fields": "status_code", "access_token": self.access_token},
100-
timeout=10,
101-
)
102-
response.raise_for_status()
103-
status = response.json().get("status_code")
104-
print(f"Instagram container {container_id} status: {status} (attempt {attempt + 1}/{max_attempts})")
105-
if status == "FINISHED":
106-
return
107-
if status in ("ERROR", "EXPIRED"):
108-
raise RuntimeError(f"Instagram container {container_id} status: {status}")
109-
time.sleep(interval)
110-
raise RuntimeError(f"Instagram container {container_id} not ready after {max_attempts * interval}s")
111-
95+
11296
def _publish_media(self, container_id: str) -> str:
11397
response = requests.post(
11498
f"{GRAPH_API_BASE}/{self.account_id}/media_publish",

0 commit comments

Comments
 (0)