Chuyển đến nội dung chính
Apidly Cloud
Chính sách cookie

Cookie phân tích và quảng cáo luôn tắt trừ khi bạn chấp nhận. Chính sách cookie

Chúng tôi muốn dùng Google Analytics và Microsoft Clarity để hiểu cách các trang công khai được sử dụng, gồm lượt xem trang và bản ghi phiên, cùng Reddit Pixel để đo xem quảng cáo của chúng tôi trên Reddit có mang lại lượt truy cập và đăng ký hay không. Bạn chọn tại đây xem chúng có được bật hay không. Từ chối không thay đổi cách trang web hoạt động.

Co giãn, phiên bản và nhật ký endpoint từ code

Áp dụng preset co giãn, đặt hạn mức chi tiêu hằng tháng, liệt kê và khôi phục phiên bản và đọc nhật ký worker của endpoint serverless bằng curl, CLI, JavaScript hoặc Python.

Cập nhật lần cuối 24 tháng 11, 2026Đọc trong 2 phút
Xem dưới dạng Markdown

Trang này làm từ script những gì thẻ Co giãn và chi tiêu, thẻ Phiên bản và nhật ký worker của một endpoint làm trong console. Các ví dụ dùng id endpoint ep_ID. Đọc thì dùng được khóa read; thay đổi cần khóa có scope full. Khóa gắn với một endpoint chỉ gọi được endpoint đó, nên không làm được việc nào ở đây. Endpoint serverless có thể chưa được bật cho tài khoản của bạn. Ý nghĩa của từng thiết lập được giải thích ở Endpoint serverless.

Áp dụng preset co giãn

Liệt kê ba preset cùng chi phí mỗi giờ của từng preset theo giá hôm nay, khi không có lưu lượng (idleHourlyMicros) và khi tải tối đa (maxHourlyMicros); current đánh dấu preset mà endpoint đang khớp. Sau đó áp dụng một preset. Preset được lưu như mọi thay đổi khác, nên cũng trở thành một phiên bản, và không bao giờ bắt đầu cập nhật cuốn chiếu.

curl "https://apidly.com/api/v1/endpoints/ep_ID/presets" \
  -H "Authorization: Bearer $APIDLY_API_KEY"

curl -X POST "https://apidly.com/api/v1/endpoints/ep_ID/presets" \
  -H "Authorization: Bearer $APIDLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"preset":"scale_to_zero"}'

apidly endpoints presets ep_ID
apidly endpoints preset ep_ID scale_to_zero
import { Apidly } from "@apidly/sdk";

const apidly = new Apidly({ apiKey: process.env.APIDLY_API_KEY });
const { presets } = await apidly.endpoints.presets("ep_ID");
for (const p of presets) {
  console.log(p.name, p.idleHourlyMicros, p.maxHourlyMicros, p.current);
}
await apidly.endpoints.applyPreset("ep_ID", "scale_to_zero");
import os
from apidly import Client

client = Client(api_key=os.environ["APIDLY_API_KEY"])
for p in client.endpoints.presets("ep_ID")["presets"]:
    print(p["name"], p["idleHourlyMicros"], p["maxHourlyMicros"], p["current"])
client.endpoints.apply_preset("ep_ID", "scale_to_zero")

Đặt hạn mức chi tiêu hằng tháng

Hạn mức tính bằng đô la Mỹ cho mỗi tháng dương lịch (UTC). Khi chạm hạn mức, endpoint tự tạm dừng, giải phóng các worker và gửi email cho chủ sở hữu. Với resumeAtNewMonth, nó tự chạy lại khi tháng sau bắt đầu. Gửi null (trong CLI là none) để bỏ hạn mức.

curl -X PATCH "https://apidly.com/api/v1/endpoints/ep_ID" \
  -H "Authorization: Bearer $APIDLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"monthlySpendCapUsd":50,"resumeAtNewMonth":true}'

apidly endpoints update ep_ID --monthly-cap 50 --resume-at-new-month on
apidly endpoints update ep_ID --monthly-cap none
import { Apidly } from "@apidly/sdk";

const apidly = new Apidly({ apiKey: process.env.APIDLY_API_KEY });
await apidly.endpoints.update("ep_ID", {
  monthlySpendCapUsd: 50,
  resumeAtNewMonth: true,
});
const { endpoint } = await apidly.endpoints.get("ep_ID");
console.log(endpoint.spendCap);
import os
from apidly import Client

