Documentation
¶
Index ¶
- type CreateRequest
- type DefaultHandler
- func (DefaultHandler) CreateHandler(ctx context.Context, db *gorm.DB, lotusClient jsonrpc.RPCClient, ...) (*model.Schedule, error)
- func (DefaultHandler) ListHandler(ctx context.Context, db *gorm.DB) ([]model.Schedule, error)
- func (DefaultHandler) PauseHandler(ctx context.Context, db *gorm.DB, scheduleID uint32) (*model.Schedule, error)
- func (DefaultHandler) RemoveHandler(ctx context.Context, db *gorm.DB, scheduleID uint32) error
- func (DefaultHandler) ResumeHandler(ctx context.Context, db *gorm.DB, scheduleID uint32) (*model.Schedule, error)
- func (DefaultHandler) UpdateHandler(ctx context.Context, db *gorm.DB, id uint32, request UpdateRequest) (*model.Schedule, error)
- type Handler
- type MockSchedule
- func (m *MockSchedule) CreateHandler(ctx context.Context, db *gorm.DB, lotusClient jsonrpc.RPCClient, ...) (*model.Schedule, error)
- func (m *MockSchedule) ListHandler(ctx context.Context, db *gorm.DB) ([]model.Schedule, error)
- func (m *MockSchedule) PauseHandler(ctx context.Context, db *gorm.DB, scheduleID uint32) (*model.Schedule, error)
- func (m *MockSchedule) RemoveHandler(ctx context.Context, db *gorm.DB, scheduleID uint32) error
- func (m *MockSchedule) ResumeHandler(ctx context.Context, db *gorm.DB, scheduleID uint32) (*model.Schedule, error)
- func (m *MockSchedule) UpdateHandler(ctx context.Context, db *gorm.DB, scheduleID uint32, request UpdateRequest) (*model.Schedule, error)
- type UpdateRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CreateRequest ¶
type CreateRequest struct {
Preparation string `json:"preparation" validation:"required"` // Preparation ID or name
Provider string `json:"provider" validation:"required"` // Provider
HTTPHeaders []string `json:"httpHeaders"` // http headers to be passed with the request (i.e. key=value)
URLTemplate string `json:"urlTemplate"` // URL template with PIECE_CID placeholder for boost to fetch the CAR file, i.e. http://127.0.0.1/piece/{PIECE_CID}.car
PricePerGBEpoch float64 `default:"0" json:"pricePerGbEpoch"` // Price in FIL per GiB per epoch
PricePerGB float64 `default:"0" json:"pricePerGb"` // Price in FIL per GiB
PricePerDeal float64 `default:"0" json:"pricePerDeal"` // Price in FIL per deal
Verified bool `default:"true" json:"verified"` // Whether the deal should be verified
IPNI bool `default:"true" json:"ipni"` // Whether the deal should be IPNI
KeepUnsealed bool `default:"true" json:"keepUnsealed"` // Whether the deal should be kept unsealed
StartDelay string `default:"72h" json:"startDelay"` // Deal start delay in epoch or in duration format, i.e. 1000, 72h
Duration string `default:"12840h" json:"duration"` // Duration in epoch or in duration format, i.e. 1500000, 2400h
ScheduleCron string `json:"scheduleCron"` // Schedule cron pattern
ScheduleCronPerpetual bool `json:"scheduleCronPerpetual"` // Whether a cron schedule should run in definitely
ScheduleDealNumber int `json:"scheduleDealNumber"` // Number of deals per scheduled time
TotalDealNumber int `json:"totalDealNumber"` // Total number of deals
ScheduleDealSize string `json:"scheduleDealSize"` // Size of deals per schedule trigger in human readable format, i.e. 100 TiB
TotalDealSize string `json:"totalDealSize"` // Total size of deals in human readable format, i.e. 100 TiB
Notes string `json:"notes"` // Notes
MaxPendingDealSize string `json:"maxPendingDealSize"` // Max pending deal size in human readable format, i.e. 100 TiB
MaxPendingDealNumber int `json:"maxPendingDealNumber"` // Max pending deal number
//nolint:tagliatelle
AllowedPieceCIDs []string `json:"allowedPieceCids"` // Allowed piece CIDs in this schedule
Force bool `json:"force"` // Force to send out deals regardless of replication restriction
}
type DefaultHandler ¶ added in v0.4.0
type DefaultHandler struct{}
func (DefaultHandler) CreateHandler ¶ added in v0.4.0
func (DefaultHandler) CreateHandler( ctx context.Context, db *gorm.DB, lotusClient jsonrpc.RPCClient, request CreateRequest, ) (*model.Schedule, error)
CreateHandler creates a new schedule based on the provided CreateRequest.
The function performs the following steps:
- Associates the provided context with the database connection.
- Retrieves the preparation from the database using the ID from the request.
- Parses the provided start delay and duration to ensure valid durations.
- If a ScheduleCron string is provided, it validates its correctness.
- Parses and validates the provided sizes: TotalDealSize, ScheduleDealSize, and MaxPendingDealSize.
- Verifies all provided piece CIDs in AllowedPieceCIDs to ensure their correctness.
- Checks for the presence of wallets attached to the preparation.
- Uses the lotusClient to retrieve the provider actor.
- Constructs a new model.Schedule instance from the provided and parsed data.
- Inserts the newly created schedule into the database.
- Returns the newly created schedule.
Parameters:
- ctx: The context for the operation, used for timeouts and cancellation.
- db: The database connection, used for CRUD operations related to schedules.
- lotusClient: The Lotus client, used for Filecoin RPC calls.
- request: The request object containing the data for the new schedule.
Returns:
- A pointer to the created model.Schedule if successful.
- An error indicating the reason for any failure during the operation.
func (DefaultHandler) ListHandler ¶ added in v0.4.0
ListHandler retrieves all the schedules from the database.
Parameters:
- ctx: The context for the operation, which can include cancellation signals, timeout details, etc.
- db: The database connection used for CRUD operations.
Returns:
- A slice of Schedule models if successful.
- An error if there are issues during the operation.
func (DefaultHandler) PauseHandler ¶ added in v0.4.0
func (DefaultHandler) PauseHandler( ctx context.Context, db *gorm.DB, scheduleID uint32, ) (*model.Schedule, error)
PauseHandler attempts to pause an active schedule based on the provided scheduleID. If the schedule is already completed, an error will be returned.
Parameters:
- ctx: The context for the operation, which can include cancellation signals, timeout details, etc.
- db: The database connection used for CRUD operations.
- scheduleID: The ID of the schedule to be paused.
Returns:
- A pointer to the updated Schedule if successful.
- An error if there are issues during the operation, e.g., if the schedule is not found or already completed.
func (DefaultHandler) RemoveHandler ¶ added in v0.5.2
func (DefaultHandler) ResumeHandler ¶ added in v0.4.0
func (DefaultHandler) ResumeHandler( ctx context.Context, db *gorm.DB, scheduleID uint32, ) (*model.Schedule, error)
ResumeHandler attempts to resume a previously paused schedule based on the provided scheduleID.
Parameters:
- ctx: The context for the operation, allowing for cancellation and timeouts.
- db: The database connection used for operations.
- scheduleID: The ID of the schedule to be resumed.
Returns:
- A pointer to the updated Schedule if successful.
- An error if any issues occur, e.g., if the schedule is not found or not in a paused state.
func (DefaultHandler) UpdateHandler ¶ added in v0.5.0
func (DefaultHandler) UpdateHandler( ctx context.Context, db *gorm.DB, id uint32, request UpdateRequest, ) (*model.Schedule, error)
UpdateHandler modifies an existing schedule record based on the provided update request.
It looks for the schedule record by the given schedule ID. If found, it processes the provided UpdateRequest to determine which fields should be updated. Once the desired changes are captured, the function commits these updates to the database.
Parameters:
- ctx: The context for managing timeouts and cancellation.
- db: The gorm.DB instance for database operations.
- id: The ID of the schedule to be updated.
- request: The UpdateRequest containing the desired changes.
Returns:
- The updated model.Schedule if the operation is successful.
- An error if any issues occur during the operation, including invalid parameters or database errors.
type Handler ¶ added in v0.4.0
type Handler interface {
CreateHandler(
ctx context.Context,
db *gorm.DB,
lotusClient jsonrpc.RPCClient,
request CreateRequest,
) (*model.Schedule, error)
UpdateHandler(
ctx context.Context,
db *gorm.DB,
scheduleID uint32,
request UpdateRequest,
) (*model.Schedule, error)
ListHandler(
ctx context.Context,
db *gorm.DB,
) ([]model.Schedule, error)
PauseHandler(
ctx context.Context,
db *gorm.DB,
scheduleID uint32,
) (*model.Schedule, error)
RemoveHandler(
ctx context.Context,
db *gorm.DB,
scheduleID uint32,
) error
ResumeHandler(
ctx context.Context,
db *gorm.DB,
scheduleID uint32,
) (*model.Schedule, error)
}
var Default Handler = &DefaultHandler{}
type MockSchedule ¶ added in v0.5.0
func (*MockSchedule) CreateHandler ¶ added in v0.5.0
func (m *MockSchedule) CreateHandler(ctx context.Context, db *gorm.DB, lotusClient jsonrpc.RPCClient, request CreateRequest) (*model.Schedule, error)
func (*MockSchedule) ListHandler ¶ added in v0.5.0
func (*MockSchedule) PauseHandler ¶ added in v0.5.0
func (*MockSchedule) RemoveHandler ¶ added in v0.5.2
func (*MockSchedule) ResumeHandler ¶ added in v0.5.0
func (*MockSchedule) UpdateHandler ¶ added in v0.5.0
func (m *MockSchedule) UpdateHandler(ctx context.Context, db *gorm.DB, scheduleID uint32, request UpdateRequest) (*model.Schedule, error)
type UpdateRequest ¶ added in v0.5.0
type UpdateRequest struct {
HTTPHeaders []string `json:"httpHeaders"` // http headers to be passed with the request (i.e. key=value)
URLTemplate *string `json:"urlTemplate"` // URL template with PIECE_CID placeholder for boost to fetch the CAR file, i.e. http://127.0.0.1/piece/{PIECE_CID}.car
PricePerGBEpoch *float64 `default:"0" json:"pricePerGbEpoch"` // Price in FIL per GiB per epoch
PricePerGB *float64 `default:"0" json:"pricePerGb"` // Price in FIL per GiB
PricePerDeal *float64 `default:"0" json:"pricePerDeal"` // Price in FIL per deal
Verified *bool `default:"true" json:"verified"` // Whether the deal should be verified
IPNI *bool `default:"true" json:"ipni"` // Whether the deal should be IPNI
KeepUnsealed *bool `default:"true" json:"keepUnsealed"` // Whether the deal should be kept unsealed
StartDelay *string `default:"72h" json:"startDelay"` // Deal start delay in epoch or in duration format, i.e. 1000, 72h
Duration *string `default:"12840h" json:"duration"` // Duration in epoch or in duration format, i.e. 1500000, 2400h
ScheduleCron *string `json:"scheduleCron"` // Schedule cron pattern
ScheduleCronPerpetual *bool `json:"scheduleCronPerpetual"` // Whether a cron schedule should run in definitely
ScheduleDealNumber *int `json:"scheduleDealNumber"` // Number of deals per scheduled time
TotalDealNumber *int `json:"totalDealNumber"` // Total number of deals
ScheduleDealSize *string `json:"scheduleDealSize"` // Size of deals per schedule trigger in human readable format, i.e. 100 TiB
TotalDealSize *string `json:"totalDealSize"` // Total size of deals in human readable format, i.e. 100 TiB
Notes *string `json:"notes"` // Notes
MaxPendingDealSize *string `json:"maxPendingDealSize"` // Max pending deal size in human readable format, i.e. 100 TiB
MaxPendingDealNumber *int `json:"maxPendingDealNumber"` // Max pending deal number
//nolint:tagliatelle
AllowedPieceCIDs []string `json:"allowedPieceCids"` // Allowed piece CIDs in this schedule
Force *bool `json:"force"` // Force to send out deals regardless of replication restriction
}