Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cron control #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions admin/class-apisunat-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,18 +475,10 @@ public function apisunat_custom_orders_list_column_content(string $column, strin
*/
public function apisunat_check_status_on_schedule(): void
{
$is_running = get_transient('apisunat_one_minute_event');

if (get_option('apisunat_forma_envio') === 'auto' && get_option('apisunat_cron_running') === 'false') {


if (get_option('apisunat_forma_envio') === 'auto') {

if ($is_running) {
// El cron ya está en ejecución, no hagas nada.
return;
}

// Establecer el transitorio para bloquear la ejecución del cron
set_transient('apisunat_one_minute_event', true, 600); // 600 segundos (10 minutos)
update_option('apisunat_cron_running', 'true');

if (!get_option('apisunat_fecha')) {
update_option('apisunat_fecha', current_time('mysql'));
Expand Down Expand Up @@ -543,7 +535,7 @@ public function apisunat_check_status_on_schedule(): void
}
}
}
delete_transient('apisunat_one_minute_event');
update_option('apisunat_cron_running', 'false');
}

/**
Expand Down Expand Up @@ -1261,11 +1253,20 @@ public function apisunat_display_data(): void
echo '<hr>';
echo '<h3>Configuración</h3>';

$cron_runnig = get_option('apisunat_cron_runnig');
if ($cron_runnig) {
$text = $cron_runnig === 'true' ? "RUNNING" : "STOPPED";
echo '<small>CRON STATUS: ' . $text . '</small>';
echo '<br>';
}

$ultimo_cambio = get_option('apisunat_fecha');
if ($ultimo_cambio) {
$fecha_formateada = date('d/m/Y H:i:s', strtotime($ultimo_cambio));
echo '<small>El último cambio a automático se realizó el: ' . $fecha_formateada . '</small>';
}


}

/**
Expand Down
3 changes: 3 additions & 0 deletions includes/class-apisunat-activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public static function activate(): void {
if ( ! wp_next_scheduled( 'apisunat_one_minute_event' ) ) {
wp_schedule_event( time(), 'apisunat_every_one_minute', 'apisunat_one_minute_event' );
}

add_option('apisunat_cron_runnig');
update_option('apisunat_cron_runnig', 'false');
}
}