Commit 64c9ca7a authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

schedule worker and redis waiting for shutdown

parent 9f84583c
FROM redis:6
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint-mg.sh
ENTRYPOINT [ "docker-entrypoint-mg.sh" ]
CMD ["redis-server"]
\ No newline at end of file
#!/bin/bash
_term() {
echo -n "Waiting for clients to disconnect before stopping"
while [ "$(redis-cli info clients | grep "connected_clients" | cut -d ":" -f 2 | tr -dc '0-9')" -gt 1 ];
do
echo -n "."
sleep 1;
done
echo ""
echo "Stopping Redis Server with PID $REDIS_PID"
kill -s SIGKILL $REDIS_PID
exit 1
}
trap _term SIGTERM
echo "Starting Redis Server"
docker-entrypoint.sh "$@" &
REDIS_PID=$!
wait
\ No newline at end of file
......@@ -37,7 +37,7 @@ services:
<<: *fpm_build
restart: unless-stopped
entrypoint: /usr/local/bin/php
command: artisan schedule:work
command: artisan schedule:work-mg
volumes:
- ./metager:/metager/metager_app
healthcheck:
......@@ -82,7 +82,8 @@ services:
- ./metager:/home/node/metager
- node_cache:/home/node/.npm
redis:
image: redis:6
build:
context: ./build/redis
restart: unless-stopped
user: "redis:redis"
healthcheck:
......
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ScheduleWorker extends Command
{
private $should_exit = false;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'schedule:work-mg';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Starts the schedule worker with correct signal handling and graceful shutdown.';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
pcntl_signal(SIGQUIT, array(&$this, "onExit"));
$this->info("Starting Scheduler");
$this->call('schedule:run');
do {
sleep(60);
$this->call('schedule:run');
} while (!$this->should_exit);
return 0;
}
public function onExit()
{
$this->info("Stopping Scheduler on SIGQUIT");
$this->should_exit = true;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment