<?php

declare(strict_types=1);

define(
'BASE_PATH',
'/var/www/html/easychair'
);

/*
bootstrap
*/

require_once
BASE_PATH
.
'/vendor/autoload.php';

require_once
BASE_PATH
.
'/app/core/Database.php';

use App\Core\Database;

$db=
Database::getInstance();

/*
fetch jobs
*/

$stmt=
$db
->query("

SELECT *

FROM
conference_home_schedule

WHERE

job_status='scheduled'

AND

execute_at<=NOW()

ORDER BY id

LIMIT 10

");

$jobs=
$stmt
->fetchAll(
PDO::FETCH_ASSOC
);

foreach(
$jobs
as $job
){

$db
->prepare("

UPDATE
conference_home_schedule

SET

job_status='running'

WHERE id=?

")

->execute([

$job['id']

]);

sleep(
1
);

$db
->prepare("

UPDATE
conference_home_schedule

SET

job_status='done',

result_json=

JSON_OBJECT(

'completed',

NOW()

)

WHERE id=?

")

->execute([

$job['id']

]);

echo
"Processed: "
.
$job['id']
.
PHP_EOL;

}

echo
"Worker finished"
.
PHP_EOL;
