Scraping works fine until appended to list [closed] - python-3.x

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am a beginner trying to scrape bitcoin price history, everything works fine until I try to append it to a list, as nothing ends up being appended to the list.
import requests
from bs4 import BeautifulSoup
import pandas as pd
from datetime import datetime
url = 'https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20190821'
page = requests.get(url).content
soup = BeautifulSoup(page, 'html.parser')
priceDiv = soup.find('div', attrs={'class':'table-responsive'})
rows = priceDiv.find_all('tr')
data = []
i = 0
for row in rows:
temp = []
tds = row.findChildren()
for td in tds:
temp.append(td.text)
if i > 0:
temp[0] = temp[0].replace(',', '')
temp[6] = temp[6].replace(',', '')
if temp[5] == '-':
temp[5] = 0
else:
temp[5] = temp[5].replace(',', '')
data.append({'date': datetime.strptime(temp[0], '%b %d %Y'),
'open': float(temp[1]),
'high': float(temp[2]),
'low': float(temp[3]),
'close': float(temp[4]),
'volume': float(temp[5]),
'market_cap': float(temp[6])})
i += 1
df = pd.DataFrame(data)
If I try to print df or data it is just empty.

As noted above, you need to increment i outside that the check for > 0.
Secondly, have you considered using pandas .read_html(). That will do the hard work for you.
Code:
import pandas as pd
url = 'https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130428&end=20190821'
dfs = pd.read_html(url)
df = dfs[0]
Output:
print (df)
Date Open* ... Volume Market Cap
0 Aug 20, 2019 10916.35 ... 15053082175 192530283565
1 Aug 19, 2019 10350.28 ... 16038264603 195243306008
2 Aug 18, 2019 10233.01 ... 12999813869 185022920955
3 Aug 17, 2019 10358.72 ... 13778035685 182966857173
4 Aug 16, 2019 10319.42 ... 20228207096 185500055339
5 Aug 15, 2019 10038.42 ... 22899115082 184357666577
6 Aug 14, 2019 10889.49 ... 19990838300 179692803424
7 Aug 13, 2019 11385.05 ... 16681503537 194762696644
8 Aug 12, 2019 11528.19 ... 13647198229 203441494985
9 Aug 11, 2019 11349.74 ... 15774371518 205941632235
10 Aug 10, 2019 11861.56 ... 18125355447 202890020455
11 Aug 09, 2019 11953.47 ... 18339989960 211961319133
12 Aug 08, 2019 11954.04 ... 19481591730 213788089212
13 Aug 07, 2019 11476.19 ... 22194988641 213330426789
14 Aug 06, 2019 11811.55 ... 23635107660 205023347814
15 Aug 05, 2019 10960.74 ... 23875988832 210848822060
16 Aug 04, 2019 10821.63 ... 16530894787 195907875403
17 Aug 03, 2019 10519.28 ... 15352685061 193233960601
18 Aug 02, 2019 10402.04 ... 17489094082 187791090996
19 Aug 01, 2019 10077.44 ... 17165337858 185653203391
20 Jul 31, 2019 9604.05 ... 16631520648 180028959603
21 Jul 30, 2019 9522.33 ... 13829811132 171472452506
22 Jul 29, 2019 9548.18 ... 13791445323 169880343827
23 Jul 28, 2019 9491.63 ... 13738687093 170461958074
24 Jul 27, 2019 9871.16 ... 16817809536 169099540423
25 Jul 26, 2019 9913.13 ... 14495714483 176085968354
26 Jul 25, 2019 9809.10 ... 15821952090 176806451137
27 Jul 24, 2019 9887.73 ... 17398734322 175005760794
28 Jul 23, 2019 10346.75 ... 17851916995 176572890702
29 Jul 22, 2019 10596.95 ... 16334414913 184443440748
... ... ... ... ...
2276 May 27, 2013 133.50 ... - 1454029510
2277 May 26, 2013 131.99 ... - 1495293015
2278 May 25, 2013 133.10 ... - 1477958233
2279 May 24, 2013 126.30 ... - 1491070770
2280 May 23, 2013 123.80 ... - 1417769833
2281 May 22, 2013 122.89 ... - 1385778993
2282 May 21, 2013 122.02 ... - 1374013440
2283 May 20, 2013 122.50 ... - 1363709900
2284 May 19, 2013 123.21 ... - 1363204703
2285 May 18, 2013 123.50 ... - 1379574546
2286 May 17, 2013 118.21 ... - 1373723882
2287 May 16, 2013 114.22 ... - 1325726787
2288 May 15, 2013 111.40 ... - 1274623813
2289 May 14, 2013 117.98 ... - 1243874488
2290 May 13, 2013 114.82 ... - 1315710011
2291 May 12, 2013 115.64 ... - 1281982625
2292 May 11, 2013 117.70 ... - 1284207489
2293 May 10, 2013 112.80 ... - 1305479080
2294 May 09, 2013 113.20 ... - 1254535382
2295 May 08, 2013 109.60 ... - 1264049202
2296 May 07, 2013 112.25 ... - 1240593600
2297 May 06, 2013 115.98 ... - 1249023060
2298 May 05, 2013 112.90 ... - 1288693176
2299 May 04, 2013 98.10 ... - 1250316563
2300 May 03, 2013 106.25 ... - 1085995169
2301 May 02, 2013 116.38 ... - 1168517495
2302 May 01, 2013 139.00 ... - 1298954594
2303 Apr 30, 2013 144.00 ... - 1542813125
2304 Apr 29, 2013 134.44 ... - 1603768865
2305 Apr 28, 2013 135.30 ... - 1488566728
[2306 rows x 7 columns]

Related

AttributeError: 'super' object has no attribute 'S'

Still learning and new to code. I am working on (really playing around and learning) a self motivated projected to try and log stock HALTS cleanly. I am able to get the symbols I want, I can even trigger the status message when a HALT occurs by streaming.
However, when a status message occurs, I cannot parse the object correctly and cannot figure out why.
To start, I scan from symbols and make a list. I then create a for loop to subscribe to status messages for those symbols:
for symbol in symbols:
stream.subscribe_statuses(on_status, symbol)
My handler, 'on_status' is where I think , I am having the problem.
async def on_status(status):
symbol = status.symbol
status_message = status.status_message
logging.info("==============")
logging.info(f"{symbol} | {status_message}")
logging.info("==============")
When a status message is streamed I receive an error:
Sep 27 10:27:12 error during websocket communication: 'super' object has no attribute 'S'
Sep 27 10:27:12 Traceback (most recent call last):
Sep 27 10:27:12 File "/app/.heroku/python/lib/python3.10/site-packages/alpaca_trade_api/stream.py", line 254, in _run_forever
Sep 27 10:27:12 await self._consume()
Sep 27 10:27:12 File "/app/.heroku/python/lib/python3.10/site-packages/alpaca_trade_api/stream.py", line 130, in _consume
Sep 27 10:27:12 await self._dispatch(msg)
Sep 27 10:27:12 File "/app/.heroku/python/lib/python3.10/site-packages/alpaca_trade_api/stream.py", line 381, in _dispatch
Sep 27 10:27:12 await handler(self._cast(msg_type, msg))
Sep 27 10:27:12 File "/app/tading_halts.py", line 1184, in on_status
Sep 27 10:27:12 logging.info(f"{symbol} | {status_message}")
Sep 27 10:27:12 File "/app/.heroku/python/lib/python3.10/site-packages/alpaca_trade_api/entity_v2.py", line 135, in __getattr__
Sep 27 10:27:12 return super().__getattr__(self._reversed_mapping[key])
Sep 27 10:27:12 File "/app/.heroku/python/lib/python3.10/site-packages/alpaca_trade_api/entity.py", line 149, in __getattr__
Sep 27 10:27:12 return getattr(super(), key)
Sep 27 10:27:12 AttributeError: 'super' object has no attribute 'S'
Now, if I just use {status} I do get the StatusV2 object but I cannot figure out how to parse out the symbol and the message from that object. The object comes back as this:
Sep 27 10:00:09 | StatusV2({ 'reason_code': '',
Sep 27 10:00:09 'reason_message': '',
Sep 27 10:00:09 'status_code': 'T',
Sep 27 10:00:09 'status_message': 'Trading Resumption',
Sep 27 10:00:09 'symbol': 'ATXI',
Sep 27 10:00:09 'tape': 'C',
Sep 27 10:00:09 'timestamp': 1664287209393738868})
Any help would greatly be appreciated as I continue to learn.

Django model generates hundreds of files in a saving loop

