Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package host
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
)
|
|
|
|
|
|
|
|
type task struct {
|
|
|
|
runner TaskRunner
|
|
|
|
proc TaskProcess
|
|
|
|
|
|
|
|
// atomic-accessed, if != 0 means that is already
|
|
|
|
// canceled before it ever ran, this happens to interrupt handlers too.
|
|
|
|
alreadyCanceled int32
|
|
|
|
Cancel func()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *task) isCanceled() bool {
|
|
|
|
return atomic.LoadInt32(&t.alreadyCanceled) != 0
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// Scheduler is a type of an event emmiter.
|
|
|
|
// Can register a specific task for a specific event
|
|
|
|
// when host is starting the server or host is interrupted by CTRL+C/CMD+C.
|
|
|
|
// It's being used internally on host supervisor.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
type Scheduler struct {
|
|
|
|
onServeTasks []*task
|
|
|
|
onInterruptTasks []*task
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// TaskCancelFunc cancels a Task when called.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
type TaskCancelFunc func()
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// Schedule schedule/registers a Task,
|
|
|
|
// it will be executed/run to when host starts the server
|
|
|
|
// or when host is interrupted by CTRL+C/CMD+C based on the TaskRunner type.
|
|
|
|
//
|
|
|
|
// See `OnInterrupt` and `ScheduleFunc` too.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func (s *Scheduler) Schedule(runner TaskRunner) TaskCancelFunc {
|
|
|
|
|
|
|
|
t := new(task)
|
|
|
|
t.runner = runner
|
|
|
|
t.Cancel = func() {
|
|
|
|
// it's not running yet, so if canceled now
|
|
|
|
// set to already canceled to not run it at all.
|
|
|
|
atomic.StoreInt32(&t.alreadyCanceled, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := runner.(OnInterrupt); ok {
|
|
|
|
s.onInterruptTasks = append(s.onInterruptTasks, t)
|
|
|
|
} else {
|
|
|
|
s.onServeTasks = append(s.onServeTasks, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
return func() {
|
|
|
|
t.Cancel()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// ScheduleFunc schedule/registers a task function,
|
|
|
|
// it will be executed/run to when host starts the server
|
|
|
|
// or when host is interrupted by CTRL+C/CMD+C based on the TaskRunner type.
|
|
|
|
//
|
|
|
|
// See `OnInterrupt` and `ScheduleFunc` too.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func (s *Scheduler) ScheduleFunc(runner func(TaskProcess)) TaskCancelFunc {
|
|
|
|
return s.Schedule(TaskRunnerFunc(runner))
|
|
|
|
}
|
|
|
|
|
|
|
|
func cancelTasks(tasks []*task) {
|
|
|
|
for _, t := range tasks {
|
|
|
|
if atomic.LoadInt32(&t.alreadyCanceled) != 0 {
|
|
|
|
continue // canceled, don't run it
|
|
|
|
}
|
|
|
|
go t.Cancel()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// CancelOnServeTasks cancels all tasks that are scheduled to run when
|
|
|
|
// host is starting the server, when the server is alive and online.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func (s *Scheduler) CancelOnServeTasks() {
|
|
|
|
cancelTasks(s.onServeTasks)
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// CancelOnInterruptTasks cancels all tasks that are scheduled to run when
|
|
|
|
// host is being interrupted by CTRL+C/CMD+C, when the server is alive and online as well.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func (s *Scheduler) CancelOnInterruptTasks() {
|
|
|
|
cancelTasks(s.onInterruptTasks)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runTaskNow(task *task, host TaskHost) {
|
|
|
|
proc := newTaskProcess(host)
|
|
|
|
task.proc = proc
|
|
|
|
task.Cancel = func() {
|
|
|
|
proc.canceledChan <- struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
go task.runner.Run(proc)
|
|
|
|
}
|
|
|
|
|
|
|
|
func runTasks(tasks []*task, host TaskHost) {
|
|
|
|
for _, t := range tasks {
|
|
|
|
if t.isCanceled() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
runTaskNow(t, host)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scheduler) runOnServe(host TaskHost) {
|
|
|
|
runTasks(s.onServeTasks, host)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scheduler) runOnInterrupt(host TaskHost) {
|
|
|
|
runTasks(s.onInterruptTasks, host)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scheduler) visit(visitor func(*task)) {
|
|
|
|
for _, t := range s.onServeTasks {
|
|
|
|
visitor(t)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, t := range s.onInterruptTasks {
|
|
|
|
visitor(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scheduler) notifyShutdown() {
|
|
|
|
s.visit(func(t *task) {
|
|
|
|
go func() {
|
|
|
|
t.proc.Host().doneChan <- struct{}{}
|
|
|
|
}()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Scheduler) notifyErr(err error) {
|
|
|
|
s.visit(func(t *task) {
|
|
|
|
go func() {
|
|
|
|
t.proc.Host().errChan <- err
|
|
|
|
}()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-10 02:31:50 +02:00
|
|
|
// CopyTo copies all tasks from "s" to "to" Scheduler.
|
|
|
|
// It doesn't care about anything else.
|
Publish the new version :airplane: | Look description please!
# FAQ
### Looking for free support?
http://support.iris-go.com
https://kataras.rocket.chat/channel/iris
### Looking for previous versions?
https://github.com/kataras/iris#version
### Should I upgrade my Iris?
Developers are not forced to upgrade if they don't really need it. Upgrade whenever you feel ready.
> Iris uses the [vendor directory](https://docs.google.com/document/d/1Bz5-UB7g2uPBdOx-rw5t9MxJwkfpx90cqG9AFL0JAYo) feature, so you get truly reproducible builds, as this method guards against upstream renames and deletes.
**How to upgrade**: Open your command-line and execute this command: `go get -u github.com/kataras/iris`.
For further installation support, please click [here](http://support.iris-go.com/d/16-how-to-install-iris-web-framework).
### About our new home page
http://iris-go.com
Thanks to [Santosh Anand](https://github.com/santoshanand) the http://iris-go.com has been upgraded and it's really awesome!
[Santosh](https://github.com/santoshanand) is a freelancer, he has a great knowledge of nodejs and express js, Android, iOS, React Native, Vue.js etc, if you need a developer to find or create a solution for your problem or task, please contact with him.
The amount of the next two or three donations you'll send they will be immediately transferred to his own account balance, so be generous please!
Read more at https://github.com/kataras/iris/blob/master/HISTORY.md
Former-commit-id: eec2d71bbe011d6b48d2526eb25919e36e5ad94e
2017-06-03 22:22:52 +02:00
|
|
|
func (s *Scheduler) CopyTo(to *Scheduler) {
|
|
|
|
s.visit(func(t *task) {
|
|
|
|
rnner := t.runner
|
|
|
|
to.Schedule(rnner)
|
|
|
|
})
|
|
|
|
}
|