daycry / cronjob Goto Github PK
View Code? Open in Web Editor NEW- Manage Cron jobs in Codeigniter 4
License: MIT License
- Manage Cron jobs in Codeigniter 4
License: MIT License
Hello there,
I've been using your package for the past few months and everything was great, till my (shared) hosting decided to mess around with my website and changed something. Since then cron jobs have not executing. If I try to manually run the command in cli, everything works.
So I have this setup:
cronjobs are enabled;
In app\Config\CronJob.php
-> init
method:
$schedule->shell("cd /home/sitename/domains/sitename/public_html/ && /usr/local/bin/php index.php Notification sendBulkNotifications")->named('not_send_notifications')->everyMinute(3);
I have this cronjob running every minute (* * * * *)
cd /home/sitename/domains/sitename && /usr/local/bin/php spark cronjob:run
In the DB table called cronjob
I have scheduled not_send_notifications
to run and has a history of being called and a time in the future that it will be called.
In Notification->sendBulkNotifications
I'm sending an email to confirm that the method is being called. But it's never been called.
If I run this command in terminal cd /home/sitename/domains/sitename/public_html/ && /usr/local/bin/php index.php Notification sendBulkNotifications
- the method is being called and I receive an email.
If I put this same command as a cronjob to be executed every minute (* * * * *), it is being executed successfully.
If I manually run php spark cronjob:run
- nothing happens.
If I manually run php spark cronjob:list
- I get a list of all cron jobs, including not_send_notifications
I had the same setup before my hosting's support messed around and everything was perfect. What went wrong?
Hi, I get an error saying: array_key_exists(): Argument #2 ($array) must be of type array, null given
VENDORPATH/daycry/cronjob/src/Traits/LogTrait.php at line 88:
if(!setting('CronJob.logSavingMethod') || !array_key_exists(setting('CronJob.logSavingMethod'), setting('CronJob.logSavingMethodClassMap'))) {
throw CronJobException::forInvalidLogType();
}
It seems like setting('CronJob.logSavingMethodClassMap') is not defined properly. Any tips?
I have the following tasks:
+------------------+---------+--------------+----------+---------------------+
| Name | Type | Expression | Last Run | Next Run |
+------------------+---------+--------------+----------+---------------------+
| set_data_to_main | command | */5 * * * * | -- | 2024-03-22 10:30:00 |
| collect_status | command | */10 * * * * | -- | 2024-03-22 10:30:00 |
or like in this other case
+------------------+---------+--------------+---------------------+---------------------+
| Name | Type | Expression | Last Run | Next Run |
+------------------+---------+--------------+---------------------+---------------------+
| set_data_to_main | command | */4 * * * * | 2024-03-22 10:56:01 | 2024-03-22 11:00:00 |
| collect_status | command | */11 * * * * | 2024-03-22 10:45:01 | 2024-03-22 11:00:00 |
The issue occurring is that the task that runs every 5 minutes is not triggered when the minutes end with 0 (or in coinciding minutes) as in the example above.
In the example case, only the collect_status task runs, and the set_data_to_main task does not run.
The set_data_to_main task is only running at minutes ending with 5 (05, 15, 25, 35, ...).
The collect_status task takes between 4 to 9 minutes to complete.
If the collect_status task is running and the set_data_to_main task is called, it runs normally as long as the two do not coincidentally start in the same minute.
Is there any way to use this package with Codeigniter 3?
Hello,
I would like use your library with logging of jobs in database. I saw that you are doing some updates of code. Why are you integrated settings library in workflow. I already using table settings and I don't want to replace that table. I would like to migrate only table cronjob to save logs there. I believe that better will be to split those two libraries and maintain logic in backend of the app for deployment etc.
Thank you.
Hello! After the latest upgrade I'm getting the followin while trying to access the logs (gear icon):
Call to a member function getLogs() on null
VENDORPATH/daycry/cronjob/src/Traits/LogTrait.php at line 64
return $this->handler->getLogs($this->name);
Also I cannot run my migrations anymore:
php spark migrate --all
[CodeIgniter\Database\Exceptions\DatabaseException]
Duplicate column name 'context'
at SYSTEMPATH/Database/BaseConnection.php:647
Because I'm using CI 4.4.6 settings package (required by shield) and it has a AddContextColumn
migration class that adds this context
column already.
Also, what public string $papa = 'file';
means in the new config file?
TIA.
When run cronjob:run :(
**** Running Tasks... ****
[ErrorException]
Undefined array key "CI_ENVIRONMENT"
at VENDORPATH/daycry/cronjob/src/Traits/ActivityTrait.php:28
After executing the following command
php spark cronjob:publish
I am getting following error
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function Daycry\CronJob\Commands\directory_mirror()
Filename: E:\dev\xampp7_new\htdocs\ci\vendor\daycry\cronjob\src\Commands\Assets.php
Line Number: 57
Kindly tell me how to fix this.
Hi,
All is working perfectly but I can't see jobs list on dashboard page.
When I go to the dashboard page, i've got an error : "Cannot access protected property Daycry\CronJob\Job::$name"
VENDORPATH\daycry\cronjob\src\Views\dashboard.php at line 28
<td><?= $job->name ?></td>
If I delete all $job->name in the view, it's working. The error seems be related to the variable "name".
My install is up to date with composer.
Thank you for your help !
I followed your steps, namely:
Downloaded and unzip to ThirdParty/
the psr4 added:
'Daycry\CronJob' => APPPATH .'ThirdParty/cronjob/src'
But I get error when i run this command:
php spark cronjob:list
Class 'Cron\CronExpression' not found
Run url
$schedule->url(base_url('cron/update-sitemap'))->everyMinute();
Log Terminal :
**** Running Tasks... ****
[2022-10-13 20:43:59] Processing: url_9a7e661ea4c1c0bd748711cf68bffce7
[2022-10-13 20:44:00] Failed: url_9a7e661ea4c1c0bd748711cf68bffce7
**** Completed ****
Log :
{
"name": "url_9a7e661ea4c1c0bd748711cf68bffce7",
"type": "url",
"action": "https:\/\/domain.test\/cron\/update-sitemap",
"environment": "[]",
"start_at": "2022-10-13 20:34:26",
"end_at": "2022-10-13 20:34:27",
"duration": "00:00:00",
"output": null,
"error": "{}",
"test_time": null
}
Command cronjob:list
log from CLI :
[Error]
Typed property Daycry\CronJob\Job::$name must not be accessed before initialization
at VENDORPATH\daycry\cronjob\src\Job.php:172
Backtrace:
1 VENDORPATH\daycry\cronjob\src\Commands\Lister.php:60
Daycry\CronJob\Job()->lastRun()
2 SYSTEMPATH\CLI\Commands.php:63
Daycry\CronJob\Commands\Lister()->run([])
3 SYSTEMPATH\CLI\CommandRunner.php:65
CodeIgniter\CLI\Commands()->run('cronjob:list', [])
4 SYSTEMPATH\CLI\CommandRunner.php:51
CodeIgniter\CLI\CommandRunner()->index([])
5 SYSTEMPATH\CodeIgniter.php:895
CodeIgniter\CLI\CommandRunner()->_remap('index', [...])
6 SYSTEMPATH\CodeIgniter.php:457
CodeIgniter\CodeIgniter()->runController(Object(CodeIgniter\CLI\CommandRunner))
7 SYSTEMPATH\CodeIgniter.php:336
CodeIgniter\CodeIgniter()->handleRequest(null, Object(Config\Cache), false)
8 SYSTEMPATH\CLI\Console.php:48
CodeIgniter\CodeIgniter()->run()
9 ROOTPATH\spark:98
CodeIgniter\CLI\Console()->run()
Hey,
Thank you for this awesome package, I love it!
Is there a possibility to add the ability to vednor publish the View files? I'd like to be able to edit them. I'd like to put a button there to disable all cron jobs, just in case (I was having problems with sending bulk emails, and the script was stuck and was sending the same email over and over again to the same people. I'd like to have some GUI where I could stop this from my phone while I'm out).
Also, it would be very helpful if I could protect the dashboard to be accessible only by Admin users.
EDIT:
I figure it out. It's just not described in the Readme file. For everybody else encountering this issue:
Go to app\Config\CronJob.php ->views['dashboard'] and put your view's path there, like: "Cronjob/dashboard" - which is located in app\Views\Cronjob\dashboard.php
EDIT2:
nvm, I found a way to overrule the dashboard.
$routes->get('cronjob/dashboard', [\Daycry\CronJob\Controllers\Dashboard::class, 'index'], ['filter' => 'your_filter_where_you_could_stop_the_request']);
Some output contains characters which result into MySQL errors:
[mysqli_sql_exception] Operand should contain 1 column(s)
I have this issue when I try to insert the shell output of php -v
I figured out that I can solve it by wrapping the output in a json_encode.
app\ThirdParty\vendor\daycry\cronjob\src\JobRunner.php
line 187
**** Running Tasks... ****
2023-04-03 12:00:00[2023-05-03 12:44:40] Processing: Daily
[2023-05-03 12:44:40] Executed: Daily
[mysqli_sql_exception]
Operand should contain 1 column(s)
at SYSTEMPATH\Database\MySQLi\Connection.php:295
Backtrace:
1 SYSTEMPATH\Database\MySQLi\Connection.php:295
mysqli()->query('INSERT INTO task_scheduler_logs
(name
, type
, action
, environment
, start_at
, end_at
, duration
, output
, error
, test_time
, created_at
, updated_at
) VALUES ('Daily', 'shell', 'php -v', '[]', '2023-05-03 12:44:40', '2023-05-03 12:44:40', '00:00:00', ('PHP 8.0.12 (cli) (built: Oct 19 2021 11:21:05) ( ZTS Visual C++ 2019 x64 )','Copyright (c) The PHP Group','Zend Engine v4.0.12, Copyright (c) Zend Technologies'), 'null', '2023-04-01 17:25:00', '2023-05-03 12:44:40', '2023-05-03 12:44:40')', 0)
2 SYSTEMPATH\Database\BaseConnection.php:692
CodeIgniter\Database\MySQLi\Connection()->execute('INSERT INTO task_scheduler_logs
(name
, type
, action
, environment
, start_at
, end_at
, duration
, output
, error
, test_time
, created_at
, updated_at
) VALUES ('Daily', 'shell', 'php -v', '[]', '2023-05-03 12:44:40', '2023-05-03 12:44:40', '00:00:00', ('PHP 8.0.12 (cli) (built: Oct 19 2021 11:21:05) ( ZTS Visual C++ 2019 x64 )','Copyright (c) The PHP Group','Zend Engine v4.0.12, Copyright (c) Zend Technologies'), 'null', '2023-04-01 17:25:00', '2023-05-03 12:44:40', '2023-05-03 12:44:40')')
3 SYSTEMPATH\Database\BaseConnection.php:606
CodeIgniter\Database\BaseConnection()->simpleQuery('INSERT INTO task_scheduler_logs
(name
, type
, action
, environment
, start_at
, end_at
, duration
, output
, error
, test_time
, created_at
, updated_at
) VALUES ('Daily', 'shell', 'php -v', '[]', '2023-05-03 12:44:40', '2023-05-03 12:44:40', '00:00:00', ('PHP 8.0.12 (cli) (built: Oct 19 2021 11:21:05) ( ZTS Visual C++ 2019 x64 )','Copyright (c) The PHP Group','Zend Engine v4.0.12, Copyright (c) Zend Technologies'), 'null', '2023-04-01 17:25:00', '2023-05-03 12:44:40', '2023-05-03 12:44:40')')
4 SYSTEMPATH\Database\BaseBuilder.php:2309
CodeIgniter\Database\BaseConnection()->query('INSERT INTO task_scheduler_logs
(name
, type
, action
, environment
, start_at
, end_at
, duration
, output
, error
, test_time
, created_at
, updated_at
) VALUES (:name:, :type:, :action:, :environment:, :start_at:, :end_at:, :duration:, :output:, :error:, :test_time:, :created_at:, :updated_at:)', [...], false)
5 SYSTEMPATH\Model.php:330
CodeIgniter\Database\BaseBuilder()->insert()
6 SYSTEMPATH\BaseModel.php:782
CodeIgniter\Model()->doInsert([...])
7 SYSTEMPATH\Model.php:730
CodeIgniter\BaseModel()->insert([...], true)
8 APPPATH\ThirdParty\vendor\daycry\cronjob\src\JobRunner.php:207
CodeIgniter\Model()->insert([...])
9 APPPATH\ThirdParty\vendor\daycry\cronjob\src\JobRunner.php:99
Daycry\CronJob\JobRunner()->storePerformanceLog(Object(Daycry\CronJob\JobLog))
10 APPPATH\ThirdParty\vendor\daycry\cronjob\src\Commands\Run.php:80
Daycry\CronJob\JobRunner()->run()
11 SYSTEMPATH\CLI\Commands.php:65
Daycry\CronJob\Commands\Run()->run([...])
12 SYSTEMPATH\CLI\Console.php:37
CodeIgniter\CLI\Commands()->run('cronjob:run', [...])
13 ROOTPATH\spark:97
CodeIgniter\CLI\Console()->run()
Hi,
Since yesterday i've been working with Postgresql on DigitalOcean's App platform, when running the migration command it seems to fail.
Database
Postgresql
Error
Attempt to read property "databaseGroup" on null
When
Running the command php spark migrate -all
I'm trying to run the "cronjob:run" command but I'm getting this error.
The helper is probably not being called correctly.
Is anyone else having the same problem?
I got this error, when access the dashboard:
Error
Call to undefined function Daycry\CronJob\Traits\setting()
VENDORPATH/daycry/cronjob/src/Traits/ActivityTrait.php at line 46
Until, last week it was working, but starts to show this error, now.
Hi,
I've definied in cronjob.php enable dashboard true. but when I try access domain.com/cronjob I get 404. How to route this dashboard?
In your example you define:
->sundays('3:15 am') | Runs every Sunday at midnight, unless time passed in.
->mondays('3:15 am') | Runs every Monday at midnight, unless time passed in.
->tuesdays('3:15 am') | Runs every Tuesday at midnight, unless time passed in.
->wednesdays('3:15 am') | Runs every Wednesday at midnight, unless time passed in.
->thursdays('3:15 am') | Runs every Thursday at midnight, unless time passed in.
->fridays('3:15 am') | Runs every Friday at midnight, unless time passed in.
->saturdays('3:15 am') | Runs every Saturday at midnight, unless time passed in.
But when you call for example ->saturdays() without a time, it will not run at midnight, it will run every minute on saturday.
Clean Device Finder | shell | * * * * 6 | 2023-07-15 10:08:06 | 2023-07-15 10:09:00
Hello @daycry,
really nice work. I want to use your library. I did everything what was needed to get it run.
I have only one custom command to run. My command ran well but after that I got this errror in a log.
Can you help to solve what is a problem ?
Thank you.
CRITICAL - 2021-10-06 19:17:29 --> Call to a member function format() on null
#0 /var/www/codeigniter4/vendor/daycry/cronjob/src/Commands/Run.php(68): Daycry\CronJob\JobRunner->run()
#1 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CLI/Commands.php(63): Daycry\CronJob\Commands\Run->run()
#2 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CLI/CommandRunner.php(70): CodeIgniter\CLI\Commands->run()
#3 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CLI/CommandRunner.php(56): CodeIgniter\CLI\CommandRunner->index()
#4 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CodeIgniter.php(800): CodeIgniter\CLI\CommandRunner->_remap()
#5 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CodeIgniter.php(399): CodeIgniter\CodeIgniter->runController()
#6 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CodeIgniter.php(317): CodeIgniter\CodeIgniter->handleRequest()
#7 /var/www/codeigniter4/vendor/codeigniter4/framework/system/CLI/Console.php(48): CodeIgniter\CodeIgniter->run()
#8 /var/www/codeigniter4/spark(63): CodeIgniter\CLI\Console->run()
#9 {main}
In your example you define the cronjob as follows:
I tried to implement this in a docker project where the docker was running Debian.
Unfortunately Debian didn't accept a cd with a command after it, what did work for me was the following:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.