Skip to content
/ crony Public

Lightweight cron replacement that calls URL.

Notifications You must be signed in to change notification settings

formapro/crony

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crony

Lightweight cron replacement that calls URL

Usage

Config

{
  "tasks": [
    {
      "cron": "@every 1m",
      "url": "http://app/task"
    }
  ]
}

Docker

services:
  app:
    
  cron:
    image: 'formapro/crony:latest'
    depends_on:
      - app
    volumes:
      - './crony.json:/app/crony.json'

Symfony

Route:

#config/routes.yaml

cron_task:
  path: '/cron/task/foo'
  controller: 'App\Controller\CronTaskController::foo'
  methods: [POST]

Controller:

<?php declare(strict_types=1);

namespace App\Controller;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class CronTaskController implements EventSubscriberInterface
{
    public function foo(Request $request): Response
    {
        $request->attributes->set('task', 'foo');

        return new Response();
    }

    public function onTerminate(PostResponseEvent $event): void
    {
        if ('foo' !== $event->getRequest()->attributes->get('task')) {
            return;
        }

        // do task
    }

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::TERMINATE => 'onTerminate',
        ];
    }
}

License

MIT

About

Lightweight cron replacement that calls URL.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published