I'm using Django 3.8.2 on Ubuntu 18.04, I'm generating a PDF file upon saving a django model but files are generated in a loop endlessly.
I have this django model:
class Fattura(models.Model):
ordine = models.ForeignKey(Ordine, on_delete=models.CASCADE, related_name="fatture", null=False)
pdf = models.FileField(upload_to='archivio/fatture/%Y/%m')
the pdf field is generated when an instance is saved, based on the information contained in the related "ordine" field which is a ForeignKey to this other model:
class Ordine(models.Model):
utente = models.ForeignKey(User, on_delete=models.CASCADE, related_name="ordini", null=False)
data = models.DateField(auto_now_add=True)
abbonamento = models.ForeignKey(Abbonamento, on_delete=models.PROTECT, null=False)
importo = models.DecimalField(max_digits = 5, decimal_places = 2, null=False)
I declared every instructions for the generation of the PDF inside the save() method of my Fattura model. I'm using the library that is recommended by Django's documentation: reportlab. Here is the custom save method:
def save(self, *args, **kwargs):
self.count_save += 1 # I defined this attribute which I increment to understand what is actually looping
print("COUNT SAVE: " + str(self.count_save)) # it always grows, that's the save method being re-called
if self.pdf._file == None:
try:
buffer = io.BytesIO()
p = canvas.Canvas(buffer)
p.drawString(100,100, str(self.ordine))
p.showPage()
p.save()
buffer.seek(0)
utente = self.ordine.utente
num_questa_fattura = utente.ordini.count()
nome_file = "{}_{}-{}.pdf".format(
self.ordine.utente.first_name.lower(),
self.ordine.utente.last_name.lower(),
num_questa_fattura)
percorso = '{}/upload/archivio/fatture/{}/{}/{}'.format(
BASE_DIR, # from settings.py
self.ordine.data.year,
self.ordine.data.month,
nome_file)
file_temporaneo = NamedTemporaryFile(delete=True)
file_temporaneo.write(buffer.getbuffer())
file_temporaneo.flush()
temp_file = File(file_temporaneo, name = nome_file)
print(nome_file)
print(file_temporaneo)
print("--------------------- SAVE")
self.pdf.save(nome_file, file_temporaneo, save=True) # saving the field (EDIT: this was the problem, setting save to True resaves the whole model object, and it was creating an infinite loop)
file_temporaneo.close()
except:
raise ValidationError("Invoice could not be saved")
super().save(*args, **kwargs) # saving the object to the database
When I save a Fattura object with my Django admin panel hundreds of PDF files are generated inside the folder I declared, in a loop, and no database saving really completes. No Django model object is available afterward so nothing is finally saved to the database and precisely 499 files are generated each time.
I'm not sure what is causing this loop, maybe the pdf field save method in the try statement? Or the final super().save(*args, **kwargs)? I can't remove it though, otherwise nothing would be saved if a PDF file is actually associated with one instance and I'm updating the other field ordine
Here's an excerpt from my logs
[Tue Nov 02 15:25:06.974768 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] COUNT SAVE: 262
[Tue Nov 02 15:25:07.010584 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] maria_rosselli-1.pdf
[Tue Nov 02 15:25:07.015778 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] <tempfile._TemporaryFileWrapper object at 0x7f7b07ac0390>
[Tue Nov 02 15:25:07.020944 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] --------------------- SAVE
[Tue Nov 02 15:25:07.124451 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] COUNT SAVE: 263
[Tue Nov 02 15:25:07.164934 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] maria_rosselli-1.pdf
[Tue Nov 02 15:25:07.170144 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] <tempfile._TemporaryFileWrapper object at 0x7f7b07ac0e48>
[Tue Nov 02 15:25:07.175250 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] --------------------- SAVE
[Tue Nov 02 15:25:07.253426 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] COUNT SAVE: 264
[Tue Nov 02 15:25:07.286589 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] maria_rosselli-1.pdf
[Tue Nov 02 15:25:07.291734 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] <tempfile._TemporaryFileWrapper object at 0x7f7b07ac0e10>
[Tue Nov 02 15:25:07.296894 2021] [wsgi:error] [pid 10050] [remote 95.x.x.x:36048] --------------------- SAVE
you need to set save to False to call the model instance's save methid again when saving the pdf:
self.pdf.save(nome_file, file_temporaneo, save=False)

Spark-sql parquet compression settings seem to be not working

I have set compression settings in SparkConf as follows:
sparkConf.set("spark.sql.parquet.compression.codec", "SNAPPY")
and also after 'SparkSession' creation as follows:
val spark = SparkSession
.builder()
.config(sparkConf)
.config("spark.sql.parquet.compression.codec", "GZIP") //SNAPPY
.config("spark.io.compression.codec", "org.apache.spark.io.LZ4CompressionCodec")
However, I see following in executor stdout:
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.codec.CodecConfig: Compression set to false
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.codec.CodecConfig: Compression: UNCOMPRESSED
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.ParquetOutputFormat: Parquet block size to 134217728
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.ParquetOutputFormat: Parquet page size to 1048576
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.ParquetOutputFormat: Parquet dictionary page size to 1048576
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.ParquetOutputFormat: Dictionary is on
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.ParquetOutputFormat: Validation is off
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.ParquetOutputFormat: Writer version is: PARQUET_1_0
Mar 16, 2019 10:34:17 AM INFO: parquet.hadoop.InternalParquetRecordWriter: Flushing mem columnStore to file. allocated memory: 0
Concerning output is :
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.codec.CodecConfig: Compression set to false
Mar 16, 2019 10:34:16 AM INFO: parquet.hadoop.codec.CodecConfig: Compression: UNCOMPRESSED
Does this mean spark is writing uncompressed data to parquet? If not how do I verify? Is there a way to view parquet metadata?

