-
Notifications
You must be signed in to change notification settings - Fork 81
Initial commit for task end points #691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e5b62fc
Initial commit for task end points
bluepal-prasanthi-moparthi dc1859e
Initial commit for task end points
bluepal-prasanthi-moparthi b3f4605
changed printf to logf
bluepal-prasanthi-moparthi 61a0073
added logs and added params in test case
bluepal-prasanthi-moparthi 0ac168e
modifed test casses added validation for task options and dbName
bluepal-prasanthi-moparthi caf59c0
changes in validator
bluepal-prasanthi-moparthi 9b60f46
chore: trigger CI with empty commit
bluepal-prasanthi-moparthi f7e08a7
Added necessary pointers in struct
bluepal-prasanthi-moparthi adfc9a3
added pointers in task implementation
bluepal-prasanthi-moparthi b763974
added note in changelog file
bluepal-prasanthi-moparthi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,5 @@ type Client interface { | |
| ClientAdmin | ||
| ClientAsyncJob | ||
| ClientFoxx | ||
| ClientTasks | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // DISCLAIMER | ||
| // | ||
| // Copyright 2024 ArangoDB GmbH, Cologne, Germany | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Copyright holder is ArangoDB GmbH, Cologne, Germany | ||
|
|
||
| package arangodb | ||
|
|
||
| import ( | ||
| "context" | ||
| ) | ||
|
|
||
| // ClientTasks defines the interface for managing tasks in ArangoDB. | ||
| type ClientTasks interface { | ||
| // Task retrieves an existing task by its ID. | ||
| // If no task with the given ID exists, a NotFoundError is returned. | ||
| Task(ctx context.Context, databaseName string, id string) (Task, error) | ||
|
|
||
| // Tasks returns a list of all tasks on the server. | ||
| Tasks(ctx context.Context, databaseName string) ([]Task, error) | ||
|
|
||
| // CreateTask creates a new task with the specified options. | ||
| CreateTask(ctx context.Context, databaseName string, options TaskOptions) (Task, error) | ||
|
|
||
| // If a task with the given ID already exists, a Conflict error is returned. | ||
| CreateTaskWithID(ctx context.Context, databaseName string, id string, options TaskOptions) (Task, error) | ||
|
|
||
| // RemoveTask deletes an existing task by its ID. | ||
| RemoveTask(ctx context.Context, databaseName string, id string) error | ||
| } | ||
|
|
||
| // TaskOptions contains options for creating a new task. | ||
| type TaskOptions struct { | ||
| // ID is an optional identifier for the task. | ||
| ID *string `json:"id,omitempty"` | ||
| // Name is an optional name for the task. | ||
| Name *string `json:"name,omitempty"` | ||
|
|
||
| // Command is the JavaScript code to be executed. | ||
| Command *string `json:"command"` | ||
|
|
||
| // Params are optional parameters passed to the command. | ||
| Params interface{} `json:"params,omitempty"` | ||
|
|
||
| // Period is the interval (in seconds) at which the task runs periodically. | ||
| // If zero, the task runs once after the offset. | ||
| Period *int64 `json:"period,omitempty"` | ||
|
|
||
| // Offset is the delay (in milliseconds) before the task is first executed. | ||
| Offset *float64 `json:"offset,omitempty"` | ||
| } | ||
|
|
||
| // Task provides access to a single task on the server. | ||
| type Task interface { | ||
| // ID returns the ID of the task. | ||
| ID() *string | ||
|
|
||
| // Name returns the name of the task. | ||
| Name() *string | ||
|
|
||
| // Command returns the JavaScript code of the task. | ||
| Command() *string | ||
|
|
||
| // Params returns the parameters of the task. | ||
| Params(result interface{}) error | ||
|
|
||
| // Period returns the period (in seconds) of the task. | ||
| Period() *int64 | ||
|
|
||
| // Offset returns the offset (in milliseconds) of the task. | ||
| Offset() *float64 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,272 @@ | ||||||
| // DISCLAIMER | ||||||
| // | ||||||
| // Copyright 2024 ArangoDB GmbH, Cologne, Germany | ||||||
| // | ||||||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
| // you may not use this file except in compliance with the License. | ||||||
| // You may obtain a copy of the License at | ||||||
| // | ||||||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||||||
| // | ||||||
| // Unless required by applicable law or agreed to in writing, software | ||||||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||||||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| // See the License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
| // | ||||||
| // Copyright holder is ArangoDB GmbH, Cologne, Germany | ||||||
| // | ||||||
|
|
||||||
| package arangodb | ||||||
|
|
||||||
| import ( | ||||||
| "context" | ||||||
| "encoding/json" | ||||||
| "fmt" | ||||||
| "net/http" | ||||||
| "net/url" | ||||||
|
|
||||||
| "github.com/pkg/errors" | ||||||
|
|
||||||
| "github.com/arangodb/go-driver/v2/arangodb/shared" | ||||||
| "github.com/arangodb/go-driver/v2/connection" | ||||||
| ) | ||||||
|
|
||||||
| type clientTask struct { | ||||||
| client *client | ||||||
| } | ||||||
|
|
||||||
| // newClientTask initializes a new task client with the given database name. | ||||||
| func newClientTask(client *client) *clientTask { | ||||||
| return &clientTask{ | ||||||
| client: client, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // will check all methods in ClientTasks are implemented with the clientTask struct. | ||||||
| var _ ClientTasks = &clientTask{} | ||||||
|
|
||||||
| type taskResponse struct { | ||||||
| ID string `json:"id,omitempty"` | ||||||
| Name string `json:"name,omitempty"` | ||||||
| Command string `json:"command,omitempty"` | ||||||
| Params json.RawMessage `json:"params,omitempty"` | ||||||
| Period int64 `json:"period,omitempty"` | ||||||
| Offset float64 `json:"offset,omitempty"` | ||||||
| } | ||||||
|
|
||||||
| func newTask(client *client, resp *taskResponse) Task { | ||||||
| return &task{ | ||||||
| client: client, | ||||||
| id: &resp.ID, | ||||||
| name: &resp.Name, | ||||||
| command: &resp.Command, | ||||||
| params: resp.Params, | ||||||
| period: &resp.Period, | ||||||
| offset: &resp.Offset, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| type task struct { | ||||||
| client *client | ||||||
| id *string | ||||||
| name *string | ||||||
| command *string | ||||||
| params json.RawMessage | ||||||
| period *int64 | ||||||
| offset *float64 | ||||||
| } | ||||||
|
|
||||||
| // Task interface implementation for the task struct. | ||||||
| func (t *task) ID() *string { | ||||||
| return t.id | ||||||
| } | ||||||
|
|
||||||
| func (t *task) Name() *string { | ||||||
| return t.name | ||||||
| } | ||||||
|
|
||||||
| func (t *task) Command() *string { | ||||||
| return t.command | ||||||
| } | ||||||
|
|
||||||
| func (t *task) Params(result interface{}) error { | ||||||
| if t.params == nil { | ||||||
| return nil | ||||||
| } | ||||||
| return json.Unmarshal(t.params, result) | ||||||
| } | ||||||
|
|
||||||
| func (t *task) Period() *int64 { | ||||||
| return t.period | ||||||
| } | ||||||
|
|
||||||
| func (t *task) Offset() *float64 { | ||||||
| return t.offset | ||||||
| } | ||||||
|
|
||||||
| // Tasks retrieves all tasks from the specified database. | ||||||
| // Retuns a slice of Task objects representing the tasks in the database. | ||||||
|
||||||
| // Retuns a slice of Task objects representing the tasks in the database. | |
| // Returns a slice of Task objects representing the tasks in the database. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.