Coder Social home page Coder Social logo

watchdogbundle's Introduction

WatchdogBundle

Workflow codecov SymfonyInsight Mutation testing badge Type coverage psalm phpstan

A widget bundle providing a watchdog which "woofs" if current time matches provided configuration.

Installation

composer require raneomik/watchdog-bundle

if not using symfony/flex, you need de register the bundle in your project :

// config/bundles.php

return [
    Raneomik\WatchdogBundle\WatchdogBundle::class => ['all' => true],
];

Configuration

It can be configured as follows:

#config/packages/watchdog.yml

watchdog:
   default: # raise an event if current date time matches (following "Or" logic)
   - date_time: '2019-12-01 11:00'           # a date and time
   - date: '2019-12-03'                      # a specific date
   - hour: '14:00'                           # a specific hour            
   - time: '14:15'                           # or time      
   - { start: '2019-12-01', end: '2019-12-31' }  # an interval of dates
   - { start: '10:00', end: '11:00' }        # or of times      
   - relative: 'first wednesday of'          # a relative format*
   - compound:                               # or a composite of the rules above, following "And" logic, for example :
     - relative: 'monday'                    # "On mondays"
     - { start: '20:00', end: '22:30' }      # "and between 20:00 and 22:30"
   
   maintenance: # define another watchdogs, independent of each other.
   - compound:
     - relative: 'sundays' 
     - { start: '05:00', end: '06:00' }

* relative format

Watchdog service

This bundle provides the Raneomik\WatchdogBundle\Watchdog\WatchdogInterface service that can be injected anywhere. It has a isWoofTime method returning true once configuration matches current date time. If several ones are defined, they can be injected as follows (based on the example above) :

use Raneomik\WatchdogBundle\Watchdog\WatchdogInterface;

class Service
{
    __construct(
        private WatchdogInterface $default,
        private WatchdogInterface $maintenance
    ) {
    }
....

WatchdogHandlerInterface and WatchdogWoofCheckEvent

This bundle also provides the Raneomik\WatchdogBundle\Handler\WatchdogHandlerInterface interface with processWoof(array $parameters = []) method, for more complex processes. It works with the WatchdogEventSubscriber subscribed to WatchdogWoofCheckEvent.

Anywhere you wish to check if it isWoofTime, dispatch a new WatchdogWoofCheckEvent($parameters, $watchdogId), and if it isWoofTime, it will trigger all WatchdogHandlerInterfaces and their processWoof(array $parameters = []) // passed to the WatchdogWoofCheckEvent constructor.

$watchdogId is null by default, which results in all defined watchdogs check. If one is passed by this parameter, it checks only the concerned one.

If you wish to use it but your project isn't set to be autoconfigured, all your Handlers implementing WatchdogHandlerInterface must be tagged with raneomik_watchdog.handler.

WIP: Profiler data collection

You can access watchdog data in Symfony profiler :

profiler.png

License

watchdogbundle's People

Contributors

raneomik avatar

Watchers

 avatar  avatar  avatar

watchdogbundle's Issues

Scoping Watchdog service & default unique one support

Currently, it supports a unique default watchdog config, under dates config key.

It would be nice if applications could embed, if needed, dynamicaly named Watchdog like this :

for example, giving this configuration :

watchdog:
    maintance: 
    - { relative: 'mondays' }
    weekend:
    - compound : 
        - { relative: 'saturdays' }
        - { relative: 'sundays' }

it should provide those Watchdog services :

class Service
{
     __construct(
        private Watchdog $maintenanceWatchdog,
        private Watchdog $weekendWatchdog
    ) {
   }
....

where each of those watchdogs have their independent time configuration.

Needs adaptations on provided handler & the handling subscriber.

Occasionnaly, make a WatchdogInterface to impose method signatures & leverage code coupling (and then permitting fakes / dummies / stubs / own logics).

Also, maybe flexibilise the config to support a unique defautlt wathdog as follows :

watchdog:
    - { relative: 'mondays' }

providing this unique service :

class Service
{
     __construct(
        private WatchdogInterface $watchdog
    ) {
   }
....

Cannot debug bundle configuration

Launching this command :

~$: symfony console debug:config WatchdogBundle

Outputs this error :

In AbstractConfigCommand.php line 115:
                                                                                          
  The extension with alias "watchdog" does not have its getConfiguration() method setup.  

non-existent Watchdog service definition

On composer update of a SF 4.4 project, we have this error :

 [KO]
Script cache:clear returned with error code 1
!!  
!!  In ContainerBuilder.php line 996:
!!                                                                                 
!!    You have requested a non-existent service "Raneomik\WatchdogBundle\Watchdog\Watchdog".                                                                  
!!                                                                                 
!!  
!!  
Script @auto-scripts was called via post-update-cmd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.