"installing" Kaitai Struct Python

I need help with installing Kaitai Struct on my Laptop.
I installed python-kaitaistruct and compiled the network files.
But i get an import error:
Traceback (most recent call last):
File "test2.py", line 1, in <module>
from ethernet_frame import *
File "/home/bene/python/ethernet_frame.py", line 15, in <module>
from ipv6_packet import Ipv6Packet
File "/home/bene/python/ipv6_packet.py", line 17, in <module>
from ipv4_packet import Ipv4Packet
File "/home/bene/python/ipv4_packet.py", line 17, in <module>
from ipv6_packet import Ipv6Packet
ImportError: cannot import name 'Ipv6Packet
My folder looks like this:
insgesamt 76K
drwxr-xr-x 3 bene bene 330 19. Jan 16:03 .
drwx------ 24 bene bene 4,0K 19. Jan 16:06 ..
-rw-r--r-- 1 bene bene 42 5. Jan 12:38 country.py
-rw-r--r-- 1 bene bene 8,0K 5. Jan 12:09 dns_packet.py
-rw-r--r-- 1 bene bene 1,6K 5. Jan 12:09 ethernet_frame.py
-rw-r--r-- 1 bene bene 3,0K 5. Jan 12:09 icmp_packet.py
-rw-r--r-- 1 bene bene 7,7K 5. Jan 12:09 ipv4_packet.py
-rw-r--r-- 1 bene bene 2,7K 5. Jan 12:09 ipv6_packet.py
-rw-r--r-- 1 bene bene 6,4K 5. Jan 12:09 microsoft_network_monitor_v2.py
-rw-r--r-- 1 bene bene 7,0K 5. Jan 12:09 pcap.py
drwxr-xr-x 2 bene bene 180 5. Jan 12:12 __pycache__
-rw-r--r-- 1 bene bene 1,1K 5. Jan 12:09 tcp_segment.py
-rw-r--r-- 1 bene bene 518 5. Jan 12:32 test1.py
-rw-r--r-- 1 bene bene 596 19. Jan 15:56 test2.py
-rw-r--r-- 1 bene bene 667 5. Jan 12:38 test.py
-rw-r--r-- 1 bene bene 880 5. Jan 12:09 udp_datagram.py
-rw-r--r-- 1 bene bene 986 5. Jan 12:09 windows_systemtime.py
and the file i executed:
from ethernet_frame import *
import socket
s = socket.socket(socket.AF_PACKET,socket.SOCK_RAW,socket.ntohs(3))
def network(buf):
io = BytesIO(buf)
ksio = KaitaiStream(io)
pkt = EthernetFrame(ksio)
dummy = pkt.ipv4_body.src_ip_addr
print(dummy)
while True:
p = s.recvfrom(65565)
network(p)
Can someone help me maybe i installed it wrong?
Or a Full Guide how to install and use it would be cool :DD
Thank you <3
I had a similar issue and after checking the .py file created by the compiler I found editing the import sequence solved the issue. Example:
import ipv4_packet was causing the same error as you have.
I checked ipv4_packet.py and it had an import statement from ipv6_packet import Ipv6Packet.
# This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
from pkg_resources import parse_version
from kaitaistruct import __version__ as ks_version, KaitaiStruct, KaitaiStream, BytesIO
from enum import Enum
if parse_version(ks_version) < parse_version('0.7'):
raise Exception("Incompatible Kaitai Struct Python API: 0.7 or later is required, but you have %s" % (ks_version))
from udp_datagram import UdpDatagram
from tcp_segment import TcpSegment
from ipv6_packet import Ipv6Packet
from icmp_packet import IcmpPacket
class Ipv4Packet(KaitaiStruct):
class ProtocolEnum(Enum):
ipv6_packet inturn tries to import the class from ipv4_packet: from ipv4_packet import Ipv4Packet, and causes the import error. If the lines (ipv4_packet .py):
from udp_datagram import UdpDatagram
from tcp_segment import TcpSegment
from ipv6_packet import Ipv6Packet
from icmp_packet import IcmpPacket
are moved to after the class definition there is no error.
Just playing around with Kaitai Struct for the first time this morning, I am sure this does not need to be done manually and there is an issue in the compilation I/we are doing, but this works if you just want to have a quick play.
I believe you should put the files that Kaitai Struct generated for you somewhere where Python will find it. Probably the simplest solution so far would be to just keep it in current directory and launch test2.py with something like:
PYTHONPATH=. python ./test2.py
Alternatively, if you want to keep everything in the same directory, newer compilers allow you to specify --python-package . to generate package imports which seek stuff in current directory.

Spring Integration: Stopping a Poller after a fixed duration

My requirement is that I would like to stop the poller after a fixed interval of time say 9 (hrs.). For now I am trying to stop the poller after 1 min. Following is my code:
<int-task:scheduler id="scheduler" pool-size="10"/>
<int-task:scheduled-tasks scheduler="scheduler">
<int-task:scheduled ref="incomingFiles.adapter" method="stop" fixed-delay="#{10 * 1000}"/>
</int-task:scheduled-tasks>
But now what I observe is that when I start my program then on startup I immediately get the message in the console as:
> INFO: Starting beans in phase 0 May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started incomingFiles.adapter May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding {service-activator} as a
> subscriber to the 'incomingFiles' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext#f4d5bc9.incomingFiles'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started
> org.springframework.integration.config.ConsumerEndpointFactoryBean#0
> May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding {router} as a subscriber to
> the 'contextStartedEventChannelChannel' channel May 28, 2014 10:27:55
> AM org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext#f4d5bc9.contextStartedEventChannelChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started
> org.springframework.integration.config.ConsumerEndpointFactoryBean#1
> May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding
> {outbound-channel-adapter:trueChannel.adapter} as a subscriber to the
> 'trueChannel' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext#f4d5bc9.trueChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started trueChannel.adapter May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding
> {outbound-channel-adapter:falseChannel.adapter} as a subscriber to the
> 'falseChannel' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext#f4d5bc9.falseChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started falseChannel.adapter May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.EventDrivenConsumer
> logComponentSubscriptionEvent INFO: Adding
> {logging-channel-adapter:_org.springframework.integration.errorLogger}
> as a subscriber to the 'errorChannel' channel May 28, 2014 10:27:55 AM
> org.springframework.integration.channel.AbstractSubscribableChannel
> adjustCounterIfNecessary INFO: Channel
> 'org.springframework.context.support.ClassPathXmlApplicationContext#f4d5bc9.errorChannel'
> has 1 subscriber(s). May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint start INFO:
> started _org.springframework.integration.errorLogger May 28, 2014
> 10:27:55 AM
> org.springframework.integration.file.FileReadingMessageSource receive
> INFO: Created message: [[Payload File
> content=C:\TEMP\incomingFile\ETD.CONFIRM.60326.140519.T0613170][Headers={id=b003893a-e013-57c8-0c96-55db627ec643, timestamp=1401287275402}]] May 28, 2014 10:27:55 AM
> org.springframework.integration.endpoint.AbstractEndpoint stop INFO:
> stopped incomingFiles.adapter
Somewhere in the start of the starttup logs we get:
May 28, 2014 10:27:55 AM
org.springframework.integration.endpoint.AbstractE ndpoint start INFO:
started incomingFiles.adapter
Somewhere in the end of the startup logs we get:
May 28, 2014 10:27:55 AM
org.springframework.integration.endpoint.AbstractE ndpoint stop INFO:
stopped incomingFiles.adapter
Why the incomingFiles.adapter has been stopped immediately while our fixed-delay="#{10 * 1000}" is 10 sec. Time is exactly same and there is absolutely no delay. So ideally the poller should stop after 10 sec. and not immediately. Also there are 4 files in the directory and its picking up only one.
Please do suggest what's wrong.
Well, I see. The
<int-task:scheduled ref="incomingFiles.adapter" method="stop"
fixed-delay="#{10 * 1000}"/>
produces PeriodicTrigger which result (nextExecutionTime) depends on triggerContext.lastScheduledExecutionTime() and if it is null (your case) it invokes underlying method immidiatelly.
Let's try this!
<task:scheduled ref="incomingFiles.adapter" method="stop"
fixed-delay="#{10 * 1000}" initial-delay="#{10 * 1000}"/>
I mean the same value for the initial-delay to postpone the first stop task for the desired time.

Resources