hotreload

package module
v0.0.0-...-d95f199 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2019 License: MIT Imports: 8 Imported by: 0

README

RoadRunner Hot Reload

Allow to automatically reload workers on file change.

Installation

QuickBuild

Add to .build.json package github.com/UPDG/roadrunner-hotreload and register it as rr.Container.Register(hotreload.ID, &hotreload.Service{})

After it build RR using QuickBuild.

Example of final file:

{
  "packages": [
    "github.com/spiral/roadrunner/service/env",
    "github.com/spiral/roadrunner/service/http",
    "github.com/spiral/roadrunner/service/rpc",
    "github.com/spiral/roadrunner/service/static",
    "github.com/UPDG/roadrunner-hotreload"
  ],
  "commands": [
    "github.com/spiral/roadrunner/cmd/rr/http"
  ],
  "register": [
    "rr.Container.Register(env.ID, &env.Service{})",
    "rr.Container.Register(rpc.ID, &rpc.Service{})",
    "rr.Container.Register(http.ID, &http.Service{})",
    "rr.Container.Register(static.ID, &static.Service{})",
    "rr.Container.Register(hotreload.ID, &hotreload.Service{})"
  ]
}
Manual
  1. Add dependency by running go get github.com/UPDG/roadrunner-hotreload

  2. Add to cms/rr/main.go import github.com/UPDG/roadrunner-hotreload

  3. Add to cms/rr/main.go line rr.Container.Register(hotreload.ID, &hotreload.Service{}) after rr.Container.Register(http.ID, &http.Service{})

Final file should look like this:

package main

import (
	"github.com/sirupsen/logrus"
	rr "github.com/spiral/roadrunner/cmd/rr/cmd"

	// services (plugins)
	"github.com/spiral/roadrunner/service/env"
	"github.com/spiral/roadrunner/service/http"
	"github.com/spiral/roadrunner/service/rpc"
	"github.com/spiral/roadrunner/service/static"
	"github.com/UPDG/roadrunner-hotreload"

	// additional commands and debug handlers
	_ "github.com/spiral/roadrunner/cmd/rr/http"
)

func main() {
	rr.Container.Register(env.ID, &env.Service{})
	rr.Container.Register(rpc.ID, &rpc.Service{})
	rr.Container.Register(http.ID, &http.Service{})
	rr.Container.Register(static.ID, &static.Service{})
	rr.Container.Register(hotreload.ID, &hotreload.Service{})

	rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true}

	// you can register additional commands using cmd.CLI
	rr.Execute()
}

Configuration

Add your RoadRunner config (.rr.yaml by default) this lines:

hotreload:
  # Enable or disable plugin
  enable: true
  
  # Path where to scan changed. Current directory by default.
  path: .
  
  # File mask to filter changes. *.php by default. Ref. to https://golang.org/pkg/path/filepath/#Match for available masks.
  files: "*.php"
  
  # Times in milliseconds between file checks. 500 (0.5 sec) by default.
  tick: 500

Documentation

Index

Constants

View Source
const ID = "hotreload"

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enable bool
	Paths  []string
	Files  string
	Tick   *time.Duration
}

func (*Config) Hydrate

func (c *Config) Hydrate(cfg service.Config) error

Hydrate must populate Config values using given Config source. Must return error if Config is not valid.

type Service

type Service struct {
}

func (*Service) Init

func (s *Service) Init(config *Config) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL