Skip to content

Commit

Permalink
Day of Week / Month support (#212)
Browse files Browse the repository at this point in the history
* Day of Week / Month support

* Allow zero values

* Add docs

* Add docs

* Add docs

* Add docs
  • Loading branch information
bajb authored Oct 7, 2024
1 parent 29feb1b commit 6f5395d
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 38 deletions.
128 changes: 90 additions & 38 deletions docs/scheduler/sequential.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,85 @@
# Sequential Scheduler

The sequential scheduler allows for a sequence or schedule of connectors to be used when attempting to complete a charge.
The sequential scheduler allows for a sequence or schedule of connectors to be used when attempting to complete a charge.
They are mapped by attempt number.

## Format

As with all configs, the standard wrapper is used.

```json5
{
"kind": "SchedulerSequential", // Must be set to "SchedulerSequential"
"kind": "SchedulerSequential",
// Must be set to "SchedulerSequential"
"metadata": {
"projectId": "test-project", // Must be set to the ChargeHive Project ID you were issued with
"name": "test-scheduler" // Set this to a memorable name for the method lock policy, no spaces, all lowercase
"projectId": "test-project",
// Must be set to the ChargeHive Project ID you were issued with
"name": "test-scheduler"
// Set this to a memorable name for the method lock policy, no spaces, all lowercase
},
"specVersion": "v1", // Must be set to the correct version
"selector": {}, // May be used to apply this to a subset of charges
"specVersion": "v1",
// Must be set to the correct version
"selector": {},
// May be used to apply this to a subset of charges
"spec": {
"schedules": { // Schedule object with the sequence of operation
"schedules": {
// Schedule object with the sequence of operation
"0": {
"attemptConfig": { // Configuration used when processing this schedule
"poolType": "single", // The order that this attempt should iterate connectors
"methodSelector": "primary", // How payment method should be selected for this attempt
"connectorLimit": 0, // Maximum number of connectors to process within an attempt per method
"methodLimit": 0, // Maximum number of methods to be attempt per method
"cascadeDelay": null, // Delay between connector cascades
"overridePoolConnectorIDs": [ // Overrides the pool, and selects these connectors
"attemptConfig": {
// Configuration used when processing this schedule
"poolType": "single",
// The order that this attempt should iterate connectors
"methodSelector": "primary",
// How payment method should be selected for this attempt
"connectorLimit": 0,
// Maximum number of connectors to process within an attempt per method
"methodLimit": 0,
// Maximum number of methods to be attempt per method
"cascadeDelay": null,
// Delay between connector cascades
"overridePoolConnectorIDs": [
// Overrides the pool, and selects these connectors
"test-connector"
]
},
"timeDelay": 86400000000000, // Delay in nanoseconds before the next Attempt - if set to 0, ChargeHive will still delay 30 minutes to avoid multiple attempts at the same time
"timeDelayOrigin": "initialisation", // Defines when the Delay before the next Attempt is based from - either "initialisation" or "last-failure"
"timeDelaySync": "Closest", // Specifies when the transaction should be performed relative to the schedules TimeSync
"timeWindowHours": "2", // Specifies the available duration for the transaction to be queued within
"timeSyncHour": 2, // An hour designation
"timeSyncZone": "UTC" // UTC or ULT
},
"timeDelay": 86400000000000,
// Delay in nanoseconds before the next Attempt - if set to 0, ChargeHive will still delay 30 minutes to avoid multiple attempts at the same time
"timeDelayOrigin": "initialisation",
// Defines when the Delay before the next Attempt is based from - either "initialisation" or "last-failure"
"timeDelaySync": "Closest",
// Specifies when the transaction should be performed relative to the schedules TimeSync
"timeWindowHours": "2",
// Specifies the available duration for the transaction to be queued within
"timeSyncHour": 2,
// An hour designation
"timeSyncZone": "UTC",
// UTC or ULT
"dayOfMonth": 1,
// Day of the month to run, e.g. 1st
"dayOfWeek": 2
// Day of the week to run, e.g. Tuesday (Monday = 1, Sunday = 7)
},
}
}
}
```

### Schedule Definition

FieldName | Required | Definition
---:|---|:---
[attemptConfig](#attemptconfig-definition)|true|Configuration to use when processing this schedule
timeDelay|true|Amount of time to wait before processing after TimeDelayOrigin in **nanoseconds**
[timeDelayOrigin](#timedelayorigin-values)|true|Specifies when the time origin is based from
[timeDelaySync](#timedelaysync-values)|true|Specifies when the transaction should be performed relative to the schedules TimeSync
timeSyncHour|true|An hour designation (0-23) i.e 2 == 2AM. Ignored if TimeDelaySync is set to None
[timeSyncZone](#timesynczone-values)|true|Indicates the timezone that the TimeSyncHour is relative to. Ignored if TimeDelaySync is set to None
---:|----------|:---
[attemptConfig](#attemptconfig-definition)| true |Configuration to use when processing this schedule
timeDelay| true |Amount of time to wait before processing after TimeDelayOrigin in **nanoseconds**
[timeDelayOrigin](#timedelayorigin-values)| true |Specifies when the time origin is based from
[timeDelaySync](#timedelaysync-values)| true |Specifies when the transaction should be performed relative to the schedules TimeSync
timeWindowHours| false |Specifies the available duration for the transaction to be queued within
timeSyncHour| true |An hour designation (0-23) i.e 2 == 2AM. Ignored if TimeDelaySync is set to None
[timeSyncZone](#timesynczone-values)| true |Indicates the timezone that the TimeSyncHour is relative to. Ignored if TimeDelaySync is set to None
dayOfMonth| false |Day of the month to run (1-28)
dayOfWeek| false |Day of the week to run (1-7) (Monday = 1, Sunday = 7)

### AttemptConfig Definition

FieldName | Required | Definition
---:|---|:---
[poolType](#pooltype-values)|true|The order that this attempt should iterate connectors
Expand All @@ -61,13 +90,15 @@ cascadeDelay|true|Duration to wait between each cascade in **nanoseconds** or nu
overridePoolConnectorIDs|false|will use this connectors instead of the ones in the pool

### PoolType Values

Value | Definition
---:|:---
"single"|Provides a pool of a single connector
"failover"|Processes the pool items in order until retrieving a result
"cascade"|Iterate connectors according to cascade rules

### MethodSelector Values

Value | Definition
---:|:---
"primary"|Indicates that the first available payment method should be used
Expand All @@ -76,24 +107,45 @@ Value | Definition
"all-backup"| Indicates that anything available other than the 1st (primary) should be used

### TimeDelayOrigin Values

Value| Definition
---:|:---
"initialisation"|Indicates that the time is based from the initialisation of the charge
"last-failure"|Indicates that the time is based from the last transaction failure

### TimeDelaySync Values
Value| Definition
---:|:---
"None"|will ignore the TimeSyncHour value
"Earliest"|will run the transaction at the earliest sync hour relative to TimeSync
"Latest"|will run the transaction at the latest sync hour relative to TimeSync
"Closest"|will run the transaction at the closest sync hour relative to TimeSync

Value | Definition
-----------:|:--------------------------
"None" |will ignore the TimeSyncHour value
"Earliest" |will run the transaction at the earliest sync hour relative to TimeSync
"Latest" |will run the transaction at the latest sync hour relative to TimeSync
"Closest" |will run the transaction at the closest sync hour relative to TimeSync

### TimeSyncZone Values
Value| Definition
---:|:---
"ULT"|Users Local Time
"UTC"|Universal Time Coordinated

Value | Definition
------:|:---------------------------
"ULT" | Users Local Time
"UTC" | Universal Time Coordinated

### Day Of Month

Value | Definition
------:|:------------------------
1-28 | Day of the month to run

### Day Of Week

Value | Definition
------:|:-----------
1 | Monday
2 | Tuesday
3 | Wednesday
4 | Thursday
5 | Friday
6 | Saturday
7 | Sunday

## Full Example

Expand Down
6 changes: 6 additions & 0 deletions v1/scheduler/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ type Schedule struct {

// TimeSyncZone indicates the timezone that the TimeSyncHour is relative to. Ignored if TimeDelaySync is set to None
TimeSyncZone TimeZone `json:"timeSyncZone" yaml:"timeSyncZone" validate:"oneof=ULT UTC CIT"`

// DayOfMonth is the day of the month to process the schedule
DayOfMonth int `json:"dayOfMonth" yaml:"dayOfMonth" validate:"min=0,max=28"`

// DayOfWeek is the day of the week to process the schedule (1 = Monday) - Sunday moved to 7 to leave 0 as an ignored value
DayOfWeek int `json:"dayOfWeek" yaml:"dayOfWeek" validate:"min=0,max=7"`
}

0 comments on commit 6f5395d

Please sign in to comment.