Laravel php artisan queue work and stop if jobs are empty - laravel-7

How to execute php artisan queue:work --stop-when-empty inside controller i tried to call it inside php artisan like below
$execute = artisan::call('php artisan queue:work --stop-when-empty');
But nothing happened, can you kindly help

\Artisan::call('queue:work --stop-when-empty');
It can be called anywhere in the Class. Like if you want to start the queue working and want it would stop whenever the queue's empty then you can use this. I would prefer you to use the queue: work in scheduler instead of calling directly. Like this.
protected function schedule(Schedule $schedule)
{
$schedule->command('queue:work --stop-when-empty')->everyMinute();
}

Related

How to get specific node PID in Node-Red?

I am using Node-Red V2.2.2. I would like to restart an specific node of the flow after an error is triggered in it.
I have managed to restart the full flow getting node-red process id. After modifying: settings.js in my .node-red folder:
functionGlobalContext: {
// os:require('os'),
'pid': process.pid
},
I am able to get general process pid from a function node:
var General_pid = context.global.pid
And kill and restart the global process from an Exec node sending General_pid in msg.payload :
Being comando.sh:
#!/bin/bash
taskkill //PID $1 //F
sleep 4
node-red
But i am unable to do this with specific nodes inside the node-red flow.
Almost all info i have searched relied on Status node to get node specific pid,
but in my case, this is the Status node structure (no PID in there):
I have also tried to get PID based on status.source.id using:
RED.nodes.getNode(id);
But RED.nodes is undefined (altough RED is defined, but it only shows functions on print)
Any idea on how to be able to get the node PID to kill it and restart it? I could do it from an Exec node, but if there is an easier way even better.
You don't.
Nodes are not separate processes that can be restarted independently of Node-RED. (While some nodes may fork a new process, e.g. a python script, Node-RED has no access to this and it is all handled inside the node in question)
You have 2 choices:
You can trigger a restart of the deployed flow by making a HTTP call to the /flows Admin API with the header set to reload. Assuming the node with the failure is well written then it should restart cleanly.
Restart all of Node-RED as you are already

Laravel PHP queue:work not working on linux

I tried to use supervisor and this is my config:
Status
In my job table
Also the "tries=3" is not working and my worker.log is also null
The jobs in your table are in the 'default' queue, but you've told your workers to only process jobs from the 'jobs' queue.
In the supervisor config either remove --queue=jobs entirely, or change it to --queue=default

How do I view my sidekiq console output locally using the default queue?

I'm using Rails 5. I would like to create a sidekiq process running locally using the default queue. My worker class looks roughly like the below ...
module Accounting::Workers
class FileGenerationWorker
include Sidekiq::Worker
def perform
print "starting work ...\n"
...
I have set up my config/sidekiq.yml file like so, in hopes of running the worker daily at a specific time (11:05 am) ...
:concurrency: 20
:queues:
- default
...
:schedule:
Accounting::Workers::FileGenerationWorker:
cron: "0 5 11 * *"
queue: default
However, when I start my rails server ("rails s"), I don't see my print statement output to the console or any of the work performed, which tells me my worker isn't running. What else am I missing in order to get this worker scheduled properly locally?
Run the workers with
bundle exec sidekiq
You may need to provide the path to the worker module. For example,
bundle exec sidekiq -r ./worker.rb
Sidekiq by itself doesn't support a :schedule: map entry in the Sidekiq configuration file.
Periodic job functionality is provided in extensions such as sidekiq-scheduler.
You need to use classes declared in the extended Sidekiq module provided in sidekiq-scheduler. For example,
./worker.rb
require 'sidekiq-scheduler'
require './app/workers/accounting'
Sidekiq.configure_client do |config|
config.redis = {db: 1}
end
Sidekiq.configure_server do |config|
config.redis = {db: 1}
end
./app/workers/accounting.rb
module Accounting
# ...
end
module Accounting::Workers
class FileGenerationWorker
include Sidekiq::Worker
def perform
puts "starting work ...\n"
end
end
end

How do I clear output cache in Pimcore programmatically?

Note that this is not disable output cache which only disable for certain request, as what the documentation specified.
Pimcore provide a cli script to clear the cache
php pimcore/cli/console.php cache:clear
You can run the same command programmatically in any of the php file with exec() function
Found this in Pimcore 4 source code in pimcore/models/Object/ClassDefinition.php
// empty output cache
try {
Cache::clearTag("output");
} catch (\Exception $e) {
} ?>
Although I don't really agree on how this works (they did not specify that "output" is a reserved keyword for cache tags).
Please use this command your project root
php bin/console cache:clear
php bin/console pimcore:cache:clear

How to run a nodejs script every second

I need to run my nodejs script for every second ,Similar to PHP cron jobs. I have tried some nodejs cron libraries like https://github.com/ncb000gt/node-cron but the issue was first run should be manual i:e I have to run the file with cron script for first time manually.
But in php cron jobs, they run by the server so if the apache server running script will automatically start and even if the script return an error for a cycle then script will run again from the beginning from the next cycle
So is there any way to achieve this in nodejs ?
You have two options:
using Node as a daemon, with something like Supervisord to run your node-cron script. This alternative is wasteful on resources such as RAM because Node and Supervisord are running all the time.
using the system's crontab, you can run your script like calling Node on the command line, such as * * * * node /path/to/your/script.js. This alternative is highly efficient but lacks some control, like being able to log the output in case of an error, although you could just pipe the output to a file: node script.js > logfile

Resources