client = Client(api_key=os.environ["APIDLY_API_KEY"])
client.endpoints.update("ep_ID", {"monthlySpendCapUsd": 50, "resumeAtNewMonth": True})
print(client.endpoints.get("ep_ID")["endpoint"]["spendCap"])

Liệt kê và khôi phục phiên bản

Mỗi thay đổi đã lưu là một phiên bản có số thứ tự, mới nhất ở đầu, với biến môi trường chỉ hiện tên. Khôi phục đưa thiết lập của một phiên bản trở lại thành một phiên bản mới; nếu điều đó đổi thiết lập worker, một lần cập nhật cuốn chiếu sẽ bắt đầu. CLI hỏi trước khi khôi phục trừ khi bạn truyền --yes.

curl "https://apidly.com/api/v1/endpoints/ep_ID/releases?limit=20" \
  -H "Authorization: Bearer $APIDLY_API_KEY"

curl -X POST "https://apidly.com/api/v1/endpoints/ep_ID/releases/VERSION/restore" \
  -H "Authorization: Bearer $APIDLY_API_KEY"

apidly endpoints releases ep_ID --limit 20
apidly endpoints restore ep_ID 3
import { Apidly } from "@apidly/sdk";

const apidly = new Apidly({ apiKey: process.env.APIDLY_API_KEY });
const { releases } = await apidly.endpoints.releases("ep_ID", { limit: 20 });
console.log(releases.map((r) => r.version));
const { changed } = await apidly.endpoints.restoreRelease("ep_ID", 3);
console.log(changed);
import os
from apidly import Client

client = Client(api_key=os.environ["APIDLY_API_KEY"])
for r in client.endpoints.releases("ep_ID", limit=20)["releases"]:
    print(r["version"], r["changes"])
print(client.endpoints.restore_release("ep_ID", 3)["changed"])

Đọc nhật ký worker

Nhật ký của endpoint là các dòng mới nhất của từng worker, tối đa 12 worker mỗi lần gọi, hoặc của một worker với worker. Nhật ký của một job là nhật ký của worker đã chạy nó; available: false với reason not_dispatched hoặc worker_gone nghĩa là không có gì để đọc. tail đặt số dòng, tối đa 500. Giá trị bí mật được ẩn trong mọi nhật ký.

curl "https://apidly.com/api/v1/endpoints/ep_ID/logs?tail=100" \
  -H "Authorization: Bearer $APIDLY_API_KEY"

curl "https://apidly.com/api/v1/endpoints/ep_ID/logs?worker=ins_ID&tail=200" \
  -H "Authorization: Bearer $APIDLY_API_KEY"

curl "https://apidly.com/api/v1/endpoints/ep_ID/jobs/job_ID/logs?tail=200" \
  -H "Authorization: Bearer $APIDLY_API_KEY"

apidly endpoints logs ep_ID --tail 100
apidly endpoints logs ep_ID --worker ins_ID
apidly endpoints job-logs ep_ID job_ID
import { Apidly } from "@apidly/sdk";

const apidly = new Apidly({ apiKey: process.env.APIDLY_API_KEY });
const { workers } = await apidly.endpoints.logs("ep_ID", { tail: 100 });
for (const w of workers) {
  console.log(`== ${w.serverId} (${w.status})\n${w.logs}`);
}
const { job } = await apidly.endpoints.jobLogs("ep_ID", "job_ID", { tail: 200 });
console.log(job.available ? job.logs : job.reason);
import os
from apidly import Client

client = Client(api_key=os.environ["APIDLY_API_KEY"])
for w in client.endpoints.logs("ep_ID", tail=100, worker="ins_ID")["workers"]:
    print(w["serverId"], w["logs"])
job = client.endpoints.job_logs("ep_ID", "job_ID", tail=200)["job"]
print(job["logs"] if job["available"] else job["reason"])

Sẵn sàng thử chưa?

Tạo tài khoản miễn phí và nạp tín dụng khi bạn muốn khởi chạy máy chủ. Mức nạp tối thiểu là 10 $.

Tạo tài khoản miễn phí

Nội dung này có hữu ích không?

Vẫn chưa giải quyết được? Liên hệ chúng tôi