Skip to content

Commit

Permalink
Merge pull request #1174 from cicoyle/fix-jobs-api
Browse files Browse the repository at this point in the history
Jobs API Clarity: Rename schedulerDaprHttpPort -> jobServiceDaprHttpPort
  • Loading branch information
alicejgibbons authored Mar 3, 2025
2 parents 2f5a5d0 + a7d5808 commit 43a98a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
6 changes: 3 additions & 3 deletions jobs/csharp/http/job-scheduler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
};

var daprHost = Environment.GetEnvironmentVariable("DAPR_HOST") ?? "http://localhost";
var schedulerDaprHttpPort = "6280";
var jobServiceDaprHttpPort = "6280";

var httpClient = new HttpClient();

Expand Down Expand Up @@ -48,7 +48,7 @@

async Task ScheduleJob(string jobName, object jobBody)
{
var reqURL = $"{daprHost}:{schedulerDaprHttpPort}/v1.0-alpha1/jobs/{jobName}";
var reqURL = $"{daprHost}:{jobServiceDaprHttpPort}/v1.0-alpha1/jobs/{jobName}";
var jsonBody = JsonSerializer.Serialize(jobBody);
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");

Expand All @@ -64,7 +64,7 @@ async Task ScheduleJob(string jobName, object jobBody)

async Task GetJobDetails(string jobName)
{
var reqURL = $"{daprHost}:{schedulerDaprHttpPort}/v1.0-alpha1/jobs/{jobName}";
var reqURL = $"{daprHost}:{jobServiceDaprHttpPort}/v1.0-alpha1/jobs/{jobName}";

var response = await httpClient.GetAsync(reqURL);

Expand Down
8 changes: 4 additions & 4 deletions jobs/go/http/job-scheduler/job-scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func main() {
daprHost = "http://localhost"
}

schedulerDaprHttpPort := "6280"
jobServiceDaprHttpPort := "6280"

client := http.Client{
Timeout: 15 * time.Second,
}

// Schedule a job using the Dapr Jobs API with short dueTime
jobName := "R2-D2"
reqURL := daprHost + ":" + schedulerDaprHttpPort + "/v1.0-alpha1/jobs/" + jobName
reqURL := daprHost + ":" + jobServiceDaprHttpPort + "/v1.0-alpha1/jobs/" + jobName

req, err := http.NewRequest("POST", reqURL, strings.NewReader(r2d2JobBody))
if err != nil {
Expand Down Expand Up @@ -71,7 +71,7 @@ func main() {
// Schedule a job using the Dapr Jobs API with long dueTime
jobName = "C-3PO"

reqURL = daprHost + ":" + schedulerDaprHttpPort + "/v1.0-alpha1/jobs/" + jobName
reqURL = daprHost + ":" + jobServiceDaprHttpPort + "/v1.0-alpha1/jobs/" + jobName

req, err = http.NewRequest("POST", reqURL, strings.NewReader(c3poJobBody))
if err != nil {
Expand All @@ -93,7 +93,7 @@ func main() {

// Gets a job using the Dapr Jobs API
jobName = "C-3PO"
reqURL = daprHost + ":" + schedulerDaprHttpPort + "/v1.0-alpha1/jobs/" + jobName
reqURL = daprHost + ":" + jobServiceDaprHttpPort + "/v1.0-alpha1/jobs/" + jobName

res, err = http.Get(reqURL)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions jobs/javascript/http/job-scheduler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const r2d2JobBody = {
dueTime: "15s",
};
const daprHost = process.env.DAPR_HOST || "http://localhost";
const schedulerDaprHttpPort = "6280";
const jobServiceDaprHttpPort = "6280";

async function main() {
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
Expand Down Expand Up @@ -45,7 +45,7 @@ async function main() {
}

async function scheduleJob(jobName, jobBody) {
const reqURL = `${daprHost}:${schedulerDaprHttpPort}/v1.0-alpha1/jobs/${jobName}`;
const reqURL = `${daprHost}:${jobServiceDaprHttpPort}/v1.0-alpha1/jobs/${jobName}`;
const response = await fetch(reqURL, {
method: "POST",
headers: {
Expand All @@ -64,7 +64,7 @@ async function scheduleJob(jobName, jobBody) {
}

async function getJobDetails(jobName) {
const reqURL = `${daprHost}:${schedulerDaprHttpPort}/v1.0-alpha1/jobs/${jobName}`;
const reqURL = `${daprHost}:${jobServiceDaprHttpPort}/v1.0-alpha1/jobs/${jobName}`;
const response = await fetch(reqURL, {
method: "GET",
});
Expand Down
5 changes: 5 additions & 0 deletions jobs/python/http/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ This quickstart includes two apps:
- [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
- [Initialized Dapr environment](https://docs.dapr.io/getting-started/install-dapr-selfhost/)

## Environment Variables

- `JOB_SERVICE_DAPR_HTTP_PORT`: The Dapr HTTP port of the job-service (default: 6280)
- `DAPR_HOST`: The Dapr host address (default: http://localhost)

## Install dependencies

<!-- STEP
Expand Down
8 changes: 4 additions & 4 deletions jobs/python/http/job-scheduler/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def main():
time.sleep(5)

dapr_host = os.getenv('DAPR_HOST', 'http://localhost')
scheduler_dapr_http_port = os.getenv('SCHEDULER_DAPR_HTTP_PORT', '6280')
job_service_dapr_http_port = os.getenv('JOB_SERVICE_DAPR_HTTP_PORT', '6280')

# Schedule R2-D2 job
schedule_job(dapr_host, scheduler_dapr_http_port, "R2-D2", R2D2_JOB_BODY)
schedule_job(dapr_host, job_service_dapr_http_port, "R2-D2", R2D2_JOB_BODY)
time.sleep(5)

# Schedule C-3PO job
schedule_job(dapr_host, scheduler_dapr_http_port, "C-3PO", C3PO_JOB_BODY)
schedule_job(dapr_host, job_service_dapr_http_port, "C-3PO", C3PO_JOB_BODY)
time.sleep(5)

# Get C-3PO job details
get_job_details(dapr_host, scheduler_dapr_http_port, "C-3PO")
get_job_details(dapr_host, job_service_dapr_http_port, "C-3PO")
time.sleep(5)

if __name__ == "__main__":
Expand Down

0 comments on commit 43a98a1

Please sign in to comment.