forked from mattermost-community/focalboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial telemetry code, system_settings table and the task scheduler
- Loading branch information
Showing
16 changed files
with
551 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,77 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
package scheduler | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type TaskFunc func() | ||
|
||
type ScheduledTask struct { | ||
Name string `json:"name"` | ||
Interval time.Duration `json:"interval"` | ||
Recurring bool `json:"recurring"` | ||
function func() | ||
cancel chan struct{} | ||
cancelled chan struct{} | ||
} | ||
|
||
func CreateTask(name string, function TaskFunc, timeToExecution time.Duration) *ScheduledTask { | ||
return createTask(name, function, timeToExecution, false) | ||
} | ||
|
||
func CreateRecurringTask(name string, function TaskFunc, interval time.Duration) *ScheduledTask { | ||
return createTask(name, function, interval, true) | ||
} | ||
|
||
func createTask(name string, function TaskFunc, interval time.Duration, recurring bool) *ScheduledTask { | ||
task := &ScheduledTask{ | ||
Name: name, | ||
Interval: interval, | ||
Recurring: recurring, | ||
function: function, | ||
cancel: make(chan struct{}), | ||
cancelled: make(chan struct{}), | ||
} | ||
|
||
go func() { | ||
defer close(task.cancelled) | ||
|
||
ticker := time.NewTicker(interval) | ||
defer func() { | ||
ticker.Stop() | ||
}() | ||
|
||
for { | ||
select { | ||
case <-ticker.C: | ||
function() | ||
case <-task.cancel: | ||
return | ||
} | ||
|
||
if !task.Recurring { | ||
break | ||
} | ||
} | ||
}() | ||
|
||
return task | ||
} | ||
|
||
func (task *ScheduledTask) Cancel() { | ||
close(task.cancel) | ||
<-task.cancelled | ||
} | ||
|
||
func (task *ScheduledTask) String() string { | ||
return fmt.Sprintf( | ||
"%s\nInterval: %s\nRecurring: %t\n", | ||
task.Name, | ||
task.Interval.String(), | ||
task.Recurring, | ||
) | ||
} |
This file contains 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
1 change: 1 addition & 0 deletions
1
...r/services/store/sqlstore/migrations/postgres_files/000002_system_settings_table.down.sql
This file contains 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 @@ | ||
DROP TABLE system_settings; |
5 changes: 5 additions & 0 deletions
5
server/services/store/sqlstore/migrations/postgres_files/000002_system_settings_table.up.sql
This file contains 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,5 @@ | ||
CREATE TABLE IF NOT EXISTS system_settings ( | ||
id VARCHAR(100), | ||
value TEXT, | ||
PRIMARY KEY (id) | ||
); |
Oops, something went wrong.